fly 5 سال پیش
والد
کامیت
12f8c194ee

+ 58 - 8
app/Http/Controllers/QuickApp/Order/OrdersController.php

@@ -23,6 +23,7 @@ use App\Modules\Product\Services\ProductService;
 use App\Modules\Book\Services\BookConfigService;
 use App\Modules\Book\Services\BookService;
 use App\Modules\Channel\Services\PayTemplateService;
+use App\Modules\Trade\Models\PayMerchant;
 use App\Modules\Trade\Pay\OrderArousePayFactory;
 use App\Modules\Trade\Pay\OrderPaySuccess;
 use Exception;
@@ -468,14 +469,62 @@ class OrdersController extends BaseController
      *
      *       }
      */
-    function wxindex(Request $request)
+    function wxIndex(Request $request)
     {
         if ($params = $this->getPayParams($request)) {
-            $params['pay_merchant_source'] = 'QuickAppWxPay';
+            $params['pay_merchant_source'] = 'OFFICIALPAY_QAPP_APP';
         } else {
             return response()->error('QAPP_PARAM_ERROR');
         }
-        $app = OrderArousePayFactory::wxApp($this->uid);
+        $app = OrderArousePayFactory::wx($this->uid);
+        // 微信支付参数
+        $params['trade_type']   = 'APP'; //交易类型
+        $result = $app->handle($params);
+        if ($result) {
+            return response()->success($result);
+        } else {
+            return response()->error('APP_CREATE_WECHAT_ORDER_FAIL');
+        }
+    }
+
+    /**
+     * @apiVersion 1.0.0
+     * @apiDescription 微信H5支付
+     * @api {get} goToH5Pay 微信H5支付
+     * @apiGroup pay
+     * @apiName wxindex
+     * @apiParam {Int}  product_id   product_id
+     * @apiParam {Int}  send_order_id   send_order_id
+     * @apiParam {String}  bid   bid
+     * @apiHeader {String} [Authorization]  token
+     * @apiSuccess {int}   code 状态码
+     * @apiSuccess {String}  msg 信息
+     * @apiSuccess {Object}  data 信息
+     * @apiSuccess {Object}  data.appId 唤起支付的appId
+     * @apiSuccess {Object}  data.mch_id 唤起支付的mch_id
+     * @apiSuccess {Object}  data.nonce_str 唤起支付的nonce_str
+     * @apiSuccess {Object}  data.prepay_id 唤起支付的prepay_id
+     * @apiSuccess {Object}  data.sign 唤起支付的sign
+     * @apiSuccess {Object}  data.trade_type 唤起支付trade_type
+     * @apiSuccessExample {json} Success-Response:
+     *     HTTP/1.1 200 OK
+     *     {
+     *       code: 0,
+     *       msg: "",
+     *       data: {
+     *
+     *       }
+     */
+    function wxH5Index(Request $request)
+    {
+        if ($params = $this->getPayParams($request)) {
+            $params['pay_merchant_source'] = 'OFFICIALPAY_QAPP_H5';
+        } else {
+            return response()->error('QAPP_PARAM_ERROR');
+        }
+        $app = OrderArousePayFactory::wx($this->uid);
+        // 微信支付参数
+        $params['trade_type']   = 'MWEB'; //交易类型
         $result = $app->handle($params);
         if ($result) {
             return response()->success($result);
@@ -567,12 +616,13 @@ class OrdersController extends BaseController
     {
         $param = $request->except('_url');
         myLog('wxpay')->info($param);
+        $pay_merchant_name = $param['attach'];
+        $pay_merchant = PayMerchant::where('name', $pay_merchant_name)->first();
+        $pay_config = json_decode($pay_merchant->config_info);
         $config = [
-            // 微信支付参数
-            'appid'     => 'wx7ff41112e6dfb2d7', // 应用ID
-            'merchant_id'     => '1500977641', // 微信支付商户号
-            'key'    => '0e7SfPt3EOS0HC1GxVa4fqmCUINcN71E', // 微信支付密钥
-            'trade_type' => 'APP',
+            'appid'     => $pay_config->appid,
+            'merchant_id'     => $pay_config->merchant_id,
+            'key'    => $pay_config->key,
         ];
         $app = PayFactory::official($config);
         $response = $app->notify()->handleNotify(function ($notify, $successful) {

+ 1 - 0
app/Http/Routes/QuickApp/QuickAppRoutes.php

@@ -70,6 +70,7 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
         Route::get('readrecord/delete', 'User\ReadRecordController@delReadRecord');
         //支付
         Route::get('goToPay', 'Order\OrdersController@wxIndex');
+        Route::get('goToH5Pay', 'Order\OrdersController@wxH5Index');
         Route::get('goToAliPay', 'Order\OrdersController@aliIndex');
 
         Route::get('checkOrder', 'Order\OrdersController@checkOrder');

+ 11 - 0
app/Libs/Pay/Merchants/Official.php

@@ -89,6 +89,17 @@ class Official implements PayMerchantInterface
                         'trade_type' => $result->trade_type,
                     ];
                     break;
+                case 'MWEB':
+                    $data = [
+                        'appId' => $result->appid,
+                        'mch_id' => $result->mch_id,
+                        'prepay_id' => $result->prepay_id,
+                        'nonce_str' => $result->nonce_str,
+                        'sign' => $result->sign,
+                        'trade_type' => $result->trade_type,
+                        'mweb_url' => $result->mweb_url,
+                    ];
+                    break;
             }
             return $data;
         }

+ 1 - 1
app/Modules/Trade/Pay/OrderArousePayFactory.php

@@ -4,7 +4,7 @@ namespace App\Modules\Trade\Pay;
 
 /**
  * 
- * @method static \App\Modules\Trade\Pay\WxAppOrderArousePay wxApp(int uid)
+ * @method static \App\Modules\Trade\Pay\WxOrderArousePay wx(int uid)
  * @method static \App\Modules\Trade\Pay\AliOrderArousePay ali(int uid)
  */
 class OrderArousePayFactory

+ 10 - 7
app/Modules/Trade/Pay/WxAppOrderArousePay.php

@@ -3,18 +3,21 @@
 namespace App\Modules\Trade\Pay;
 
 use App\Libs\Pay\PayFactory;
+use App\Modules\Trade\Models\PayMerchant;
 use Log;
 
-class WxAppOrderArousePay extends OrderArousePayAbstract
+class WxOrderArousePay extends OrderArousePayAbstract
 {
     public function arouse(array $data)
     {
+        $pay_merchant_name = $data['pay_merchant_source'];
+        $pay_merchant = PayMerchant::where('name', $pay_merchant_name)->first();
+        $pay_config = json_decode($pay_merchant->config_info);
         $config = [
-            // 微信支付参数
-            'appid'     => 'wx7ff41112e6dfb2d7', // 应用ID
-            'merchant_id'     => '1500977641', // 微信支付商户号
-            'key'    => '0e7SfPt3EOS0HC1GxVa4fqmCUINcN71E', // 微信支付密钥
-            'trade_type' => 'APP',
+            'appid'     => $pay_config->appid,
+            'merchant_id'     => $pay_config->merchant_id,
+            'key'    => $pay_config->key,
+            'trade_type' => $data['trade_type'],
         ];
         $pay = PayFactory::official($config);
         try {
@@ -23,7 +26,7 @@ class WxAppOrderArousePay extends OrderArousePayAbstract
                 'price'        => $data['price'], // 订单金额,单位:分
                 'body'             => '快应用 小说', // 订单描述
                 'create_ip' => _getIp(), // 支付人的 IP
-                'remark'            => 'QuickApp'
+                'remark'            =>  $pay_merchant_name
             ];
             $result = $pay->send($payOrder);
             if ($result) {