diff --git a/app/Http/Controllers/Manager/OrdersController.php b/app/Http/Controllers/Manager/OrdersController.php
index 57ae409..10bea66 100644
--- a/app/Http/Controllers/Manager/OrdersController.php
+++ b/app/Http/Controllers/Manager/OrdersController.php
@@ -589,18 +589,17 @@ class OrdersController extends CommonController
switch (request()->type) {
case "weixin":
- try {
- $res = (new WxMicroPay())->pay($recharge);
- return response()->json([
- "errorcode" => 0,
- "errormsg" => "支付成功!"
- ]);
- } catch (\Exception $exception) {
+ $res = (new WxMicroPay())->pay($recharge);
+ if ($res !== true) {
return response()->json([
"errorcode" => 60003,
- "errormsg" => $exception->getMessage()
+ "errormsg" => $res->getMessage()
]);
}
+ return response()->json([
+ "errorcode" => 0,
+ "errormsg" => "支付成功!"
+ ]);
break;
}
}
diff --git a/app/Libs/WxMicroPay.class.php b/app/Libs/WxMicroPay.class.php
index 63af454..65f8d53 100644
--- a/app/Libs/WxMicroPay.class.php
+++ b/app/Libs/WxMicroPay.class.php
@@ -10,21 +10,6 @@ class WxMicroPay extends WxPayCommon
{
public $pay_url = "https://api.mch.weixin.qq.com/pay/micropay";
- function checkParameters()
- {
- if (!$this->parameters["out_trade_no"]) {
- throw new Exception("缺少必填参数out_trade_no!" . "
");
- } elseif (!$this->parameters["body"]) {
- throw new Exception("缺少必填参数body!" . "
");
- } elseif (!$this->parameters["total_fee"]) {
- throw new Exception("缺少必填参数total_fee!" . "
");
- } elseif (!$this->parameters["auth_code"]) {
- throw new Exception("缺少必填参数auth_code!" . "
");
- } elseif (!strlen($this->parameters["auth_code"]) != 18) {
- throw new Exception("支付码不正确!" . "
");
- }
- }
-
/**
*
* 扫码支付,并且确认结果,接口比较慢
@@ -33,26 +18,38 @@ class WxMicroPay extends WxPayCommon
public function pay(Recharge $recharge)
{
//提交被扫支付
- $this->setParameter("out_trade_no", $recharge->serial);
- $this->setParameter("body", "充值{$recharge->money}元");
- $this->setParameter("total_fee", $recharge->money * 100);
- $this->setParameter("auth_code", request()->auth_code);
-
- $this->checkParameters();
- \Log::info($this->parameters);
- $xml = $this->createXml();
- $result = $this->postXmlCurl($xml, $this->pay_url);
- \Log::info($result);
- $result = $this->xmlToArray($result);
+ try {
+ $this->setParameter("out_trade_no", $recharge->serial);
+ $this->setParameter("body", "充值{$recharge->money}元");
+ $this->setParameter("total_fee", $recharge->money * 100);
+ $this->setParameter("auth_code", request()->auth_code);
- //如果返回成功
- if (!array_key_exists("return_code", $result) || !array_key_exists("result_code", $result)) {
- throw new Exception("接口调用失败");
- }
+ if (!$this->parameters["out_trade_no"]) {
+ throw new Exception("缺少必填参数out_trade_no!" . "
");
+ } elseif (!$this->parameters["body"]) {
+ throw new Exception("缺少必填参数body!" . "
");
+ } elseif (!$this->parameters["total_fee"]) {
+ throw new Exception("缺少必填参数total_fee!" . "
");
+ } elseif (!$this->parameters["auth_code"]) {
+ throw new Exception("缺少必填参数auth_code!" . "
");
+ } elseif (!strlen($this->parameters["auth_code"]) != 18) {
+ throw new Exception("支付码不正确!" . "
");
+ }
- dd($result);
+ \Log::info($this->parameters);
+ $xml = $this->createXml();
+ $result = $this->postXmlCurl($xml, $this->pay_url);
+ \Log::info($result);
+ $result = $this->xmlToArray($result);
- return true;
+ //如果返回成功
+ if (!array_key_exists("return_code", $result) || !array_key_exists("result_code", $result)) {
+ throw new Exception("接口调用失败");
+ }
+ return true;
+ } catch (Exception $exception) {
+ return $exception;
+ }
//取订单号
$out_trade_no = $microPayInput->GetOut_trade_no();