master
elf 2 years ago
parent 3f20260523
commit 22996d03e8

@ -25,7 +25,7 @@ class Client
public function post($url, $params): string
{
Log::write('REQUEST_URL: ' . json_encode($url));
Log::write('REQUEST_URL: ' . $url);
Log::write('REQUEST_DATA: ' . json_encode($params));
$curl = curl_init();
if (stripos($url, 'https://') !== false){

@ -40,6 +40,9 @@ class Request
'merchantCode' => $this->merchantCode,
'totalBizType' => $this->totalBizType,
], $this->params);
foreach ($params as $key => $value) {
$params[$key] = $this->strToEncoding($value, 'GBK');
}
$params[Sign::SIGN_KEY] = Sign::generate($params, $this->signFields, $this->secretKey);
return $params;
}
@ -47,4 +50,13 @@ class Request
public function getUrl() {
return Config::get('base_url') . $this->url;
}
private 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);
}
}
}

@ -25,25 +25,13 @@ class Sign
}
private static function hmacMd5($signString, $secretKey) {
$data = self::strToEncoding($signString, 'GBK');
$key = self::strToEncoding($secretKey, 'GBK');
if (function_exists('hash_hmac')) {
return hash_hmac('md5', $data, $key);
}
$key = (strlen($key) > 64) ? pack('H32', 'md5') : str_pad($key, 64, chr(0));
$ipad = substr($key,0, 64) ^ str_repeat(chr(0x36), 64);
$opad = substr($key,0, 64) ^ str_repeat(chr(0x5C), 64);
return md5($opad.pack('H32', md5($ipad.$data)));
return hash_hmac('md5', $signString, $secretKey);
}
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);
}
$secretKey = (strlen($secretKey) > 64) ? pack('H32', 'md5') : str_pad($secretKey, 64, chr(0));
$ipad = substr($secretKey,0, 64) ^ str_repeat(chr(0x36), 64);
$opad = substr($secretKey,0, 64) ^ str_repeat(chr(0x5C), 64);
return md5($opad.pack('H32', md5($ipad. $signString)));
}
}
Loading…
Cancel
Save