diff --git a/extend/Wechat/WechatPay.php b/extend/Wechat/WechatPay.php index 8c318bf..89c8723 100644 --- a/extend/Wechat/WechatPay.php +++ b/extend/Wechat/WechatPay.php @@ -271,20 +271,21 @@ class WechatPay $url = "v3/pay/transactions/out-trade-no/" . $out_trade_no . "/close"; $response = $app->getClient()->postJson($url, $options); - if ($response->isFailed()) { - // 出错了,处理异常 - $result = $response->toArray(false); - Log::getInstance()->info(json_encode($result,JSON_UNESCAPED_UNICODE)); - if(empty($result)){ - // 返回值为空 - throw new BusinessException("发起支付失败"); - } - if (!empty($result['code'])){ - if ($result['code'] != 400){ - throw new BusinessException($result['message']); + if (!empty($response)){ + if ($response->isFailed()) { + // 出错了,处理异常 + $result = $response->toArray(false); + if(empty($result)){ + // 返回值为空 + throw new BusinessException("关闭支付订单失败"); + } + if (!empty($result['code'])){ + if ($result['code'] != 400){ + throw new BusinessException($result['message']); + } + }else{ + throw new BusinessException("关闭支付订单失败"); } - }else{ - throw new BusinessException("关闭支付订单失败"); } }