Skip to content

Commit

Permalink
Update 接口鉴权.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vxiumzhi authored Nov 20, 2024
1 parent ad2a7a6 commit c970d86
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
有了安全凭证SecretId 和 SecretKey后,就可以生成签名串了。以下是生成签名串的详细过程:

假设你的 SecretId 和 SecretKey 分别是:
> SecretId: AKIDz8krbsJ5yKBZQpn74WFkmLPx3gnPhESA
> SecretKey: Gu5t9xGARNpq86cd98joQYCN3Cozk1qA
> SecretId: *********************************************
> SecretKey: ****************************************
**注意:这里只是示例,请请根据你实际申请的SecretId和SecretKey进行后续操作!**

Expand All @@ -39,7 +39,7 @@
| 参数名称 | 中文 | 参数值|
|---------|---------|---------|
| Action | 方法名| DescribeInstances |
| SecretId | 密钥Id | AKIDz8krbsJ5yKBZQpn74WFkmLPx3gnPhESA |
| SecretId | 密钥Id | ******************************************* |
| Timestamp | 当前时间戳 | 1465185768 |
| Nonce | 随机正整数 | 11886 |
| Region | 实例所在区域 | gz |
Expand All @@ -56,7 +56,7 @@
'Action' : 'DescribeInstances',
'Nonce' : 11886,
'Region' : 'gz',
'SecretId' : 'AKIDz8krbsJ5yKBZQpn74WFkmLPx3gnPhESA',
'SecretId' : '*********************************************',
'Timestamp' : 1465185768,
'instanceIds.0' : 'ins-09dx96dg',
'limit' : 20,
Expand All @@ -72,7 +72,7 @@
然后将格式化后的各个参数用"&"拼接在一起,最终生成的请求字符串为:

```
Action=DescribeInstances&Nonce=11886&Region=gz&SecretId=AKIDz8krbsJ5yKBZQpn74WFkmLPx3gnPhESA&Timestamp=1465185768&instanceIds.0=ins-09dx96dg&limit=20&offset=0
Action=DescribeInstances&Nonce=11886&Region=gz&SecretId=*********************************************&Timestamp=1465185768&instanceIds.0=ins-09dx96dg&limit=20&offset=0
```

### 2.3. 拼接签名原文字符串
Expand All @@ -90,7 +90,7 @@ Action=DescribeInstances&Nonce=11886&Region=gz&SecretId=AKIDz8krbsJ5yKBZQpn74WFk
示例的拼接结果为:

```
GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=11886&Region=gz&SecretId=AKIDz8krbsJ5yKBZQpn74WFkmLPx3gnPhESA&Timestamp=1465185768&instanceIds.0=ins-09dx96dg&limit=20&offset=0
GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=11886&Region=gz&SecretId=*********************************************&Timestamp=1465185768&instanceIds.0=ins-09dx96dg&limit=20&offset=0
```

### 2.4. 生成签名串
Expand All @@ -100,8 +100,8 @@ GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=11886&Region=g
具体代码如下,以 PHP 语言为例:

```
$secretKey = 'Gu5t9xGARNpq86cd98joQYCN3Cozk1qA';
$srcStr = 'GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=11886&Region=gz&SecretId=AKIDz8krbsJ5yKBZQpn74WFkmLPx3gnPhESA&Timestamp=1465185768&instanceIds.0=ins-09dx96dg&limit=20&offset=0';
$secretKey = '********************************';
$srcStr = 'GETcvm.api.qcloud.com/v2/index.php?Action=DescribeInstances&Nonce=11886&Region=gz&SecretId=*********************************************&Timestamp=1465185768&instanceIds.0=ins-09dx96dg&limit=20&offset=0';
$signStr = base64_encode(hash_hmac('sha1', $srcStr, $secretKey, true));
echo $signStr;
```
Expand Down

0 comments on commit c970d86

Please sign in to comment.