Browse Source

小程序支付

牟新芬 3 years ago
parent
commit
6198cbe50c
2 changed files with 27 additions and 4 deletions
  1. 19 2
      app/api/controller/v1/Weixin.php
  2. 8 2
      config/weixin.php

+ 19 - 2
app/api/controller/v1/Weixin.php

@@ -150,8 +150,8 @@ class Weixin extends BaseController
         $data['type'] = 'order';
         $data['time'] = time();
         Db::name('wx_notify')->insert($data);
-        $app = Factory::payment(config('weixin')['wxPay']);
         if ($from == 'weixin') {
+            $app = Factory::payment(config('weixin')['wxPay']);
             $result = $app->order->unify([
                 'body' => '支付订单',
                 'out_trade_no' => $order['order_id'],
@@ -164,7 +164,9 @@ class Weixin extends BaseController
             $jsConfig = $jssdk->bridgeConfig($result['prepay_id'], false);
             $json['result'] = $jsConfig;
             $json['type'] = 'WECHAT_PAY';
-        } else {
+        }
+        if ($from == 'h5') {
+            $app = Factory::payment(config('weixin')['wxPay']);
             $result = $app->order->unify([
                 'body' => '支付订单',
                 'out_trade_no' => $order['order_id'],
@@ -177,6 +179,21 @@ class Weixin extends BaseController
             $json['result'] = $jsConfig;
             $json['type'] = 'WECHAT_H5_PAY';
         }
+        if ($from == 'routine') {
+            $app = Factory::payment(config('weixin')['routinePay']);
+            $result = $app->order->unify([
+                'body' => '支付订单',
+                'out_trade_no' => $order['order_id'],
+                'total_fee' => $order['all_price'] * 100,
+                'notify_url' => 'https://www.boofly.cn/api/weixin/notify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+                'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
+                'openid' => $request->user['routine_openid']
+            ]);
+            $jssdk = $app->jssdk;
+            $jsConfig = $jssdk->bridgeConfig($result['prepay_id'], false);
+            $json['result'] = $jsConfig;
+            $json['type'] = 'ROUTINE_PAY';
+        }
         return app('json')->success($json);
     }
 

+ 8 - 2
config/weixin.php

@@ -13,14 +13,20 @@ return [
     'APPID'       => 'wx21448716e2a0b7df',
     'APPSECRET'   => '196324da0b037154c00ed3d29827eef7',
     'REDIRECT'    => 'http://www.boofly.cn/api/weixin/result',
+    'mini_program' => [
+        'app_id' => 'wxb4c2433f398a6a48',
+        'secret' => '3fb376e8197f3fb9670644adbcabae59'
+    ],
     'wxPay' => [
         'app_id' => 'wx21448716e2a0b7df',
         'mch_id' => '1611790333',
         'key' => 'W2GAkgcny9CkjIRpWviHuZwfmGP5Wk4f',
         'notify_url' => ''
     ],
-    'mini_program' => [
+    'routinePay' => [
         'app_id' => 'wxb4c2433f398a6a48',
-        'secret' => '3fb376e8197f3fb9670644adbcabae59'
+        'mch_id' => '1611790333',
+        'key' => 'W2GAkgcny9CkjIRpWviHuZwfmGP5Wk4f',
+        'notify_url' => ''
     ]
 ];