创建 WeChatMsgForwarderController.java

pull/1/head
wangsiyuan 2023-12-12 18:28:20 +08:00
parent f7d7e9e551
commit 42133da898
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
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);
}
}