springboot通过code获取微信小程序openId
@RequestMapping("/getOpenId")public Result wx(@RequestBody Map<String,Object> map) {Map<String, Object> remap = new HashMap<>();//1、向微信服务器 使用登录凭证 code 获取 session_key 和 openidString u
·
@RequestMapping("/getOpenId")
public Result wx(@RequestBody Map<String,Object> map) {
Map<String, Object> remap = new HashMap<>();
//1、向微信服务器 使用登录凭证 code 获取 session_key 和 openid
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxAppID +
"&secret=" + secret +
"&js_code=" + map.get("code").toString() +
"&grant_type=authorization_code";
ResponseEntity<String> res = restTemplate.getForEntity(url, String.class);
JSONObject jsonObject = JSONObject.parseObject(res.getBody());
remap.put("openId",jsonObject.get("openid").toString());
return ResultUtil.success(remap);
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)