package com.kimgo.wepush.controller; import com.kimgo.wepush.model.WeChatMsg; import com.kimgo.wepush.response.ServerResponseEntity; import com.kimgo.wepush.service.HandleWeChatMsgService; import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @RestController @Validated @RequestMapping(value = "/api",method = RequestMethod.POST) public class WeChatMsgForwarderController { private final Logger logger = LoggerFactory.getLogger(WeChatMsgForwarderController.class); private final HandleWeChatMsgService handleWeChatMsgService; public WeChatMsgForwarderController(HandleWeChatMsgService handleWeChatMsgService) { this.handleWeChatMsgService = handleWeChatMsgService; } @PostMapping("/wechat") public ServerResponseEntity receiveMsg(@RequestHeader("accessToken") String accessToken, @RequestBody @Valid WeChatMsg weChatMsg){ logger.info("CallInfoO: {}",weChatMsg.toString()); if(accessToken == null){ logger.warn("Access token is missing or empty"); return ServerResponseEntity.fail("accessToken cannot be empty."); } if (weChatMsg.isInvalid()) { logger.debug("CallInfo has invalid fields."); return ServerResponseEntity.fail("json body value error."); } return handleWeChatMsgService.handleMsg(accessToken,weChatMsg); } }