|
@@ -1,10 +1,53 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
+use WeChatPay\Builder;
|
|
|
+use WeChatPay\Crypto\Rsa;
|
|
|
+use WeChatPay\Transformer;
|
|
|
+use WeChatPay\Util\PemUtil;
|
|
|
+
|
|
|
class Index
|
|
|
{
|
|
|
- public function index()
|
|
|
- {
|
|
|
- return redirect('/admin.php/home');
|
|
|
- }
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ return redirect('/admin.php/home');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function t1()
|
|
|
+ {
|
|
|
+ // 商户号
|
|
|
+ $merchantId = config('wxconfig.payMchId');
|
|
|
+
|
|
|
+// 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名
|
|
|
+ $merchantPrivateKeyFilePath = file_get_contents(root_path('/extend/wechat-del/cert') . 'apiclient_key.pem');
|
|
|
+ $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
|
|
|
+
|
|
|
+// 「商户API证书」的「证书序列号」
|
|
|
+ $merchantCertificateSerial = config('wxconfig.serial');
|
|
|
+
|
|
|
+// 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名
|
|
|
+ $platformCertificateFilePath = file_get_contents(root_path('/extend/wechat-del/cert') . 'apiclient_cert.pem');
|
|
|
+ $platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
|
|
|
+
|
|
|
+// 从「微信支付平台证书」中获取「证书序列号」
|
|
|
+ $platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);
|
|
|
+
|
|
|
+// 构造一个 APIv3 客户端实例
|
|
|
+ $instance = Builder::factory([
|
|
|
+ 'mchid' => $merchantId,
|
|
|
+ 'serial' => $merchantCertificateSerial,
|
|
|
+ 'privateKey' => $merchantPrivateKeyInstance,
|
|
|
+ 'certs' => [
|
|
|
+ $platformCertificateSerial => $platformPublicKeyInstance,
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+
|
|
|
+// 发送请求
|
|
|
+ $resp = $instance->chain('v3/certificates')->get(
|
|
|
+ ['debug' => true] // 调试模式,https://docs.guzzlephp.org/en/stable/request-options.html#debug
|
|
|
+ );
|
|
|
+ halt($resp->getBody());
|
|
|
+
|
|
|
+ }
|
|
|
}
|