WxController.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.PostMapping;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import java.util.HashMap;
  12. import java.util.Map;
  13. @RestController
  14. @RequestMapping("/api/wx")
  15. public class WxController {
  16. /*@Autowired
  17. private RemoteHelper remoteHelper;
  18. @GetMapping("/getWxToken")
  19. public String getWxToken() {
  20. Map<String, String> params = new HashMap<>();
  21. params.put("grant_type","client_credential");
  22. params.put("appid","wx765e6ec59e26c288");
  23. params.put("secret","a44d8034671866e957484f5ed4e1df48");
  24. remoteHelper.getJson(params, "https://api.weixin.qq.com/cgi-bin/token",null);
  25. return "";
  26. }*/
  27. @Autowired
  28. private WechatService wechatService;
  29. @GetMapping("getOAuthUrl")
  30. public BaseResponse<String> getOAuthUrl() {
  31. return RespGenerstor.success(wechatService.getOAuthUrl(""));
  32. }
  33. @GetMapping("getOpenId")
  34. public BaseResponse<String> getOpenId(String code) throws WxErrorException {
  35. return RespGenerstor.success(wechatService.getOpenId(code));
  36. }
  37. @PostMapping("/sentMsg")
  38. public BaseResponse<String> sentMsg(){
  39. Map<String,String> data = new HashMap<>();
  40. data.put("keyword1","巧克力");
  41. data.put("keyword2","39.8元");
  42. data.put("keyword3","2014年9月22日");
  43. return RespGenerstor.success(wechatService.sentMsg("admin",data));
  44. }
  45. }