我正在进行支付集成,我在PHP中有一个示例代码,并尝试使其在Ruby中运行.到目前为止收效甚微.有人可以检查我的实现并修复我是否做错了什么?谢谢.
PHP代码:
/*
* HMAC HASH creation
* RFC 2104
*
http://www.ietf.org/rfc/rfc2104.txt
*
* @param string $key Secret key for encryption
* @param string $data String to encode
*/
function hmac($key, $data) {
$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*", md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad;
$k_opad = $key ^ $opad;
return md5($k_opad . pack("H*", …Run Code Online (Sandbox Code Playgroud)