<?php// Pay no attention to this statement.
// It's only needed if timezone in php.ini is not set correctly.
date_default_timezone_set("UTC");// The current time. Needed to create the Timestamp parameter below.
$now = new DateTime();// The parameters for the GET request. These will get signed.
$parameters = array(
    // The ID of the user making the call.
    'UserID' => '[email protected]',    // The API version. Currently must be 1.0
    'Version' => '1.0',    // The API method to call.
    'Action' => 'GetBrands',    // The format of the result.
    'Format' => 'XML',    // The current time in ISO8601 format
    //'Timestamp' => $now->format(DateTime::ISO8601)
'Timestamp' => '2015-07-01T11:11:11+00:00'
);// Sort parameters by name.
ksort($parameters);// URL encode the parameters.
$encoded = array();
foreach ($parameters as $name => $value) {
    $encoded[] = rawurlencode($name) . '=' . rawurlencode($value);
}// Concatenate the sorted and URL encoded parameters into a string.
$concatenated = implode('&', $encoded);// The API key for the user as generated in the Seller Center GUI.
// Must be an API key associated with the UserID parameter.
$api_key = 'b1bdb357ced10fe4e9a69840cdd4f0e9c03d77fe';// Compute signature and add it to the parameters.
$parameters['Signature'] =
    rawurlencode(hash_hmac('sha256', $concatenated, $api_key, false));
echo $parameters['Signature'];我运行的结果是:62d759cdbf8e2da71bf561f0d908fc5bb6f2cb041e4a5ea1ebb90ad4fc8d8251
但说是正确的应该是:3ceb8ed91049dfc718b0d2d176fb2ed0e5fd74f76c5971f34cdab48412476041
这个是什么情况?

解决方案 »

  1.   

    你所输出的运行结果是由(hash_hmac生成的哈希值然后再通过rawurlencode转码的内容)
    hash_hmac('算法名', '你要加密的字符串', '加密键','true或false');  
    //如果 raw_output 设置为 TRUE, 则返回原始二进制数据表示的信息摘要,否则返回 16 进制小写字符串格式表示的信息摘要。
    rewurlencode('字符串');   //把除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数。//目前还在学习中,如有不对还请指正