获取微信支付平台证书报错,有人帮忙看下嘛吗?
在调用获取微信平台证书接口:https://api.mch.weixin.qq.com/v3/certificates 时
一直返回{"code""SIGN_ERROR""message""商户证书序列号有误。请使用签名私钥匹配的证书序列号"}
可以确定的是提交的API证书私钥以及证书序列号都是从服务商平台获取的
//代码如下:
public function getCert($s_id = '15')
{
$server = Serves::find($s_id);
$url = 'https://api.mch.weixin.qq.com/v3/certificates';
$timestamp = time();
$str = 'abc';
$private_key = self::getPrivateKey($server->pem_key);//服务商api证书私钥
$mch_id = $server->mch_id;//服务商商户号
$serial_no = $server->serial_no;//api证书序列号
$sign = self::makeSign($url, 'GET', $timestamp, $str, '', $private_key, $mch_id, $serial_no);
$header = [
'Authorization: WECHATPAY2-SHA256-RSA2048 '.$sign,
'Accept:application/json',
'User-Agent:weixinpay'
];
$result = self::curl($url, '', $header, 'GET';
$result = json_decode($result, true);
return $result;
}
//签名的方法在这
public function makeSign($url, $method, $timestamp, $nonce, $body, $private_key, $mchid, $serial_no)
{
$url_parts = parse_url($url);
$canonical_url = ($url_parts['path'].(!empty($url_parts['query']) ? "?${url_parts['query']}" : "";
$message = $method."\n".$canonical_url."\n".$timestamp."\n".$nonce."\n".$body."\n";
openssl_sign($message, $signs, $private_key, 'sha256WithRSAEncryption';
$sign = base64_encode($signs);
$sign = 'mchid="'.$mchid.'",nonce_str="'.$nonce.'",signature="'.$sign.'",timestamp="'.$timestamp.'",serial_no="'.$serial_no.'"';
return $sign;
}
帮忙看看这是什么原因啊