panda 1 年之前
父节点
当前提交
c287c50afe
共有 2 个文件被更改,包括 78 次插入87 次删除
  1. 16 71
      application/api/controller/HuiPay.php
  2. 62 16
      application/api/controller/HuiPayBak.php

+ 16 - 71
application/api/controller/HuiPay.php

@@ -6,6 +6,7 @@ use addons\epay\library\Service;
 use app\common\controller\Api;
 use app\common\controller\Api;
 use app\utils\CurlUtil;
 use app\utils\CurlUtil;
 use app\utils\Easywechat\MiniAppService;
 use app\utils\Easywechat\MiniAppService;
+use app\utils\JingXiu\JingXiuPayUtil;
 use app\utils\LogUtil;
 use app\utils\LogUtil;
 use app\utils\PayUtil;
 use app\utils\PayUtil;
 use think\Cache;
 use think\Cache;
@@ -22,8 +23,6 @@ class HuiPay extends Api
     const LOG_MODULE = 'HuiPay';
     const LOG_MODULE = 'HuiPay';
     protected $noNeedLogin = ['vip_recharge', 'gold_recharge', 'pay', 'pay_notify'];
     protected $noNeedLogin = ['vip_recharge', 'gold_recharge', 'pay', 'pay_notify'];
     protected $noNeedRight = '*';
     protected $noNeedRight = '*';
-    // h5 跳转小程序
-    const H5 = 'https://mp-pay-0gk77hzo6366ff37-1320524135.tcloudbaseapp.com';
 
 
     public function _initialize()
     public function _initialize()
     {
     {
@@ -106,12 +105,14 @@ class HuiPay extends Api
                 throw new Exception('下单失败');
                 throw new Exception('下单失败');
             }
             }
 
 
-            // h5跳转小程序支付链接
-            $url = self::H5 . "?order_no={$pay_no}&money=$money";
             Db::commit();
             Db::commit();
-            $this->success('success', [
-                'url' => $url
-            ]);
+
+            $pay = new JingXiuPayUtil();
+            if (!$pay->wxWapPay($pay_no,$money,'充值会员','/api/hui_pay/pay_notify')){
+                $this->error($pay->getMessage());
+            }
+            $data = $pay->getData();
+            $this->success('success', $data);
         } catch (Exception $e) {
         } catch (Exception $e) {
             Db::rollback();
             Db::rollback();
             $this->error($e->getMessage());
             $this->error($e->getMessage());
@@ -197,12 +198,13 @@ class HuiPay extends Api
                 throw new Exception('下单失败');
                 throw new Exception('下单失败');
             }
             }
 
 
-            // h5跳转小程序支付链接
-            $url = self::H5 . "?order_no={$pay_no}&money=$money";
             Db::commit();
             Db::commit();
-            $this->success('success', [
-                'url' => $url
-            ]);
+            $pay = new JingXiuPayUtil();
+            if (!$pay->wxWapPay($pay_no,$money,'充值金币','/api/hui_pay/pay_notify')){
+                $this->error($pay->getMessage());
+            }
+            $data = $pay->getData();
+            $this->success('success', $data);
         } catch (Exception $e) {
         } catch (Exception $e) {
             Db::rollback();
             Db::rollback();
             $this->error($e->getMessage());
             $this->error($e->getMessage());
@@ -210,54 +212,6 @@ class HuiPay extends Api
     }
     }
 
 
     /**
     /**
-     * 汇付 支付
-     */
-    public function pay()
-    {
-        $params = \request()->post();
-        $order_no = $params['order_no'] ?? '';
-        if ($params['openid'] != 9696) {
-            $wxInfo = Cache::get($params['openid'] ?? '');
-            $openid = $wxInfo['openid'] ?? '';
-        } else {
-            $openid = 'ol8qS68vKSgWJ3Unrgfyi3rkakcQ';
-        }
-
-        if (empty($order_no) || empty($openid)) {
-            $this->error('支付超时,请重新下单支付');
-        }
-
-        // 获取下单信息
-        $order = Db::name('pay_order')->where('pay_no', $order_no)->find();
-        if (!$order) {
-            $this->error('订单不存在,请重新下单支付');
-        }
-
-        $money = $order['money'];
-        $money = '0.01';// 测试支付
-
-//        $order_no = "D0" . time();
-
-        $pay = new PayUtil();
-        $notify_url = CurlUtil::getHttp('/api/hui_pay/pay_notify', false);
-        if (!$pay->jsPay($openid, $order_no, $money, $order['memo'] ?? '商品下单支付', $notify_url)) {
-            $this->error($pay->getMessage());
-        }
-
-        $res = $pay->getData();
-        if (empty($res['data']['pay_info']) || !$pay_info = json_decode($res['data']['pay_info'], true)) {
-            $this->error('支付信息有误');
-            // exit;
-            // 这里 不加 exit 编辑器可能会提示  $pay_info 有可能不存在的变量 是因为 fastadmin 自带 error 写法不规范导致的
-        }
-
-        $this->success('success', [
-            'pay_info' => $pay_info,// 这里编辑器可能会提示  有可能不存在的变量 是因为 fastadmin 自带 error 写法不规范导致的
-            'order_no' => $order_no
-        ]);
-    }
-
-    /**
      * 支付回调
      * 支付回调
      *
      *
      * @param Request $request
      * @param Request $request
@@ -269,17 +223,8 @@ class HuiPay extends Api
     public function pay_notify(Request $request)
     public function pay_notify(Request $request)
     {
     {
         $params = $request->param();
         $params = $request->param();
-
-        // 消息主体信息
-        $resp_data_json = htmlspecialchars_decode($params['resp_data'] ?? '');
-        $resp_data = json_decode(stripslashes($resp_data_json), true);
-        unset($params['resp_data']);
-
-        LogUtil::info('支付回调参数', self::LOG_MODULE, __FUNCTION__, [
-            'params' => $params,
-            'resp_data2' => base64_encode($resp_data_json),
-            'resp_data' => $resp_data,
-        ]);
+        LogUtil::info('支付回调参数', self::LOG_MODULE, __FUNCTION__, $params);
+        return 'SUCCESS';
 
 
         // 校验回调信息
         // 校验回调信息
         if (empty($params['resp_code']) || $params['resp_code'] != '00000000' || empty($resp_data['req_seq_id'])) {
         if (empty($params['resp_code']) || $params['resp_code'] != '00000000' || empty($resp_data['req_seq_id'])) {

+ 62 - 16
application/api/controller/JingXiuPay.php → application/api/controller/HuiPayBak.php

@@ -6,7 +6,6 @@ use addons\epay\library\Service;
 use app\common\controller\Api;
 use app\common\controller\Api;
 use app\utils\CurlUtil;
 use app\utils\CurlUtil;
 use app\utils\Easywechat\MiniAppService;
 use app\utils\Easywechat\MiniAppService;
-use app\utils\JingXiu\JingXiuPayUtil;
 use app\utils\LogUtil;
 use app\utils\LogUtil;
 use app\utils\PayUtil;
 use app\utils\PayUtil;
 use think\Cache;
 use think\Cache;
@@ -17,12 +16,14 @@ use think\Request;
 /**
 /**
  * 通行证
  * 通行证
  */
  */
-class JingXiuPay extends Api
+class HuiPay extends Api
 {
 {
     // 日志模块名称
     // 日志模块名称
-    const LOG_MODULE = 'JingXiuPay';
+    const LOG_MODULE = 'HuiPay';
     protected $noNeedLogin = ['vip_recharge', 'gold_recharge', 'pay', 'pay_notify'];
     protected $noNeedLogin = ['vip_recharge', 'gold_recharge', 'pay', 'pay_notify'];
     protected $noNeedRight = '*';
     protected $noNeedRight = '*';
+    // h5 跳转小程序
+    const H5 = 'https://mp-pay-0gk77hzo6366ff37-1320524135.tcloudbaseapp.com';
 
 
     public function _initialize()
     public function _initialize()
     {
     {
@@ -105,14 +106,12 @@ class JingXiuPay extends Api
                 throw new Exception('下单失败');
                 throw new Exception('下单失败');
             }
             }
 
 
+            // h5跳转小程序支付链接
+            $url = self::H5 . "?order_no={$pay_no}&money=$money";
             Db::commit();
             Db::commit();
-
-            $pay = new JingXiuPayUtil();
-            if (!$pay->wxWapPay($pay_no,$money,'充值会员','/api/jing_xiu_pay/pay_notify')){
-                $this->error($pay->getMessage());
-            }
-            $data = $pay->getData();
-            $this->success('success', $data);
+            $this->success('success', [
+                'url' => $url
+            ]);
         } catch (Exception $e) {
         } catch (Exception $e) {
             Db::rollback();
             Db::rollback();
             $this->error($e->getMessage());
             $this->error($e->getMessage());
@@ -198,13 +197,12 @@ class JingXiuPay extends Api
                 throw new Exception('下单失败');
                 throw new Exception('下单失败');
             }
             }
 
 
+            // h5跳转小程序支付链接
+            $url = self::H5 . "?order_no={$pay_no}&money=$money";
             Db::commit();
             Db::commit();
-            $pay = new JingXiuPayUtil();
-            if (!$pay->wxWapPay($pay_no,$money,'充值会员','/api/jing_xiu_pay/pay_notify')){
-                $this->error($pay->getMessage());
-            }
-            $data = $pay->getData();
-            $this->success('success', $data);
+            $this->success('success', [
+                'url' => $url
+            ]);
         } catch (Exception $e) {
         } catch (Exception $e) {
             Db::rollback();
             Db::rollback();
             $this->error($e->getMessage());
             $this->error($e->getMessage());
@@ -212,6 +210,54 @@ class JingXiuPay extends Api
     }
     }
 
 
     /**
     /**
+     * 汇付 支付
+     */
+    public function pay()
+    {
+        $params = \request()->post();
+        $order_no = $params['order_no'] ?? '';
+        if ($params['openid'] != 9696) {
+            $wxInfo = Cache::get($params['openid'] ?? '');
+            $openid = $wxInfo['openid'] ?? '';
+        } else {
+            $openid = 'ol8qS68vKSgWJ3Unrgfyi3rkakcQ';
+        }
+
+        if (empty($order_no) || empty($openid)) {
+            $this->error('支付超时,请重新下单支付');
+        }
+
+        // 获取下单信息
+        $order = Db::name('pay_order')->where('pay_no', $order_no)->find();
+        if (!$order) {
+            $this->error('订单不存在,请重新下单支付');
+        }
+
+        $money = $order['money'];
+        $money = '0.01';// 测试支付
+
+//        $order_no = "D0" . time();
+
+        $pay = new PayUtil();
+        $notify_url = CurlUtil::getHttp('/api/hui_pay/pay_notify', false);
+        if (!$pay->jsPay($openid, $order_no, $money, $order['memo'] ?? '商品下单支付', $notify_url)) {
+            $this->error($pay->getMessage());
+        }
+
+        $res = $pay->getData();
+        if (empty($res['data']['pay_info']) || !$pay_info = json_decode($res['data']['pay_info'], true)) {
+            $this->error('支付信息有误');
+            // exit;
+            // 这里 不加 exit 编辑器可能会提示  $pay_info 有可能不存在的变量 是因为 fastadmin 自带 error 写法不规范导致的
+        }
+
+        $this->success('success', [
+            'pay_info' => $pay_info,// 这里编辑器可能会提示  有可能不存在的变量 是因为 fastadmin 自带 error 写法不规范导致的
+            'order_no' => $order_no
+        ]);
+    }
+
+    /**
      * 支付回调
      * 支付回调
      *
      *
      * @param Request $request
      * @param Request $request