全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

签名过程示例

最近更新时间:2024-02-26 15:54:33

该样例以iam服务的CreateUser为例,点击查看该API文档

1、构造规范化请求字符串:CanonicalizedQueryString

//请求参数数组:
array (
    'Accesskey'=> 'AKLTXQVF0pOmS6aahIrD5r0B3Q', //公共参数
    'Service'=> 'iam', //公共参数
    'Action'=> 'CreateUser', //公共参数
    'Version'=> '2015-11-01', //公共参数
    'Timestamp'=> '2021-08-12T02:47:36Z', //公共参数
    'SignatureVersion'=> '1.0', //公共参数
    'SignatureMethod'=> 'HMAC-SHA256', //公共参数
    'UserName' => 'Ttest', //业务参数
    'RealName' => '周四测试', //业务参数
    'Email' => '[email protected]', //业务参数
    'Remark' => '~ce shi*%#|+', //业务参数
)

第一步:请求参数排序

//排序结果如下:
array (
    'Accesskey' => 'AKLTXQVF0pOmS6aahIrD5r0B3Q',
    'Action' => 'CreateUser',
    'Email' => '[email protected]',
    'RealName' => '周四测试',
    'Remark' => '~ce shi*%#|+',
    'Service' => 'iam',
    'SignatureMethod' => 'HMAC-SHA256',
    'SignatureVersion' => '1.0',
    'Timestamp' => '2021-08-12T02:47:36Z',
    'UserName' => 'Ttest',
    'Version' => '2015-11-01',
)

第二步:请求参数编码

//编码结果如下:
array (
    'Accesskey' => 'AKLTXQVF0pOmS6aahIrD5r0B3Q',
    'Action' => 'CreateUser',
    'Email' => 'zsce%40kkingsoft.com',
    'RealName' => '%E5%91%A8%E5%9B%9B%E6%B5%8B%E8%AF%95',
    'Remark' => '~ce%20shi%2A%25%23%7C%2B',
    'Service' => 'iam',
    'SignatureMethod' => 'HMAC-SHA256',
    'SignatureVersion' => '1.0',
    'Timestamp' => '2021-08-12T02%3A47%3A36Z',
    'UserName' => 'Ttest',
    'Version' => '2015-11-01',
)

第三步:请求参数拼接成CanonicalizedQueryString

//拼接结果如下
Accesskey=AKLTXQVF0pOmS6aahIrD5r0B3Q&Action=CreateUser&Email=zsce%40kkingsoft.com&RealName=%E5%91%A8%E5%9B%9B%E6%B5%8B%E8%AF%95&Remark=~ce%20shi%2A%25%23%7C%2B&Service=iam&SignatureMethod=HMAC-SHA256&SignatureVersion=1.0&Timestamp=2021-08-12T02%3A47%3A36Z&UserName=Ttest&Version=2015-11-01

2、计算签名

sk = 'OMovU5PTLh6y9E9Ioe3K411jt99VqyQSBXgAcDYlo49R3lvUIzb6e/efZCFDmtFlzw=='
CanonicalizedQueryString = "Accesskey=AKLTXQVF0pOmS6aahIrD5r0B3Q&Action=CreateUser&Email=zsce%40kkingsoft.com&RealName=%E5%91%A8%E5%9B%9B%E6%B5%8B%E8%AF%95&Remark=~ce%20shi%2A%25%23%7C%2B&Service=iam&SignatureMethod=HMAC-SHA256&SignatureVersion=1.0&Timestamp=2021-08-12T02%3A47%3A36Z&UserName=Ttest&Version=2015-11-01"
//sign = hash_hmac('sha256', CanonicalizedQueryString, sk)
sign: fc9088ab845949dac4040be9b7ce7859068b5c21d4c400fec8ee0cefb777f659

3、将签名值作为Signature参数值添加到请求参数中

//请求示例:
curl -s -L -X POST 'iam.api.ksyun.com' \
-H 'Accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Accesskey=AKLTXQVF0pOmS6aahIrD5r0B3Q' \
--data-urlencode 'Service=iam' \
--data-urlencode 'Action=CreateUser' \
--data-urlencode 'Version=2015-11-01' \
--data-urlencode 'Timestamp=2021-08-12T02:47:36Z' \
--data-urlencode 'SignatureVersion=1.0' \
--data-urlencode 'SignatureMethod=HMAC-SHA256' \
--data-urlencode 'UserName=Ttest' \
--data-urlencode 'RealName=周四测试' \
--data-urlencode '[email protected]' \
--data-urlencode 'Remark=~ce shi*%#|+' \
--data-urlencode 'Signature=fc9088ab845949dac4040be9b7ce7859068b5c21d4c400fec8ee0cefb777f659'


文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈