php对接微信h5新版 V3支付遇到的第一个报错
意思是说证书序列号不正确
解决过程:
1、我得到的证书有apiclient_cert.pem,apiclient_key.pem,wpay.p12这三个文件
2、我下载了官网提供的sdk(下载地址 https://github.com/wechatpay-apiv3/wechatpay-php)
3、按照文件写了代码

$merchantPrivateKeyFilePath 这个字段,填写apiclient_key.pem文件绝对路径
一定要保留file://,不然会报错
platformCertificateFilePath这个字段,填写的apiclientcert.pem文件地址,其他参数对应填写,然后运行在构造客户端实例时就报了The‘certs(platformCertificateFilePath这个字段,填写的apiclient_cert.pem文件地址,其他参数对应填写,然后运行在构造客户端实例时就报了The `certs(%1platformCertificateFilePath这个字段,填写的apiclientc​ert.pem文件地址,其他参数对应填写,然后运行在构造客户端实例时就报了The‘certs(s)` contains the merchant’s certificate serial number(%2KaTeX parse error: Undefined control sequence: \wechatpay at position 48: …步一步打印到wechatpay\̲w̲e̲c̲h̲a̲t̲p̲a̲y̲\src\ClientJson…platformCertificateFilePath这个字段应该使用支付平台证书,而不是下载的apiclient_cert.pem这个文件
4、sdk不能调用,那我就自己封装获取,根据官网文档(https://pay.weixin.qq.com/wiki/doc/apiv3/apis/wechatpay5_1.shtml)
5、代码如下

/*** 获取证书* @return mixed*/public static function certificates(){//请求参数(报文主体)$headers = self::sign('GET','https://api.mch.weixin.qq.com/v3/certificates','');$result = self::curl_get('https://api.mch.weixin.qq.com/v3/certificates',$headers);$result = json_decode($result,true);$aa = self::decryptToString($result['data'][0]['encrypt_certificate']['associated_data'],$result['data'][0]['encrypt_certificate']['nonce'],$result['data'][0]['encrypt_certificate']['ciphertext']);dd($aa);//解密后的内容,就是证书内容}/*** 签名* @param string $http_method    请求方式GET|POST* @param string $url            url* @param string $body           报文主体* @return array*/public static function sign($http_method = 'POST',$url = '',$body = ''){$mch_private_key = self::getMchKey();//私钥$timestamp = time();//时间戳$nonce = self::getRandomStr(32);//随机串$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, $mch_private_key, 'sha256WithRSAEncryption');$sign = base64_encode($raw_sign);//设置HTTP头$config = self::config();$token = sprintf('WECHATPAY2-SHA256-RSA2048 mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',$config['mchid'], $nonce, $timestamp, $config['serial_no'], $sign);$headers = ['Accept: application/json','User-Agent: */*','Content-Type: application/json; charset=utf-8','Authorization: '.$token,];return $headers;}//私钥public static function getMchKey(){//path->私钥文件存放路径return openssl_get_privatekey(file_get_contents('你的apiclient_key.pem文件绝对路径'));}/*** 获得随机字符串* @param $len      integer       需要的长度* @param $special  bool      是否需要特殊符号* @return string       返回随机字符串*/public static function getRandomStr($len, $special=false){$chars = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k","l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v","w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G","H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R","S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2","3", "4", "5", "6", "7", "8", "9");if($special){$chars = array_merge($chars, array("!", "@", "#", "$", "?", "|", "{", "/", ":", ";","%", "^", "&", "*", "(", ")", "-", "_", "[", "]","}", "<", ">", "~", "+", "=", ",", "."));}$charsLen = count($chars) - 1;shuffle($chars);                            //打乱数组顺序$str = '';for($i=0; $i<$len; $i++){$str .= $chars[mt_rand(0, $charsLen)];    //随机取出一位}return $str;}/*** 配置*/public static function config(){return ['appid' => '','mchid' => '',//商户号'serial_no' => '',//证书序列号'description' => '',//应用名称(随意)'notify' => '',//支付回调];}
//get请求public static function curl_get($url,$headers=array()){$info = curl_init();curl_setopt($info,CURLOPT_RETURNTRANSFER,true);curl_setopt($info,CURLOPT_HEADER,0);curl_setopt($info,CURLOPT_NOBODY,0);curl_setopt($info,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($info,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($info,CURLOPT_SSL_VERIFYHOST,false);//设置header头curl_setopt($info, CURLOPT_HTTPHEADER,$headers);curl_setopt($info,CURLOPT_URL,$url);$output = curl_exec($info);curl_close($info);return $output;}const KEY_LENGTH_BYTE = 32;const AUTH_TAG_LENGTH_BYTE = 16;
/*** Decrypt AEAD_AES_256_GCM ciphertext** @param string    $associatedData     AES GCM additional authentication data* @param string    $nonceStr           AES GCM nonce* @param string    $ciphertext         AES GCM cipher text** @return string|bool      Decrypted string on success or FALSE on failure*/public static function decryptToString($associatedData, $nonceStr, $ciphertext) {$aesKey = '你的APIv3密钥';$ciphertext = \base64_decode($ciphertext);if (strlen($ciphertext) <= self::AUTH_TAG_LENGTH_BYTE) {return false;}// ext-sodium (default installed on >= PHP 7.2)if (function_exists('\sodium_crypto_aead_aes256gcm_is_available') && \sodium_crypto_aead_aes256gcm_is_available()) {return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);}// ext-libsodium (need install libsodium-php 1.x via pecl)if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && \Sodium\crypto_aead_aes256gcm_is_available()) {return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);}// openssl (PHP >= 7.1 support AEAD)if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) {$ctext = substr($ciphertext, 0, -self::AUTH_TAG_LENGTH_BYTE);$authTag = substr($ciphertext, -self::AUTH_TAG_LENGTH_BYTE);return \openssl_decrypt($ctext, 'aes-256-gcm', $aesKey, \OPENSSL_RAW_DATA, $nonceStr,$authTag, $associatedData);}throw new \RuntimeException('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php');}

6、请求接口,获取到证书内容,保存到文件中,命名为cert.pem,然后在使用sdk时,$platformCertificateFilePath这个变量使用的路径改为新获取到证书的路径,就可以直接调用sdk了

The `certs(%1$s)` contains the merchant‘s certificate serial number(%2$s) which is not allowed here.相关推荐

  1. php 支付宝和微信pc支付

    支付宝pc支付 文档:电脑网站支付产品介绍 | 网页&移动应用 1,创建网页&移动应用 创建应用 2,获得网站支付能力 支付宝开放平台 3,sdk composer intall al ...

  2. 利用https访问站点(基于linux系统)

    一.HTTPS原理 HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版 ...

  3. http://www.secrepo.com 安全相关的数据获取源

    来自:http://www.secrepo.com Network MACCDC2012 - Generated with Bro from the 2012 dataset A nice datas ...

  4. centos8编译openssl-1.0.2u、openssl-1.1.1k

    目录 一.给openssl-1.0.2u打包rpm 二.编译安装openssl-1.1.1k 三.给openssl-1.1.1k打包rpm(不推荐!) 近日openssl爆出拒绝服务.证书绕过漏洞,C ...

  5. Openssl私建CA

    构建私有CA:    在确定配置为CA的服务上生成一个自签证书,并为CA提供所需要的目录及文件即可: 步骤:   (1) 生成私钥: [root@centos7 ~]# (umask 077; ope ...

  6. 22.加密与安全相关,证书申请CA(gpg,openssl)

    安全机制 信息安全防护的目标 保密性 Confidentiality 完整性 Integrity 可用性 Usability 可控制性 Controlability 不可否认性 Non-repudia ...

  7. 菜鸟学Linux 第044篇笔记 算法和私有CA

    菜鸟学Linux 第044篇笔记 算法和私有CA 证书吊销列表CRL(Certificate Revocation List ) 如何解决私钥丢失 PKI: Public Key Infrastruc ...

  8. linux添加ssl信任根证书,linux系统添加根证书linux证书信任列表

    1.linux 访问 https 证书问题 [root@boss-test-dev001-jydx ~]# curl -v https://mobile.mycard520.com.tw * Abou ...

  9. linux ftp 团队认证,linux下ftp和ftps以及ftp基于mysql虚拟用户认证服务器的搭建

    linux下ftp和ftps以及ftp基于mysql虚拟用户认证服务器的搭建 1.FTP协议:有命令和数据连接两种 命令连接,控制连接:21/tcp 数据连接: 主动模式,运行在20/tcp端口 和 ...

  10. https原理与实践

    HTTPS 原理与证书实践 分类: Web应用 1.1 网络安全知识 1.1.1 网结安全出现背景 网络就是实现不同主机之间的通讯,网络出现之初利用TCP/IP协议簇的相关协议概念,已经满足了互连两台 ...

最新文章

  1. 句法分析常用算法框架以及NLPIR、Dependency Viwer
  2. Kubernetes 弹性伸缩全场景解析 (一):概念延伸与组件布局
  3. debian源码安装bind9.10.6
  4. String类的对象的方法 格式小结 java 1202
  5. 电击图片弹出无边自定义窗口
  6. mysql user表空_Mysql User表为空
  7. OCS2007视频会议客户端的部署与应用
  8. 看英文看的头疼的一次
  9. mysql 数字正则_mysql 正则
  10. 怎样提升小程序UV访客,快速开通流量主!
  11. 电子技术应用课程设计
  12. 超好用的卸载软件 —— Geek
  13. ts 正负条形图 组件_手把手教你使用ggplot2绘制条形图
  14. 要多大内存才满足_什么是延迟满足能力?“延迟满足”能力对孩子有多重要家长要清楚...
  15. Python批量裁剪图形外围空白区域
  16. 做一个FLASH游戏你需要掌握的东西【实用】
  17. html背景图片溢出,如何清除背景图片溢出?
  18. 35,UC(14) .
  19. 很多人都想考一个RHCE吧,大家不妨看看我是怎么变成一个RHCE的。
  20. 计算机领域网络顶级会议,【分享】计算机领域的一些顶级会议【已搜索,无重复】 - 信息科学 - 小木虫 - 学术 科研 互动社区...

热门文章

  1. 下载新版火狐后无法同步书签_Ubuntu解决火狐浏览器无法同步书签的问题【推荐】...
  2. 【Java 多线程 8】同步容器与并发容器
  3. android 动画卡顿优化,Android属性动画卡顿的优化
  4. ERP采购管理 华夏
  5. 数字电路 逻辑函数的化简之 公式化简法
  6. linux 命令行修改分辨率,Linux命令行(console)屏幕分辨率调整
  7. Matlab R2019a Win64位 迅雷下载链接
  8. 数据库查询之内连接,左连接,右连接
  9. 【从零开始学架构-李运华】08|架构设计三原则
  10. python合并大量ts文件_python合并ts视频