WechatController.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.ydtech.modules.admin.controller;
  2. import cn.hutool.core.util.XmlUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.fasterxml.jackson.core.JsonProcessingException;
  5. import com.fasterxml.jackson.dataformat.xml.XmlMapper;
  6. import com.ydtech.core.page.HttpResult;
  7. import com.ydtech.exception.SystemException;
  8. import com.ydtech.modules.admin.model.vo.WechatBindVo;
  9. import com.ydtech.modules.admin.model.vo.WechatLoginVo;
  10. import com.ydtech.modules.admin.model.vo.WechatVo;
  11. import com.ydtech.modules.admin.model.vo.wechat.WechatCustomerCallbackVo;
  12. import com.ydtech.modules.admin.model.vo.wechat.WechatEncryptVo;
  13. import com.ydtech.modules.admin.service.WechatService;
  14. import com.ydtech.modules.base.controller.BaseController;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiOperation;
  17. import io.swagger.models.Xml;
  18. import lombok.AllArgsConstructor;
  19. import lombok.Data;
  20. import lombok.NoArgsConstructor;
  21. import lombok.RequiredArgsConstructor;
  22. import lombok.extern.slf4j.Slf4j;
  23. import me.chanjar.weixin.common.error.WxErrorException;
  24. import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
  25. import me.chanjar.weixin.cp.api.WxCpKfService;
  26. import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgListResp;
  27. import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendRequest;
  28. import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.http.MediaType;
  31. import org.springframework.web.bind.annotation.*;
  32. import java.util.List;
  33. @Api(tags = "微信业务")
  34. @Slf4j
  35. @RestController
  36. @RequestMapping("/wechat")
  37. @RequiredArgsConstructor
  38. public class WechatController extends BaseController {
  39. private final WechatService wechatService;
  40. @PostMapping("/login")
  41. @ApiOperation(value = "登录")
  42. public HttpResult<WechatVo> login(@RequestBody WechatLoginVo wechatLoginVo) {
  43. try {
  44. return wechatService.login(wechatLoginVo);
  45. } catch (WxErrorException e) {
  46. log.info(e.getMessage());
  47. throw new SystemException("微信授权失败");
  48. }
  49. }
  50. @PostMapping("/bind")
  51. @ApiOperation(value = "工号绑定微信")
  52. public HttpResult<Object> bind(@RequestBody WechatBindVo wechatBindVo) throws WxErrorException {
  53. try {
  54. String userId = getUserId();
  55. return wechatService.bind(wechatBindVo, userId);
  56. } catch (WxErrorException e) {
  57. log.info(e.getMessage());
  58. throw new SystemException("微信授权失败");
  59. }
  60. }
  61. }