From 30b4f2384fc277fd15f63e79c752484738900bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Thu, 13 Apr 2017 19:26:20 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E4=BF=AE=E6=94=B9=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E6=94=AF=E4=BB=98=E6=B5=8B=E8=AF=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/wechat/controller/Notify.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/application/wechat/controller/Notify.php b/application/wechat/controller/Notify.php index f5aa368d8..9154445cd 100644 --- a/application/wechat/controller/Notify.php +++ b/application/wechat/controller/Notify.php @@ -15,6 +15,8 @@ namespace app\wechat\controller; use think\Controller; +use think\Db; +use think\Log; /** * 微信支付通知处理控制器 @@ -31,19 +33,30 @@ class Notify extends Controller { // 获取支付通知 $notifyInfo = $pay->getNotify(); - p($notifyInfo); // 支付通知数据获取失败 if ($notifyInfo === FALSE) { // 接口失败的处理 - echo $pay->errMsg; + Log::error("微信支付通知消息验证失败,{$pay->errCode}[{$pay->errCode}]"); + return $pay->errMsg; } else { //支付通知数据获取成功 if ($notifyInfo['result_code'] == 'SUCCESS' && $notifyInfo['return_code'] == 'SUCCESS') { + // 记录支付通知数据 + Db::name('WechatPayNotify')->insert($notifyInfo); + $prepayMap = ['out_trade_no' => $notifyInfo['out_trade_no']]; + $prepayData = Db::name('WechatPayPrepayid')->where($prepayMap)->find(); + if (empty($prepayData)) { + $pay->replyXml(['return_code' => 'ERROR', 'return_msg' => '系统中未发现对应的预支付记录!']); + } + $prepayUpdateData = ['transaction_id' => $notifyInfo['transaction_id'], 'is_pay' => 1, 'pay_at' => date('Y-m-d H:i:s')]; + if (false === Db::name('WechatPayPrepayid')->where($prepayMap)->update($prepayUpdateData)) { + $pay->replyXml(['return_code' => 'ERROR', 'return_msg' => '更新系统预支付记录失败!']); + } // 支付状态完全成功,可以更新订单的支付状态了 // @todo 这里去完成你的订单状态修改操作 // 回复xml,replyXml方法是终态方法 - $pay->replyXml(['return_code' => 'SUCCESS', 'return_msg' => 'DEAL WITH SUCCESS']); + $pay->replyXml(['return_code' => 'SUCCESS', 'return_msg' => '系统业务处理成功!']); } } }