工具类
public class ComonUtils {
public static StringBuffer appendUrl(StringInput code) {
StringBuffer info = new StringBuffer("https://api.weixin.qq.com/sns/jscode2session?");
info.append("appid=").append("替换你的小程序的appid").append("&");
info.append("secret=").append("替换你的小程序的secret").append("&");
info.append("js_code=").append(code.getStrValue()).append("&");
info.append("grant_type=").append("authorization_code");
return info;
}
}
远程调用使用restTemplate
@ApiOperation(value = "获取openid")
@PostMapping(value = "/getappid")
public SuccessOutPut<AppOutPut> getappid(@RequestBody StringInput code) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8)