|
|
|
|
@ -23,7 +23,6 @@ class WxMicroPay extends WxPayCommon
|
|
|
|
|
$this->setParameter("body", "充值{$recharge->money}元");
|
|
|
|
|
$this->setParameter("total_fee", $recharge->money * 100);
|
|
|
|
|
$this->setParameter("auth_code", request()->auth_code);
|
|
|
|
|
\Log::info($this->parameters);
|
|
|
|
|
|
|
|
|
|
if (!$this->parameters["out_trade_no"]) {
|
|
|
|
|
throw new Exception("缺少必填参数out_trade_no!");
|
|
|
|
|
@ -44,16 +43,42 @@ class WxMicroPay extends WxPayCommon
|
|
|
|
|
|
|
|
|
|
//判断接口是否返回成功
|
|
|
|
|
if (!array_key_exists("return_code", $result) || !array_key_exists("result_code", $result)) {
|
|
|
|
|
throw new Exception("接口调用失败");
|
|
|
|
|
throw new Exception("接口调用失败!");
|
|
|
|
|
}
|
|
|
|
|
if ($result["return_code"] == "SUCCESS" && $result["result_code"] == "FAIL" && $result["err_code"] != "USERPAYING" && $result["err_code"] != "SYSTEMERROR") {
|
|
|
|
|
throw new Exception("支付失败!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception $exception) {
|
|
|
|
|
return $exception;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询支付结果
|
|
|
|
|
$out_trade_no = $this->parameters["out_trade_no"];
|
|
|
|
|
$queryTimes = 10;
|
|
|
|
|
while ($queryTimes > 0) {
|
|
|
|
|
$succResult = 0;
|
|
|
|
|
$queryResult = $this->query($out_trade_no, $succResult);
|
|
|
|
|
//如果需要等待1s后继续
|
|
|
|
|
if ($succResult == 2) {
|
|
|
|
|
sleep(2);
|
|
|
|
|
continue;
|
|
|
|
|
} else if ($succResult == 1) {//查询成功
|
|
|
|
|
event();
|
|
|
|
|
return $queryResult;
|
|
|
|
|
} else {//订单交易失败
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//4、次确认失败,则撤销订单
|
|
|
|
|
if (!$this->cancel($out_trade_no)) {
|
|
|
|
|
throw new WxpayException("撤销单失败!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//取订单号
|
|
|
|
|
$out_trade_no = $microPayInput->GetOut_trade_no();
|
|
|
|
|
|
|
|
|
|
|