我正在尝试使用 Python 连接到 Shopwedo API。https://admin.shopwedo.com/developer/。
除了散列之外,一切都运行良好。下面是 PHP 和 Python 中的示例脚本。相同字符串的散列返回不同的最终结果。
PHP代码
/** * Prepare credentials: */
$credentials = array(
'id' => 1234,
'key' => "HelloTest",
'timestamp' => 1554888606,
'salt' => 'diego' );
/** * Generate token by combining credentials: */
$hash_preparation = implode('', array_values($credentials));
$token = hash_hmac('sha512', $hash_preparation, '');
print($token);
此 PHP 代码返回:
b0d45466aa68db7df247d858094f88010b7c58820538309fff
e28a42458a6ce4b6b2d48b1c5b9d40492851db075af9d86b2e
1c81c4a6960d3dfb4616bccb617a
蟒蛇代码
import hashlib
params={'shopid':1234,
'apikey': "HelloTest",
'timestamp':1554888606,
'salt': "diego"}
tosign = "".join([str(params[i]) for i in params] )
token = hashlib.sha512(tosign.encode()).hexdigest()
print(token)
此 Python 代码返回:
34480ef855ff09d743ff5931ff39851ee4031e470c0fddb7e7
ba6a1c9a8a5145bfbcd020c11220287f2747f28f48d77893ff
f4f8dcce82ab54e70c67f172bab9
墨色风雨
尚方宝剑之说
相关分类