我想将以下C#代码转换为
PHP.
C#是:
byte[] operation = UTF8Encoding.UTF8.GetBytes("getfaqs"); byte[] secret = UTF8Encoding.UTF8.GetBytes("Password"); var hmac = newHMACSHA256(secret); byte[] hash = hmac.ComputeHash(operation);
我已经变成了这个:
$hash = hash_hmac( "sha256",utf8_encode("getfaqs"),utf8_encode("Password"));
然后我有:
var apiKey = "ABC-DEF1234"; var authInfo = apiKey + ":" + hash //base64 encode the authorisation info var authorisationHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));
我认为应该是:
$authInfo = base64_encode($apiKey . ":" . $hash);
要么
$authInfo = base64_encode(utf8_encode($apiKey . ":" . $hash));
但不确定,请注意第二个编码使用Encoding.UTF8,而不是UTF8Encoding.UTF8.