Skip to content

Commit

Permalink
修改签名
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Aug 29, 2017
1 parent fbe9f17 commit 3fbe13a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions server/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var crypto = require('crypto');

var cos = {
// 获取个人 API 密钥 https://console.qcloud.com/capi
sid: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
skey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
SecretId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
getAuthorization: function (method, pathname, callback) {
method = (method ? method : 'post').toLowerCase();
pathname = pathname ? pathname : '/';
Expand Down Expand Up @@ -48,15 +48,15 @@ var cos = {

// 要用到的 Authorization 参数列表
var qSignAlgorithm = 'sha1';
var qAk = cos.sid;
var qAk = cos.SecretId;
var qSignTime = now + ';' + expired;
var qKeyTime = now + ';' + expired;
var qHeaderList = getObjectKeys(headers).join(';').toLowerCase();
var qUrlParamList = getObjectKeys(queryParams).join(';').toLowerCase();

// 签名算法说明文档:https://www.qcloud.com/document/product/436/7778
// 步骤一:计算 SignKey
var signKey = crypto.createHmac('sha1', cos.skey).update(qKeyTime).digest('hex');
var signKey = crypto.createHmac('sha1', cos.SecretKey).update(qKeyTime).digest('hex');

// 步骤二:构成 FormatString
var formatString = [method.toLowerCase(), pathname, obj2str(queryParams), obj2str(headers), ''].join('\n');
Expand Down
8 changes: 4 additions & 4 deletions server/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function getAuthorization($method, $pathname)
$headers = array();

// 获取个人 API 密钥 https://console.qcloud.com/capi
$sid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$skey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$SecretId = 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$SecretKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// 工具方法
function getObjectKeys($obj)
Expand Down Expand Up @@ -48,15 +48,15 @@ function obj2str($obj)

// 要用到的 Authorization 参数列表
$qSignAlgorithm = 'sha1';
$qAk = $sid;
$qAk = $SecretId;
$qSignTime = $now . ';' . $expired;
$qKeyTime = $now . ';' . $expired;
$qHeaderList = strtolower(implode(';', getObjectKeys($headers)));
$qUrlParamList = strtolower(implode(';', getObjectKeys($queryParams)));

// 签名算法说明文档:https://www.qcloud.com/document/product/436/7778
// 步骤一:计算 SignKey
$signKey = hash_hmac("sha1", $qKeyTime, $skey);
$signKey = hash_hmac("sha1", $qKeyTime, $SecretKey);

// 步骤二:构成 FormatString
$formatString = implode("\n", array(strtolower($method), $pathname, obj2str($queryParams), obj2str($headers), ''));
Expand Down

0 comments on commit 3fbe13a

Please sign in to comment.