错误信息:
{"code""PARAM_ERROR","message""请确认待处理的消息是否为加密后的密文"}
看到特约商户更新了文档之后,我采用的是最新的API-v3接口规则
请求头如下(证书序列号是微信支付平台序列号):
array("Content-Type: application/json","Accept:application/json","User-Agent:".$_SERVER['HTTP_USER_AGENT'],"Authorization:"$this->authorization,"Wechatpay-Serial:"$this->cert_sn)
验签如下(验签使用的是商户平台私钥):
$url_parts = parse_url($url);
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query'])) ? "?${url_parts['query']}" : ""));
$message = strtoupper($http_method).'\n'.canonical_url.'\n'.
$timestamp.'\n'.
$nonce.'\n'.
$body.'\n';
$pri_key_string = file_get_contents($this->apiclient_key);
$pri_key = openssl_get_privatekey($pri_key_string);
if(!openssl_sign(message, raw_sign, pri_key, 'sha256WithRSAEncryption')){
throw new WxPayException('make sign failed:'.PHP_EOL);
}
$sign = base64_encode($raw_sign);
加密敏感信息(使用微信支付平台公钥):
$pub_key_string = file_get_contents($this->cert_path);
$pub_key = openssl_get_publickey($pub_key_string);
$encrypted = '';
if(openssl_public_encrypt($str,$encrypted,$pub_key,OPENSSL_PKCS1_OAEP_PADDING)){
return base64_encode($encrypted);
}
麻烦看一下是什么问题,官方给的错误信息没有明确指出是哪个字段加密出错,现在找不到处理的办法了。
https://github.com/wechatpay-apiv3/wechatpay-guzzle-middleware/pull/18 这个0侵入的加/解密方案,可以尝试下。
use WechatPay\GuzzleMiddleware\Util\SensitiveInfoCodec as Codec; // Codec默认为加密模式,实例后直接当方法用即可 $encryptor = new Codec(PemUtil::loadCertificate('/downloaded/public.pem')); // POST 语法糖 $resp = $client->post('/v3/applyment4sub/applyment/', [ 'json' => [ 'business_code' => 'APL_98761234', 'contact_info' => [ 'contact_name' => $encryptor('窃格瓦拉'), 'contact_id_number' => $encryptor('45012119841227000X'), 'mobile_phone' => $encryptor('12345678901'), 'contact_email' => $encryptor('noop@real.world'), ], //... ], 'headers' => [ // 命令行获取证书序列号 // openssl x509 -in /downloaded/public.pem -noout -serial | awk -F= '{print $2}' 'Wechatpay-Serial' => 'must be the serial number via the downloaded pem file of `/v3/certificates`', 'Accept' => 'application/json', ], ]);
req username 不设置就不会报这个错
同样的问题,不知道哪些参数需要加密,哪些参数不需要加密,也没个说明
https://github.com/wechatpay-apiv3/wechatpay-apache-httpclient/blob/master/src/main/java/com/wechat/pay/contrib/apache/httpclient/util/RsaCryptoUtil.java
我是使用官方提供的加密方法(方法的证书参数是微信平台证书),尝试对请求json中的每一个参数加密,然后再做减法依次取消一个参数,直到最后只剩对一个姓名加密,就不报错了
解决了,contactme:qq1198551705
麻烦您说一下您的问题出在哪了?我现在也是出了这个问题
解决了。
新版V3的进件
php版本demo我发出来了
这边是上传了敏感数据吧,要加密的。关键加密数据的格式需要参考文档。仔细参考文档核对一下。
{
"business_code": "d47f621d43d9a0db6b10d5f6ad10e52e",
"contact_info": {
"mobile_phone": "Nnt71WFO+Pek9zZKPk9cCFhghz4QE0NWMPgnOVQx+duBfdt7W3Fo5JF1/v/OqnCmkXZ0pwqKUkInW9Ck4Eht8U7WhV+aBukUu6TBTR4D4T1Oyh6vBoYWl16p6kvNdjkc8crDB/onJKGhdP/a09ipC3Ee/XAHvbVqWmwVGa+xQ8AEuSa6YdcEEo/MU5qMUGrxQvnsxMDHsMlOhE4rajBAVi9PQLEzzOchz2NCLWz564387ReACgMGU/S/I/g+asdaRhznbCoiEH+xDAaqUaZvgadzs96WDOMsUJOoEWA1tbE7ZNLPfZrz7DxhDmA1kzkVysQAbCkkpjwB8IPpMDdvVg==",
"contact_email": "FL+4uRj/7EWO4oWrY0CgkGGg4RnT8p9W3TAk5xWuQ16V53NjLqODTjMt6dY5QR0z+wXIo+EKbIjrM0VRtSbueG68lc9C4zZC/fUWdA8xgmN1gaRPLcF7kBDgxdS1oagWo9dPLReOMFnhhbA5wn2FfwToxxo50LQEUf5jAT7qHRM4UAvwV/+LC0tH9Cd79h51PP77p2GuSYsRpqgWAdLBgFmrvSI4Tv4NFX1Fx16Mp6Opq8beOGhBG+Kp17n3IZ7PMfY8VPQeJKaRfYqxzL9tb5BP3SAu7uxpml7iJHqTNEk3bHi+X0Rc3is4r/ai96awVTuGo+aPY5JCbHm+UX5T+A==",
"contact_name": "HWPkrXreEtoWKQKndLXzNCkqP2SIwOalQ4kb6aSTtsSlUZeRsQmpP2+C3zrEKf8wTqkqSCPZVT2WrxvdHlshp4gXtChodw56Gy6uZczGZ+2Ax+VZKw+Pc1ZqnJYyZ3GsJRIsI3Lu8pYUNxrDKtHUneu1rP+KdIIwxA/Rj3KdloQ6WVLnxOyeHH4i8dq3qIdKJlW0iKyG6Lj19MLquv5zL+t2jqonNnoOtCZrsa/QZZ/VbwVLsGgBCrP7iak3lHZjA5yrw6drprqM8Tik0YPd8vURhbYgL7xXMwMrNSVUQmlF5rRH/3EMx5N2jhfDlBSgR0SYzlLNLtDI1DK8uObdNA==",
"contact_id_number": "B5EWfts29fxGHuLRTmgvyBSLHzuXzcfOHfdS5/s/q9fMvoOweYSDHN+9RO1lhetjsgznzmYfqjfQcUX2AYYuLgMNFMz9JMtDXTEeJHjFL5eg5Kjg6UjV+RXfhAYrN1z0jW1P7arBM3Zr4iOS/LITKTyuGffcrFoB0XwamapleFdE5Fnv1AHVC6AAm1VqUoVpi26ub92//OPy+2iU0DzOM92FSwj3H2BSVFYoLdjawXpXkztevgLf4nE21uQERfwuT+aKQpnKK6+XBHBDlyAR7f8GUESt9oJygCXBaSGifT6LcfkXix7FG/OSMVzPNeQo1Jkl+1edkQEJgnQYKqnKsg=="
}
}
谢邀,首先看不懂php,再一个没做过你这,等官方看下吧