yingzi 2 lat temu
rodzic
commit
07ca0604cd
2 zmienionych plików z 32 dodań i 0 usunięć
  1. 9 0
      app/api/controller/User.php
  2. 23 0
      app/model/api/Sys.php

+ 9 - 0
app/api/controller/User.php

@@ -380,6 +380,13 @@ class User extends BaseController
         if(!in_array($pay_type,["wxpay","balance"])){
             return app('json')->fail('不支持该支付方式!');
         }
+        
+        $weixinConfig = (new SysModel)->getWeixinConfig();
+//        if(empty($weixinConfig)){
+//            return app('json')->fail('支付配置为空!');
+//        }
+        
+        
         //缓存
         $redis = \think\facade\Cache::store('redis');
         $key   = 'show_template_order_sub_' . $request->user['uid'];
@@ -481,6 +488,8 @@ class User extends BaseController
                     ->select()
                     ->toArray();
             $wxpay = new wxpayApi();
+//            $wxpay = new wxpayApi($weixinConfig);
+            
             foreach ($payTrade as $v) {
 //                if($v['pay_type'] == 'wxpay') {
 //                    $result = $wxpay->closeOrder($v['pay_no']);

+ 23 - 0
app/model/api/Sys.php

@@ -91,4 +91,27 @@ class Sys extends Model
         $data["wxconfig"] = $wxconfig;
         return $data;
     }
+    
+    /**
+     * 获取微信配置
+     * @return bool
+     */
+    public function getWeixinConfig(){
+        $data = $this->getDataInfo("weixin");
+        foreach($data as $k=>$v){
+            if(empty($v)){
+                return false;
+            }
+        }
+        $return=[
+            "APPID"         => $data["appid"],
+            "APPSECRET"     => $data["secret"],
+            "MCHID"         => $data["mchid"],
+            "ApiV2Key"      => $data["apiv2key"],
+            "ApiclientKey"  => "file://".app()->getRootPath()."/".trim($data["apiclient_key"],"/"),
+            "ApiclientCert" => "file://".app()->getRootPath()."/".trim($data["apiclient_cert"],"/"),
+            "NOTIFY_URL"    => $data["notify_url"],
+        ];
+        return $return;
+    }
 }