shish 2 лет назад
Родитель
Сommit
a555b74562
2 измененных файлов с 54 добавлено и 38 удалено
  1. 39 34
      app-hd/controllers/PurchaseController.php
  2. 15 4
      common/components/lakala/Lakala.php

+ 39 - 34
app-hd/controllers/PurchaseController.php

@@ -25,6 +25,7 @@ use Yii;
 use common\components\util;
 use biz\wx\classes\WxMessageClass;
 use bizGhs\order\services\OrderService;
+use common\components\lakala\Lakala;
 
 class PurchaseController extends BaseController
 {
@@ -696,44 +697,48 @@ class PurchaseController extends BaseController
             util::success(['hasError' => 1, 'hasNoMiniOpenId' => 1]);
         }
         $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
-        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
-        $wxPayType = 0;
-        if (httpUtil::isMiniProgram()) {
-            $wxPayType = 1;
-        }
-        $attach = "couponId=" . $couponId . "&capitalType=" . $purchaseCapital . '&wxPayType=' . $wxPayType;
-        //订单30分钟后过期
-        $now = time();
-        $expireTime = $now + 1800;
-
-        $wx = Yii::getAlias("@vendor/weixin");
-        require_once($wx . '/lib/WxPay.Api.php');
-        require_once($wx . '/example/WxPay.JsApiPay.php');
-        $input = new \WxPayUnifiedOrder();
-        $input->SetBody($name);
-        $input->SetOut_trade_no($orderSn);
-        $input->SetTotal_fee($totalFee * 100);
-        $input->SetTime_start(date("YmdHis", $now));
-        //将流水类型、代金劵等传给微信再回传
-        $input->SetAttach($attach);
-        $input->SetTime_expire(date("YmdHis", $expireTime));
-        $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
-        $input->SetTrade_type("JSAPI");
+
         //花卉宝代为申请的微信支付
         $merchantExtend = WxOpenClass::getWxInfo();
 
-        if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
-            $input->SetSub_openid($openId);
-        } else {
-            $input->SetOpenid($openId);
+        $ghsId = $order->ghsId ?? 0;
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::fail('没有供货商信息');
         }
-
-        //强制使用小程序的miniAppId
-        $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-        $tools = new \JsApiPay();
-        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-        $newParams = json_decode($jsApiParameters, true);
+        $ghsShopId = $ghs->shopId ?? 0;
+        $ghsShop = ShopClass::getById($ghsShopId, true);
+        if (empty($ghsShop)) {
+            util::fail('没有供货商门店信息');
+        }
+
+        $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
+        $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
+        $params = [
+            'appid' => 'OP00002119',
+            'serial_no' => '018b08cfddbd',
+            'merchant_no' => $ghsShop->lklSjNo,
+            'term_no' => $ghsShop->lklScanTermNo,
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $laResource = new Lakala($params);
+        $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
+        $wxParams = [
+            'orderSn' => $orderSn,
+            'amount' => $totalFee,
+            'capitalType' => $purchaseCapital,
+            'notifyUrl' => $notifyUrl,
+            'wxAppId' => $merchantExtend['miniAppId'],
+            'openId' => $openId,
+            'subject' => $name,
+            'couponId' => $couponId,
+        ];
+        $response = $laResource->driveWxPay($wxParams);
+        if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+            util::fail('下单失败');
+        }
+        $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
         $newParams['id'] = $id;
         util::success($newParams);
     }

+ 15 - 4
common/components/lakala/Lakala.php

@@ -62,9 +62,15 @@ class Lakala
     }
 
     //主扫交易,支付宝
-    public function driveWxPay($orderSn, $amount)
+    public function driveWxPay($params)
     {
-        $notifyUrl = \Yii::$app->params['hdHost'] . "/notice/pay-callback";
+        $orderSn = $params['orderSn'];
+        $amount = $params['amount'];
+        $notifyUrl = $params['notifyUrl'];
+        $subject = $params['subject'];
+        $capitalType = $params['capitalType'];
+        $wxAppId = $params['wxAppId'];
+        $openId = $params['openId'];
         $location_info = ['request_ip' => $_SERVER['SERVER_ADDR']];
         $arr = [
             'merchant_no' => $this->merchant_no,
@@ -74,9 +80,14 @@ class Lakala
             'trans_type' => '71',
             'total_amount' => $amount * 100,
             'location_info' => $location_info,
-            'subject' => '购买花材',
+            'subject' => $subject,
             'notify_url' => $notifyUrl,
-            'remark' => '',
+            'remark' => '{"capitalType":' . $capitalType . '}',
+            'acc_busi_fields' => [
+                'sub_appid' => $wxAppId,
+                'user_id' => $openId,
+                'timeout_express' => 30,
+            ],
         ];
         $baseRequestVO = [
             'req_data' => $arr,