创建 WeChatMsgForwarderController.java
parent
f7d7e9e551
commit
42133da898
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue