Skip to content

Commit b5a2e8d

Browse files
committed
mod nodejs package
1 parent ce2802f commit b5a2e8d

File tree

3 files changed

+159
-6
lines changed

3 files changed

+159
-6
lines changed

Qcloud_CDN_API/nodejs/AddCdnHost.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*需要填写你的密钥,可从 https://console.qcloud.com/capi 获取 SecretId 及 $secretKey*/
2+
$secretKey='YOUR_SECRET_KEY';
3+
$secretId='YOUR_SECRET_ID';
4+
$action='AddCdnHost';
5+
6+
7+
8+
/*****************参数************************/
9+
/**
10+
参数名 类型 是否必填 描述
11+
host string 是 域名
12+
hostType string 是 域名类型,(cname,ftp)
13+
projectId int 是 项目id
14+
origin string 否 源站
15+
**/
16+
17+
18+
19+
20+
/*参数*/
21+
$PRIVATE_PARAMS = array(
22+
"host" => "c.u-ndefined.com",
23+
"projectId" => 0,
24+
"hostType" => "cname",
25+
"origin" => "e.u-ndefinded.com:12023"
26+
);
27+
28+
$HttpUrl="cdn.api.qcloud.com";
29+
30+
/*除非有特殊说明,如MultipartUploadVodFile,其它接口都支持GET及POST*/
31+
$HttpMethod="POST";
32+
33+
/*是否https协议,大部分接口都必须为https,只有少部分接口除外(如MultipartUploadVodFile)*/
34+
$isHttps =true;
35+
36+
/*下面这五个参数为所有接口的 公共参数;对于某些接口没有地域概念,则不用传递Region(如DescribeDeals)*/
37+
$COMMON_PARAMS = array(
38+
'Nonce' => rand(),
39+
'Timestamp' =>time(NULL),
40+
'Action' =>$action,
41+
'SecretId' => $secretId,
42+
);
43+
44+
/***********************************************************************************/
45+
46+
47+
CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps);
48+
49+
function CreateRequest($HttpUrl,$HttpMethod,$COMMON_PARAMS,$secretKey, $PRIVATE_PARAMS, $isHttps)
50+
{
51+
$FullHttpUrl = $HttpUrl."/v2/index.php";
52+
53+
/***************对请求参数 按参数名 做字典序升序排列,注意此排序区分大小写*************/
54+
$ReqParaArray = array_merge($COMMON_PARAMS, $PRIVATE_PARAMS);
55+
ksort($ReqParaArray);
56+
57+
/**********************************生成签名原文**********************************
58+
* 将 请求方法, URI地址,及排序好的请求参数 按照下面格式 拼接在一起, 生成签名原文,此请求中的原文为
59+
* GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=345122&Region=gz
60+
* &SecretId=AKIDz8krbsJ5yKBZQ ·1pn74WFkmLPx3gnPhESA&Timestamp=1408704141
61+
* &instanceIds.0=qcvm12345&instanceIds.1=qcvm56789
62+
* ****************************************************************************/
63+
$SigTxt = $HttpMethod.$FullHttpUrl."?";
64+
65+
$isFirst = true;
66+
foreach ($ReqParaArray as $key => $value)
67+
{
68+
if (!$isFirst)
69+
{
70+
$SigTxt = $SigTxt."&";
71+
}
72+
$isFirst= false;
73+
74+
/*拼接签名原文时,如果参数名称中携带_,需要替换成.*/
75+
if(strpos($key, '_'))
76+
{
77+
$key = str_replace('_', '.', $key);
78+
}
79+
80+
$SigTxt=$SigTxt.$key."=".$value;
81+
}
82+
83+
/*********************根据签名原文字符串 $SigTxt,生成签名 Signature******************/
84+
$Signature = base64_encode(hash_hmac('sha1', $SigTxt, $secretKey, true));
85+
86+
87+
/***************拼接请求串,对于请求参数及签名,需要进行urlencode编码********************/
88+
$Req = "Signature=".urlencode($Signature);
89+
foreach ($ReqParaArray as $key => $value)
90+
{
91+
$Req=$Req."&".$key."=".urlencode($value);
92+
}
93+
94+
/*********************************发送请求********************************/
95+
if($HttpMethod === 'GET')
96+
{
97+
if($isHttps === true)
98+
{
99+
$Req="https://".$FullHttpUrl."?".$Req;
100+
}
101+
else
102+
{
103+
$Req="http://".$FullHttpUrl."?".$Req;
104+
}
105+
106+
$Rsp = file_get_contents($Req);
107+
108+
}
109+
else
110+
{
111+
if($isHttps === true)
112+
{
113+
$Rsp= SendPost("https://".$FullHttpUrl,$Req,$isHttps);
114+
}
115+
else
116+
{
117+
$Rsp= SendPost("http://".$FullHttpUrl,$Req,$isHttps);
118+
}
119+
}
120+
121+
var_export(json_decode($Rsp,true));
122+
}
123+
124+
function SendPost($FullHttpUrl, $Req, $isHttps)
125+
{
126+
127+
$ch = curl_init();
128+
curl_setopt($ch, CURLOPT_POST, 1);
129+
curl_setopt($ch, CURLOPT_POSTFIELDS, $Req);
130+
131+
curl_setopt($ch, CURLOPT_URL, $FullHttpUrl);
132+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
133+
if ($isHttps === true) {
134+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
135+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
136+
}
137+
138+
$result = curl_exec($ch);
139+
140+
return $result;
141+
}

Qcloud_CDN_API/nodejs/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "nodejs",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}

Qcloud_CDN_API/python/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ python QcloudCdnTools_V2.py OnlineHost -u xxxxx -p xxxxxxx --hostId 206092
4141
## DeleteCdnHost
4242
python QcloudCdnTools_V2.py DeleteCdnHost -u xxxxx -p xxxxxxx --hostId 81094
4343

44-
##GenerateLogList
44+
## GenerateLogList
4545
python QcloudCdnTools_V2.py GenerateLogList -u xxxxx -p xxxxxxx --hostId 206092
4646

47-
##GetCdnRefreshLog
47+
## GetCdnRefreshLog
4848
python QcloudCdnTools_V2.py GetCdnRefreshLog -u xxxxxxxxxxxx -p xxxxxxxxxxxx --startDate 2016-04-25 --endDate 2016-04-26
4949

50-
##GetCdnStatTop
50+
## GetCdnStatTop
5151
python QcloudCdnTools_V2.py GetCdnStatTop -u xxxxxxxxxxxx -p xxxxxxxxxxxx --startDate 2016-05-08 --endDate 2016-05-09 --statType bandwidth --projects 0 --hosts ping.cdn.qcloud.com --hosts ts6.cache.qcloudcdn.com
5252

53-
##GetCdnStatusCode
53+
## GetCdnStatusCode
5454
python QcloudCdnTools_V2.py GetCdnStatusCode -u xxxxxxxxxxxx -p xxxxxxxxxxxx --startDate 2016-05-08 --endDate 2016-05-09 --projects 0 --hosts ping.cdn.qcloud.com --hosts ts6.cache.qcloudcdn.com
5555

56-
##DescribeCdnHostDetailedInfo
56+
## DescribeCdnHostDetailedInfo
5757
python QcloudCdnTools_V2.py DescribeCdnHostDetailedInfo -u xxxxxxxxxxxx -p xxxxxxxxxxxx --startDate 2016-05-08 --endDate 2016-05-09 --projects 0 --hosts ping.cdn.qcloud.com --hosts ts6.cache.qcloudcdn.com --statType bandwidth
5858

59-
##DescribeCdnHostInfo
59+
## DescribeCdnHostInfo
6060
python QcloudCdnTools_V2.py DescribeCdnHostInfo -u xxxxxxxxxxxx -p xxxxxxxxxxxx --startDate 2016-05-08 --endDate 2016-05-09 --projects 0 --statType bandwidth --debug

0 commit comments

Comments
 (0)