notify_logic = new NotifyLogic(); $this->setChannel('notify'); } /** * @return ResponseInterface * @throws InvalidArgumentException * @throws RuntimeException * @throws ReflectionException * @throws Throwable */ public function notify(): ResponseInterface { $app = getWeChatMiniProgramPaymentApp(); $server = $app->getServer(); $server->handlePaid(function (Message $message, \Closure $next) use ($app) { // $message->out_trade_no 获取商户订单号 // $message->payer['openid'] 获取支付者 openid // 🚨🚨🚨 注意:推送信息不一定靠谱哈,请务必验证 // 建议是拿订单号调用微信支付查询接口, $this->info('接收回调消息', $message->toArray()); try{ // 验证通过,业务处理 $app->getValidator()->validate($app->getRequest()); // 查询订单 $response = $app->getClient()->postXml(V2Api::QUERY_ORDER->value, [ 'body' => [ 'appid' => config('wechat.payment.app_id'), 'mch_id' => config('wechat.payment.mch_id'), 'out_trade_no' => $message->out_trade_no ] ]); if ($response->isFailed()) { // 查询失败 $this->warning('订单查询失败', [$message->out_trade_no]); return $next($message); } // 不成功 if ( !isset($response['return_code'], $response['result_code']) || $response["return_code"] !== "SUCCESS" || $response["result_code"] !== "SUCCESS" ) { $this->warning('订单查询支付失败', [$message->out_trade_no, $response]); return $next($message); } // 业务处理 $result = $this->notify_logic->notifyHandle($message); $this->info('接受回调消息结果', ['result' => $result]); } catch(\Exception $e){ // 验证失败 $err_msg = '订单验证签名失败:'. $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); $this->error($err_msg, [$message->toArray()]); } return $next($message); }); return $server->serve(); } }