package com.hz.employmentsite.controller; import com.hz.employmentsite.filter.exception.BaseResponse; import com.hz.employmentsite.filter.exception.RespGenerstor; import com.hz.employmentsite.services.service.WechatService; import me.chanjar.weixin.common.error.WxErrorException; import org.apache.tomcat.util.buf.UDecoder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; import java.util.UUID; @RestController @RequestMapping("/api/wx") public class WxController { /*@Autowired private RemoteHelper remoteHelper; @GetMapping("/getWxToken") public String getWxToken() { Map params = new HashMap<>(); params.put("grant_type","client_credential"); params.put("appid","wx765e6ec59e26c288"); params.put("secret","a44d8034671866e957484f5ed4e1df48"); remoteHelper.getJson(params, "https://api.weixin.qq.com/cgi-bin/token",null); return ""; }*/ @Autowired private WechatService wechatService; @GetMapping("getOAuthUrl") public BaseResponse getOAuthUrl(String redirectUrl) throws UnsupportedEncodingException { return RespGenerstor.success(wechatService.getOAuthUrl(URLDecoder.decode(redirectUrl,"UTF-8"))); } @GetMapping("getOpenId") public BaseResponse getOpenId(String code) throws WxErrorException { return RespGenerstor.success(wechatService.getOpenId(code)); } @PostMapping("/sentMsg") public BaseResponse sentMsg() throws Exception { Map data = new HashMap<>(); data.put("thing28","张三"); data.put("phone_number34","134556456456"); data.put("thing10","开发"); 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", "-R2xeAeey7rOKN5VAuUr8cFMsJFlFp7ksN7m6H5_5VU",data)); } }