Browse Source

微信支付测试

linwu 2 years ago
parent
commit
0557646240
3 changed files with 69 additions and 17 deletions
  1. 47 4
      app/admin/controller/Index.php
  2. 17 12
      config/wxconfig.php
  3. 5 1
      vendor/guzzlehttp/guzzle/src/Utils.php

+ 47 - 4
app/admin/controller/Index.php

@@ -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());
+
+    }
 }

+ 17 - 12
config/wxconfig.php

@@ -16,22 +16,27 @@
 use think\facade\Env;
 
 return [
-	
-	// 微信小程序名称,招聘海报标题
-	'appName'			=> '晋江人力',
-	
+
+    // 微信小程序名称,招聘海报标题
+    'appName'      => '晋江人力',
+
     // 微信小程序AppId
-    'appId'				=> 'wxad3278410c424601',
+    'appId'        => 'wxad3278410c424601',
     // 微信小程序AppSecret
-    'appSecret'			=> 'd577ae5e42559033ac876bbe3131808b',
+    'appSecret'    => 'd577ae5e42559033ac876bbe3131808b',
     // 微信支付账号商户号
-    'payMchId'			=> '1526991841',
+    //    'payMchId'			=> '1526991841',
+    'payMchId'     => '1619349052',
+
     // 微信支付账号支付密钥
-    'payKey'			=> 'yangjialun19990928yangjie9721107',
-	// 微信支付回调地址
-	'payNotifyUrl'		=> "https://linggong.jinjianghc.com/mainapp.php/notify/orderwechat",
+    //    'payKey'			=> 'yangjialun19990928yangjie9721107',
+    'payKey'       => 'fFTEk1uLa6NJ7vhoi0w3C2y3qpY1ENhM',
+    // 微信支付回调地址
+    'payNotifyUrl' => "https://linggong.jinjianghc.com/mainapp.php/notify/orderwechat",
+    //证书序列号
+    'serial'       => '18DAE57714EB72C9D88158947E1217C1E7693C8A',
 
-	// 阿里身份证识别APPCODE
-	'aliAppCode'		=> '',
+    // 阿里身份证识别APPCODE
+    'aliAppCode'   => '',
 
 ];

+ 5 - 1
vendor/guzzlehttp/guzzle/src/Utils.php

@@ -71,7 +71,11 @@ final class Utils
             return \STDOUT;
         }
 
-        return \GuzzleHttp\Psr7\Utils::tryFopen('php://output', 'w');
+        if (DIRECTORY_SEPARATOR=='\\') {
+            return \GuzzleHttp\Psr7\Utils::tryFopen('php://stdout', 'w');
+        } else {
+            return \GuzzleHttp\Psr7\Utils::tryFopen('php://output', 'w');
+        }
     }
 
     /**