diff --git a/examples/cdn/AddCdnHost.php b/examples/cdn/AddCdnHost.php new file mode 100644 index 0000000000..5965725794 --- /dev/null +++ b/examples/cdn/AddCdnHost.php @@ -0,0 +1,142 @@ + "c.u-ndefined.com", + "projectId" => 0, + "hostType" => "cname", + "origin" => "e.u-ndefinded.com:12023" + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/DeleteCdnHost.php b/examples/cdn/DeleteCdnHost.php new file mode 100644 index 0000000000..0793400c9f --- /dev/null +++ b/examples/cdn/DeleteCdnHost.php @@ -0,0 +1,133 @@ + 862, + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/DescribeCdnHostDetailedInfo.php b/examples/cdn/DescribeCdnHostDetailedInfo.php new file mode 100644 index 0000000000..89c0294199 --- /dev/null +++ b/examples/cdn/DescribeCdnHostDetailedInfo.php @@ -0,0 +1,141 @@ + rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + + +/*****************参数************************/ +/** + 参数名 类型 是否必填 描述 +startDate string 是 开始日期 +endDate string 是 结束日期 +statType string 是 查看维度 +projects array 是 项目id +hosts array 否 查询域名 +**/ + + +$PRIVATE_PARAMS = array( + 'startDate'=> '2016-04-26', + 'endDate' => '2016-04-27', + 'statType' => 'bandwidth', + 'projects.0'=> 0, + 'hosts.0' =>'ping.cdn.qcloud.com' +); + + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/DescribeCdnHostInfo.php b/examples/cdn/DescribeCdnHostInfo.php new file mode 100644 index 0000000000..147ec1d1ad --- /dev/null +++ b/examples/cdn/DescribeCdnHostInfo.php @@ -0,0 +1,141 @@ + rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + + +/*****************参数************************/ +/** + 参数名 类型 是否必填 描述 +startDate string 是 开始日期 +endDate string 是 结束日期 +statType string 是 查看维度 +projects array 是 项目id +hosts array 否 查询域名 +**/ + + +$PRIVATE_PARAMS = array( + 'startDate'=> '2016-04-26', + 'endDate' => '2016-04-27', + 'statType' => 'bandwidth', + 'projects.0'=> 0, + 'hosts.0' =>'ping.cdn.qcloud.com' +); + + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/DescribeCdnHosts.php b/examples/cdn/DescribeCdnHosts.php new file mode 100644 index 0000000000..e2e0e0f19e --- /dev/null +++ b/examples/cdn/DescribeCdnHosts.php @@ -0,0 +1,122 @@ + rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +$PRIVATE_PARAMS = array(); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/GetCdnRefreshLog.php b/examples/cdn/GetCdnRefreshLog.php new file mode 100644 index 0000000000..bc47bb2a08 --- /dev/null +++ b/examples/cdn/GetCdnRefreshLog.php @@ -0,0 +1,135 @@ + rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/*****************参数************************/ +/** + 参数名 类型 是否必填 描述 +startDate string 是 开始日期 +endDate string 是 结束日期 +url string 否 查询的URL +**/ + + +$PRIVATE_PARAMS = array( + 'startDate'=> '2016-04-26', + 'endDate' => '2016-04-27', +); + + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/GetCdnStatTop.php b/examples/cdn/GetCdnStatTop.php new file mode 100644 index 0000000000..78709ac3df --- /dev/null +++ b/examples/cdn/GetCdnStatTop.php @@ -0,0 +1,142 @@ + rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + + +/*****************参数************************/ +/** + 参数名 类型 是否必填 描述 +startDate string 是 开始日期 +endDate string 是 结束日期 +statType string 是 查看维度 +projects array 是 项目id +hosts array 否 查询域名 +period int 否 数据采样间隔 +**/ + + +$PRIVATE_PARAMS = array( + 'startDate'=> '2016-04-26', + 'endDate' => '2016-04-27', + 'statType' => 'bandwidth', + 'projects.0'=> 0, + 'hosts.0' =>'ping.cdn.qcloud.com' +); + + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/GetCdnStatusCode.php b/examples/cdn/GetCdnStatusCode.php new file mode 100644 index 0000000000..4dca0985cd --- /dev/null +++ b/examples/cdn/GetCdnStatusCode.php @@ -0,0 +1,140 @@ + rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/*****************参数************************/ +/** + 参数名 类型 是否必填 描述 +startDate string 是 开始日期 +endDate string 是 结束日期 +projects array 是 项目id +hosts array 否 查询域名 +sources array 否 网络层级 +period int 否 数据采样间隔 +**/ + + +$PRIVATE_PARAMS = array( + 'startDate'=> '2016-04-26', + 'endDate' => '2016-04-27', + 'projects.0'=> 0, + 'hosts.0' =>'ping.cdn.qcloud.com' +); + + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/GetHostInfoByHosts.php b/examples/cdn/GetHostInfoByHosts.php new file mode 100644 index 0000000000..fa4e2cf115 --- /dev/null +++ b/examples/cdn/GetHostInfoByHosts.php @@ -0,0 +1,126 @@ + "ping.cdn.qcloud.com", + "hosts.1" => "img46.ddimg.cn", + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/GetHostInfoByIds.php b/examples/cdn/GetHostInfoByIds.php new file mode 100644 index 0000000000..d723f10d24 --- /dev/null +++ b/examples/cdn/GetHostInfoByIds.php @@ -0,0 +1,125 @@ + 253, + "ids.1" => 326, + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/OfflineHost.php b/examples/cdn/OfflineHost.php new file mode 100644 index 0000000000..f159014e3b --- /dev/null +++ b/examples/cdn/OfflineHost.php @@ -0,0 +1,133 @@ + 862, + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/OnlineHost.php b/examples/cdn/OnlineHost.php new file mode 100644 index 0000000000..c3820a57c3 --- /dev/null +++ b/examples/cdn/OnlineHost.php @@ -0,0 +1,133 @@ + 862, + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/RefreshCdnDir.php b/examples/cdn/RefreshCdnDir.php new file mode 100644 index 0000000000..588a6cb82d --- /dev/null +++ b/examples/cdn/RefreshCdnDir.php @@ -0,0 +1,133 @@ + 'http://foo.bar.com/dir0/', + 'dirs.1'=> 'http://foo.bar.com/dir1/', + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/RefreshCdnUrl.php b/examples/cdn/RefreshCdnUrl.php new file mode 100644 index 0000000000..c2f69b6cbd --- /dev/null +++ b/examples/cdn/RefreshCdnUrl.php @@ -0,0 +1,132 @@ + 'http://ping.cdn.qcloud.com/ping/t0.css', + 'urls.1'=> 'http://ping.cdn.qcloud.com/ping/t1.css', + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/UpdateCache.php b/examples/cdn/UpdateCache.php new file mode 100644 index 0000000000..53c8bce226 --- /dev/null +++ b/examples/cdn/UpdateCache.php @@ -0,0 +1,134 @@ + 862, + "cache" => "[[0,\"all\", 1023448]]", + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/UpdateCdnConfig.php b/examples/cdn/UpdateCdnConfig.php new file mode 100644 index 0000000000..f99906ed49 --- /dev/null +++ b/examples/cdn/UpdateCdnConfig.php @@ -0,0 +1,148 @@ + 862, + "projectId" => 0, + "cacheMode" => "custom", + "cache" => "[[0,\"all\", 1023448]]", + "refer" => "[1,[\"qq.baidu.com\", \"v.qq.com\"]]", + "fwdHost" => "qq.com.cn", + "fullUrl" => "off", + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/UpdateCdnHost.php b/examples/cdn/UpdateCdnHost.php new file mode 100644 index 0000000000..d21d5e4446 --- /dev/null +++ b/examples/cdn/UpdateCdnHost.php @@ -0,0 +1,135 @@ + 862, + "host" => 'test.com', + "origin" => '1.1.1.1', + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +} diff --git a/examples/cdn/UpdateCdnProject.php b/examples/cdn/UpdateCdnProject.php new file mode 100644 index 0000000000..b5375b1e4f --- /dev/null +++ b/examples/cdn/UpdateCdnProject.php @@ -0,0 +1,134 @@ + 862, + "projectId" => 0, + ); + +$HttpUrl="cdn.api.qcloud.com"; + +/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/ +$HttpMethod="POST"; + +/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/ +$isHttps =true; + +/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/ +$COMMON_PARAMS = array( + 'Nonce' => rand(), + 'Timestamp' =>time(NULL), + 'Action' =>$action, + 'SecretId' => $secretId, + ); + +/***********************************************************************************/ + +CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps); + +function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps) +{ + $FullHttpUrl = $HttpUrl."/v2/index.php"; + + /***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/ + $ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS); + ksort($ReqParaArray); + + /**********************************生成签名原文********************************** + * 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为 + * GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz + * &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141 + * &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789 + * ****************************************************************************/ + $SigTxt = $HttpMethod.$FullHttpUrl."?"; + + $isFirst = true; + foreach ($ReqParaArray as $key => $value) + { + if (!$isFirst) + { + $SigTxt = $SigTxt."&"; + } + $isFirst= false; + + /*拼接签名原文时,如果参数名称中携带_,需要替换成.*/ + if(strpos($key, '_')) + { + $key = str_replace('_', '.', $key); + } + + $SigTxt=$SigTxt.$key."=".$value; + } + + /*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/ + $Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true)); + + + /***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/ + $Req = "Signature=".urlencode($Signature); + foreach ($ReqParaArray as $key => $value) + { + $Req=$Req."&".$key."=".urlencode($value); + } + + /*********************************发送请求********************************/ + if($HttpMethod === 'GET') + { + if($isHttps === true) + { + $Req="https://".$FullHttpUrl."?".$Req; + } + else + { + $Req="http://".$FullHttpUrl."?".$Req; + } + + $Rsp = file_get_contents($Req); + + } + else + { + if($isHttps === true) + { + $Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps); + } + else + { + $Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps); + } + } + + var_export(json_decode($Rsp,true)); +} + +function SendPost($FullHttpUrl, $Req, $isHttps) +{ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $Req); + + curl_setopt($ch, CURLOPT_URL, $FullHttpUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($isHttps === true) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + $result = curl_exec($ch); + + return $result; +}