WechatCustomerController.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.ydtech.modules.admin.controller.wechat;
  2. import com.fasterxml.jackson.core.JsonProcessingException;
  3. import com.ydtech.core.page.HttpResult;
  4. import com.ydtech.modules.admin.components.wechat.customer.response.CustomerListResponse;
  5. import com.ydtech.modules.admin.service.WechatCustomerService;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiOperation;
  8. import lombok.RequiredArgsConstructor;
  9. import lombok.extern.slf4j.Slf4j;
  10. import me.chanjar.weixin.common.error.WxErrorException;
  11. import org.springframework.http.MediaType;
  12. import org.springframework.web.bind.annotation.*;
  13. import javax.servlet.http.HttpServletRequest;
  14. import java.util.List;
  15. @Api(tags = "微信业务")
  16. @Slf4j
  17. @RestController
  18. @RequestMapping("/wechat/customer")
  19. @RequiredArgsConstructor
  20. public class WechatCustomerController {
  21. private final WechatCustomerService customerService;
  22. @GetMapping(path = "/callback")
  23. @ApiOperation(value = "客服回调")
  24. public String customerCallback(@RequestParam(value = "msg_signature") String msgSignature,
  25. @RequestParam(value = "timestamp") String timestamp,
  26. @RequestParam(value = "nonce") String nonce,
  27. @RequestParam(value = "echostr") String echoStr) {
  28. return customerService.customerCallback(msgSignature, timestamp, nonce, echoStr);
  29. }
  30. @PostMapping(path = "/callback", consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
  31. @ApiOperation(value = "客服回调(处理事件发送欢迎语)")
  32. public HttpResult<String> customerCallback(@RequestBody String wechatEncrypt) throws JsonProcessingException, WxErrorException {
  33. customerService.callbackSendMsgOnEvent(wechatEncrypt);
  34. return HttpResult.ok();
  35. }
  36. @PostMapping(path = "/list")
  37. @ApiOperation(value = "客服列表")
  38. public HttpResult<List<CustomerListResponse.AccountListDTO>> list() throws JsonProcessingException {
  39. List<CustomerListResponse.AccountListDTO> list = customerService.list();
  40. return HttpResult.ok(list);
  41. }
  42. }