<?php
$app_key = '12008678';/*填写appkey */
$secret='';/*填入Appsecret'*/
$timestamp=time()."000";
$message = $secret.'app_key'.$app_key.'timestamp'.$timestamp.$secret;
$mysign=strtoupper(hash_hmac("md5",$message,$secret));
setcookie("timestamp",$timestamp);
setcookie("sign",$mysign);
?>
有PHP开发环镜的朋友请帮我输出一个结果:HMAC("MD5," 12342e93ab9ad9822c77b75fc9cf2d4bapp_key469115timespamp2012-10-23 21:41:2512342e93ab9ad9822c77b75fc9cf2d4b","12342e93ab9ad9822c77b75fc9cf2d4b")
c# 的HMAC:
public class Hmac { private static string BuildEncodedSig(string data, string key) { using (HMACSHA1 hmac = new HMACSHA1(Encoding.UTF8.GetBytes(key))) { byte[] buffer = Encoding.UTF8.GetBytes(data); byte[] hashValue = hmac.ComputeHash(buffer); return Convert.ToBase64String(hashValue); } } public static bool VerifyEncodedSig(string encodedSig, string data, string key) { string forCheck = Hmac.BuildEncodedSig(data, key); return forCheck == encodedSig; } }
<?php
echo hash_hmac("MD5","12342e93ab9ad9822c77b75fc9cf2d4bapp_key469115timespamp2012-10-23 21:41:2512342e93ab9ad9822c77b75fc9cf2d4b","12342e93ab9ad9822c77b75fc9cf2d4b");
?>
输出的值为:0269bfa518171b8709d71bc289852e70
哎,人真是都太懒了啊,你google一下,一大堆吧?即使你不懂php,应该也能搜出来吧?现在人都习惯直接要代码了?
你好,我现在也遇到这样的问题,同样是签名错误。
请问你当时是怎么解决的?能跟我说一下吗。
淘宝API好坑爹啊。说改就改。
/// <summary>
/// hmacmd5算法加密(生成长度32)
/// </summary>
/// <param name="encryptText">加密明文</param>
/// <param name="encryptKey">加密密钥</param>
/// <returns></returns>
public static string HMAC_MD5(string encryptText, string encryptKey)
{
HMACMD5 myHMACSHA1 = new HMACMD5(Encoding.Default.GetBytes(encryptKey));
byte[] RstRes = myHMACSHA1.ComputeHash(Encoding.Default.GetBytes(encryptText));
StringBuilder EnText = new StringBuilder();
foreach (byte Byte in RstRes)
{
EnText.AppendFormat("{0:x2}", Byte);
}
return EnText.ToString();
}
有用。。。非常感谢。。