WxController.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.hz.employmentsite.controller;
  2. import com.hz.employmentsite.filter.exception.BaseResponse;
  3. import com.hz.employmentsite.filter.exception.RespGenerstor;
  4. import com.hz.employmentsite.services.service.WechatService;
  5. import me.chanjar.weixin.common.error.WxErrorException;
  6. import org.apache.tomcat.util.buf.UDecoder;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.web.bind.annotation.GetMapping;
  9. import org.springframework.web.bind.annotation.PostMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import java.io.UnsupportedEncodingException;
  13. import java.net.URLDecoder;
  14. import java.util.HashMap;
  15. import java.util.Map;
  16. import java.util.UUID;
  17. @RestController
  18. @RequestMapping("/api/wx")
  19. public class WxController {
  20. /*@Autowired
  21. private RemoteHelper remoteHelper;
  22. @GetMapping("/getWxToken")
  23. public String getWxToken() {
  24. Map<String, String> params = new HashMap<>();
  25. params.put("grant_type","client_credential");
  26. params.put("appid","wx765e6ec59e26c288");
  27. params.put("secret","a44d8034671866e957484f5ed4e1df48");
  28. remoteHelper.getJson(params, "https://api.weixin.qq.com/cgi-bin/token",null);
  29. return "";
  30. }*/
  31. @Autowired
  32. private WechatService wechatService;
  33. @GetMapping("getOAuthUrl")
  34. public BaseResponse<String> getOAuthUrl(String redirectUrl) throws UnsupportedEncodingException {
  35. return RespGenerstor.success(wechatService.getOAuthUrl(URLDecoder.decode(redirectUrl,"UTF-8")));
  36. }
  37. @GetMapping("getOpenId")
  38. public BaseResponse<String> getOpenId(String code) throws WxErrorException {
  39. return RespGenerstor.success(wechatService.getOpenId(code));
  40. }
  41. @PostMapping("/sentMsg")
  42. public BaseResponse<String> sentMsg() throws Exception {
  43. Map<String,String> data = new HashMap<>();
  44. data.put("thing28","张三");
  45. data.put("phone_number34","134556456456");
  46. data.put("thing10","开发");
  47. return RespGenerstor.success(wechatService.sendMsg("ow5Mm61JAlqqNhZzcV9lLqTDnBCs", UUID.randomUUID().toString(),"http://www.bowintek.com/hzyz/mobile/index.html/#/jobUserInfo/index?userId=60ea0d5b-a75c-11ed-a6c5-7085c2a9999e",
  48. "-R2xeAeey7rOKN5VAuUr8cFMsJFlFp7ksN7m6H5_5VU",data));
  49. }
  50. }