Browse Source

【Mod】修复正式因配置缓存导致的支付失败

liuxiangxin 4 months ago
parent
commit
27b74f0b9c
1 changed files with 10 additions and 12 deletions
  1. 10 12
      app/Servers/WechatPay/Payment.php

+ 10 - 12
app/Servers/WechatPay/Payment.php

@@ -5,7 +5,6 @@ use DateTimeZone;
 use App\Facades\Servers\Logs\Log;
 use WeChatPay\Builder;
 use WeChatPay\Crypto\Rsa;
-use WeChatPay\Util\PemUtil;
 use WeChatPay\Formatter;
 
 class Payment
@@ -14,12 +13,11 @@ class Payment
     private $mchid;
     private $instance;
     private $merchantPrivateKeyInstance;
-    private $merchantCertificateSerial;
 
     function __construct()
     {
         // 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名
-        $merchantPrivateKeyFilePath = Config('wechatpay.private_key');
+        $merchantPrivateKeyFilePath = config('wechatpay.private_key');
         //$merchantPrivateKeyFilePath = 'file://D:\phpstudy_pro\WWW\mall\kailin\resources\1612111355_20241118_cert\apiclient_key.pem';
         $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
 
@@ -27,7 +25,7 @@ class Payment
         $merchantCertificateSerial = '4A5F7CFCC3280CF8C09735D5FC2DEFBC9CCD6F46';
 
         // 从本地文件中加载「微信支付平台证书」或者「微信支付平台公钥」,用来验证微信支付应答的签名
-        $platformCertificateOrPublicKeyFilePath = Config('wechatpay.platformCertificate');
+        $platformCertificateOrPublicKeyFilePath = config('wechatpay.platformCertificate');
         $platformPublicKeyInstance =    Rsa::from($platformCertificateOrPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC);
 
         // 「微信支付平台证书」的「证书序列号」或者是「微信支付平台公钥ID」
@@ -36,7 +34,7 @@ class Payment
 
         // 构造一个 APIv3 客户端实例
         $instance = Builder::factory([
-            'mchid'      => Config('wechatpay.mchid'),
+            'mchid'      => config('wechatpay.mchid'),
             'serial'     => $merchantCertificateSerial,
             'privateKey' => $merchantPrivateKeyInstance,
             'certs'      => [
@@ -44,10 +42,10 @@ class Payment
             ],
         ]);
         $this->instance   = $instance;
-        $this->appid   = Config('wechatpay.appid');
-        $this->mchid   = Config('wechatpay.mchid');
+        $this->appid   = config('wechatpay.appid');
+        $this->mchid   = config('wechatpay.mchid');
         $this->merchantPrivateKeyInstance   = $merchantPrivateKeyInstance;
-        $this->merchantCertificateSerial   = Config('wechat.certificate');
+        $this->merchantCertificateSerial   = config('wechat.certificate');
         return;
     }
     /**
@@ -55,7 +53,7 @@ class Payment
      */
     public function pay($params)
     {
-        $notify_url = Config('wechatpay.notify_url');
+        $notify_url = config('wechatpay.notify_url');
         //调用微信JSAPI下单获取预支付交易会话标识
         try {
             $resp = $this->instance
@@ -66,7 +64,7 @@ class Payment
                     'appid'        => $this->appid,
                     'description'  => $params['description'],
                     /*'time_expire'  => $this->timestampToRfc3339(time() + env('ORDER_OUT_TIME')*60),*/
-                    'notify_url'   => env('APP_URL').'/api/wechat_pay/notify',
+                    'notify_url'   => $notify_url,
                     'amount'       => [
                         //'total'    => 1,
                         'total'    => $params['total_price']*100,
@@ -125,7 +123,7 @@ class Payment
      */
     public function refund($params)
     {
-        $notify_url = Config('wechat.course_refund_notify_url');
+        $notify_url = config('wechat.course_refund_notify_url');
         try {
             $resp = $this->instance
                 ->chain('v3/refund/domestic/refunds')
@@ -133,7 +131,7 @@ class Payment
                     'out_trade_no'      => $params['out_trade_no'],
                     'out_refund_no'   => $params['out_refund_no'],
                     'reason'          => $params['reason'] ?? '用户退款',
-                    'notify_url'      => env('APP_URL').'/api/wechat_pay/refund_notify',
+                    'notify_url'      => $notify_url,
                     'amount'          => [
                         'refund'      => $params['refund'] * 100,
                         'total'       => $params['total'] * 100,