Update WeChatMsgForwarderController.java

This commit is contained in:
2024-04-17 14:20:19 +08:00
parent c18e126dfd
commit f5d120817d

View File

@@ -22,18 +22,28 @@ public class WeChatMsgForwarderController {
this.handleWeChatMsgService = handleWeChatMsgService;
}
/**
* 接收微信消息。
*
* @param accessToken 访问令牌,用于验证请求的合法性。该参数通过请求头传递。
* @param weChatMsg 微信消息体,包含消息的各种内容。该参数通过请求体传递,并需通过验证。
* @return 返回处理结果,如果处理成功,返回成功状态和处理信息;如果失败,返回失败状态和错误信息。
*/
@PostMapping("/wechat")
public ServerResponseEntity receiveMsg(@RequestHeader("accessToken") String accessToken,
@RequestBody @Valid WeChatMsg weChatMsg){
@RequestBody @Valid WeChatMsg weChatMsg){
logger.info("weChatMsg: {}",weChatMsg.toString());
// 检查accessToken是否为空为空则返回错误信息
if(accessToken == null){
logger.warn("Access token is missing or empty");
return ServerResponseEntity.fail("accessToken cannot be empty.");
}
// 检查weChatMsg消息体是否有效无效则返回错误信息
if (weChatMsg.isInvalid()) {
logger.debug("CallInfo has invalid fields.");
return ServerResponseEntity.fail("json body value error.");
}
// 调用服务处理微信消息
return handleWeChatMsgService.handleMsg(accessToken,weChatMsg);
}
}