根据https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_2.shtml 这个文档,开发合单支付严格按照文档要求进行签名,但是返回的结果始终是如下,按照https://wechatpay-api.gitbook.io/wechatpay-api-v3/chang-jian-wen-ti/qian-ming-xiang-guan 该文档,签名失败也没有提供detail的细节说明.
如下是返回的错误信息,包含header头信息
"HTTP\/1.1 401 Unauthorized\r\nServer: nginx\r\nDate: Sun, 05 Apr 2020 04:27:15 GMT\r\nContent-Type: application\/json; charset=utf-8\r\nContent-Length: 67\r\nConnection: keep-alive\r\nKeep-Alive: timeout=8\r\nCache-Control: no-cache, must-revalidate\r\nX-Content-Type-Options: nosniff\r\nRequest-ID: 2pu3so\r\n\r\n{\"code\":\"SIGN_ERROR\",\"message\":\"验签失败,请检查签名\\t\"}\n"
请问一下 合单下单-JS支付API的 签名是怎样的.
我的签名规则如下
$url = 'https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi';
$timestamp = time();
$nonce = $this->nonce_str();
$datas = json_encode($params);
$sign = $this->sign1($url, 'POST', $timestamp, $nonce, $datas , $this->mch_private_key, $this->mch_id, $this->serial_no);
// echo(mb_strlen(' WECHATPAY2-SHA256-RSA2048 ' . $sign,"utf-8"));
//设置header头
$header = [
'Authorization: WECHATPAY2-SHA256-RSA2048 ' . $sign,
'Accept:application/json',
'User-Agent:' . $this->mch_id,
'Content-Type:application/json',
'Wechatpay-Serial:' . $zhengshu
];
签名的函数如下
public function sign1($url, $http_method, $timestamp, $nonce, $bodya, $mch_private_key, $merchant_id, $serial_no)
{
$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" .
$bodya . "\n";
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
$sign = base64_encode($raw_sign);
$schema = 'WECHATPAY2-SHA256-RSA2048 ';
$token = sprintf(
'mchid="%s",nonce_str="%s",signature="%s",timestamp="%d",serial_no="%s"',
$merchant_id,
$nonce,
$sign,
$timestamp,
$serial_no,
$bodya
);
// echo($token);
return $token;
}
这个函数也是微信官方文档提供的函数,请教各位大神,怎样解决问题
我解决了,你是什么问题
请问解决了吗,我也是卡在验签这里了