我使用的接口是退款接口:
https://api.mch.weixin.qq.com/v3/refund/domestic/refunds
签名生成代码如下,服务商和商户号证书都试了,都无法退款成功。返回信息是签名错误。
$url传入的是退款接口地址,证书序列号和商户号都修改过服务商和特约商户的了,都跑不通。
public function getAuthorization($http_method = "POST", $body = [], $url = "v3/pay/partner/transactions/jsapi"): string
{
$serial_no = $this->merchantCertificateSerial; // 商户证书序列号
$mchid = $this->config['service_member']; // 商户号
$timestamp = time();
$nonce = $this->nonce_str();
$url_parts = parse_url($url);
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
$message = $http_method . "\n" .
$canonical_url . "\n" .
$timestamp . "\n" .
$nonce . "\n" .
$body . "\n";
openssl_sign($message, $raw_sign, $this->merchantPrivateKeyInstance, 'sha256WithRSAEncryption');
$sign = base64_encode($raw_sign);
return sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$mchid, $nonce, $timestamp, $serial_no, $sign);
}
是不是这里的服务没授权导致的,但是我使用商户号进行退款仍然提示签名错误,错误信息如下
{
"code": "SIGN_ERROR",
"detail": {
"detail": {
"issue": "sign not match"
},
"field": "signature",
"location": "authorization",
"sign_information": {
"method": "POST",
"sign_message_length": 324,
"truncated_sign_message": "POST\n/v3/refund/domestic/refunds\n1693894402\nwwGNussqESygThKOPRGplkjMAWuBnFoB\n{\"out_tr\n",
"url": "/v3/refund/domestic/refunds"
}
},
"message": "错误的签名,验签失败"
}
服务商模式退款使用的是服务商商户号的证书密钥,用sdk吧https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay6_0.shtml
服务商API退款是授权了的