'POST', // HTTP请求方法 'CanonicalURI' => '/', // URL参数 'CanonicalQueryString' => '', //HTTP 查询字符串 'CanonicalHeaders' => 'content-type:application/json'."\n".'host:'.$host."\n", // 参与签名头部信息 'SignedHeaders' => 'content-type;host', // 参与签名的头部信息 'HashedRequestPayload' => strtolower(bin2hex(hash("SHA256", json_encode($allParams, JSON_UNESCAPED_UNICODE), true))), ]; $canonicalRequestStr = ''; $mark = "\n"; $i = 1; foreach ($canonicalRequest as $key => $value){ if($i == (count($canonicalRequest)) ){ $mark = ''; } $canonicalRequestStr .= $value . $mark ; $i++; } // 拼接待签名字符串 $credentialScope = gmdate('Y-m-d', $time).'/'.$service.'/'.'tc3_request'; $hashedCanonicalRequest = strtolower(bin2hex(hash("SHA256", $canonicalRequestStr, true))); $stringToSign = [ 'algorithm' => 'TC3-HMAC-SHA256', 'timestamp' => $time, 'credentialScope' => $credentialScope, 'hashedCanonicalRequest' => $hashedCanonicalRequest, ]; $stringToSignStr = ''; $mark = "\n"; $i = 1; foreach ($stringToSign as $key => $value){ if($i == (count($stringToSign)) ){ $mark = ''; } $stringToSignStr .= $value . $mark ; $i++; } // 计算签名 $secretDate = hash_hmac('SHA256', gmdate('Y-m-d', $time), 'TC3'.$secretKey, true); $secretService = hash_hmac('SHA256', $service, $secretDate, true); $secretSigning = hash_hmac('SHA256', 'tc3_request', $secretService, true); $signture = strtolower(hash_hmac('SHA256', $stringToSignStr, $secretSigning)); // authorization $authorization = 'TC3-HMAC-SHA256 Credential='.$secretId.'/'.$credentialScope.', SignedHeaders=content-type;host, Signature='.$signture; return $authorization; } }