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(); $message = $server->getRequestMessage(); $this->info('接收回调消息', $message->toArray()); try { // 验证签名通过,业务处理 // $app->getValidator()->validate($app->getRequest()); // 业务处理 $result = $this->notify_logic->notifyHandle($message); $this->info('接受回调消息结果', ['result' => $result]); if ($result) { return $this->returnSuccess(); } return $this->returnFailure('订单处理失败'); } catch (Exception $e) { // 验证失败 $err_msg = '订单处理流程失败:' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); $this->error($err_msg, [$message->toArray()]); // 返回 SUCCESS 或者 FAIL 等其他状态 return $this->returnFailure('订单处理异常'); } } /** * 返回成功 * @return Response */ public function returnSuccess(): Response { return new Response(200, [], Xml::build([ 'return_code' => 'SUCCESS', 'return_msg' => 'OK' ]) ); } /** * 返回失败 * @param string $error_msg * @return Response */ public function returnFailure(string $error_msg): Response { return new Response(200, [], Xml::build([ 'return_code' => 'FAIL', 'return_msg' => $error_msg ]) ); } }