|
|
@ -25,25 +25,13 @@ class Sign
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static function hmacMd5($signString, $secretKey) {
|
|
|
|
private static function hmacMd5($signString, $secretKey) {
|
|
|
|
$data = self::strToEncoding($signString, 'GBK');
|
|
|
|
|
|
|
|
$key = self::strToEncoding($secretKey, 'GBK');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (function_exists('hash_hmac')) {
|
|
|
|
if (function_exists('hash_hmac')) {
|
|
|
|
return hash_hmac('md5', $data, $key);
|
|
|
|
return hash_hmac('md5', $signString, $secretKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$key = (strlen($key) > 64) ? pack('H32', 'md5') : str_pad($key, 64, chr(0));
|
|
|
|
$secretKey = (strlen($secretKey) > 64) ? pack('H32', 'md5') : str_pad($secretKey, 64, chr(0));
|
|
|
|
$ipad = substr($key,0, 64) ^ str_repeat(chr(0x36), 64);
|
|
|
|
$ipad = substr($secretKey,0, 64) ^ str_repeat(chr(0x36), 64);
|
|
|
|
$opad = substr($key,0, 64) ^ str_repeat(chr(0x5C), 64);
|
|
|
|
$opad = substr($secretKey,0, 64) ^ str_repeat(chr(0x5C), 64);
|
|
|
|
return md5($opad.pack('H32', md5($ipad.$data)));
|
|
|
|
return md5($opad.pack('H32', md5($ipad. $signString)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static function strToEncoding($str, $encoding) {
|
|
|
|
|
|
|
|
$encode = mb_detect_encoding($str, ['ASCII', 'GB2312', 'GBK', 'UTF-8']);
|
|
|
|
|
|
|
|
if($encode == $encoding){
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
|
|
|
|
} else{
|
|
|
|
|
|
|
|
return mb_convert_encoding($str, $encoding, $encode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|