Browse Source

充值回调接口返回

shish 5 years ago
parent
commit
1a3195e887
1 changed files with 63 additions and 72 deletions
  1. 63 72
      app-ghs/controllers/RechargeController.php

+ 63 - 72
app-ghs/controllers/RechargeController.php

@@ -13,78 +13,69 @@ use Yii;
 class RechargeController extends BaseController
 {
 
-	//充值记录 shish 2021.2.21
-	public function actionList()
-	{
-		$where = ['shopId' => $this->shopId, 'payStatus' => RechargeClass::PAY_STATUS_HAS_PAY];
-		$list = RechargeClass::getRechargeList($where);
-		util::success($list);
-	}
+    //充值记录 shish 2021.2.21
+    public function actionList()
+    {
+        $where = ['shopId' => $this->shopId, 'payStatus' => RechargeClass::PAY_STATUS_HAS_PAY];
+        $list = RechargeClass::getRechargeList($where);
+        util::success($list);
+    }
 
-	//充值余额 shish 2021.2.21
-	public function actionBalance()
-	{
-		ini_set('date.timezone', 'Asia/Shanghai');
-		$get = Yii::$app->request->get();
-		$amount = $get['amount'] ?? 500;
-		$wxPay = dict::getConfig('payWay', 'wxPay');
-		$data = [
-			'amount' => $amount,
-			'payWay' => $wxPay,
-			'sjId' => $this->sjId,
-			'sjStyle' => MerchantClass::STYLE_RETAIL,
-			'shopId' => $this->shopId,
-			'modPrice' => 0,
-			'remark' => '',
-		];
-		$order = RechargeClass::addOrder($data);
-		$orderSn = $order['orderSn'];
-		$name = $order['orderName'] ?? '充值';
-		$totalFee = $order['amount'];
-		
-		//强制使用小程序的miniOpenId
-		$openId = $this->admin['miniOpenId'];
-		
-		$capitalTypeData = dict::getConfig('capitalType');
-		$capitalType = $capitalTypeData['xhRecharge']['id'];
-		//流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
-		$wxPayType = 0;
-		if (httpUtil::isMiniProgram()) {
-			$wxPayType = 1;
-		}
-		$attach = "couponId=0&capitalType=" . $capitalType . '&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::getGhsWxInfo();
-		if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
-			$input->SetSub_openid($openId);
-		} else {
-			$input->SetOpenid($openId);
-		}
-		
-		//强制使用小程序的AppId
-		$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-		
-		$wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-		$tools = new \JsApiPay();
-		$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-		$newParams = json_decode($jsApiParameters, true);
-		util::success($newParams);
-	}
+    //充值余额 shish 2021.2.21
+    public function actionBalance()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $get = Yii::$app->request->get();
+        $amount = $get['amount'] ?? 500;
+        $wxPay = dict::getConfig('payWay', 'wxPay');
+        $data = [
+            'amount' => $amount,
+            'payWay' => $wxPay,
+            'sjId' => $this->sjId,
+            'sjStyle' => MerchantClass::STYLE_RETAIL,
+            'shopId' => $this->shopId,
+            'modPrice' => 0,
+            'remark' => '',
+        ];
+        $order = RechargeClass::addOrder($data);
+        $orderSn = $order['orderSn'];
+        $name = $order['orderName'] ?? '充值';
+        $totalFee = $order['amount'];
+        //强制使用小程序的miniOpenId
+        $openId = $this->admin['miniOpenId'];
+        $capitalTypeData = dict::getConfig('capitalType');
+        $capitalType = $capitalTypeData['xhRecharge']['id'];
+        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+        $wxPayType = httpUtil::isMiniProgram() ? 1 : 0;
+        $attach = "couponId=0&capitalType=" . $capitalType . '&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['ghsHost'] . '/notice/wx-callback/');
+        $input->SetTrade_type("JSAPI");
+
+        $merchantExtend = WxOpenClass::getGhsWxInfo();
+        //平台代为申请支付商户号时使用
+        //$input->SetSub_openid($openId);
+        $input->SetOpenid($openId);
+
+        //强制使用小程序的AppId
+        $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+        $tools = new \JsApiPay();
+        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+        $newParams = json_decode($jsApiParameters, true);
+        util::success($newParams);
+    }
 
 }