赞
踩
通过code换取openid
通过微信小程序code获取openid
@PostMapping("/getOpenid") @CrossOrigin @ResponseBody public Map<String,Object> getOpenid(@RequestBody byte[] req) { HashMap<String, Object> objectObjectMap = new HashMap<>(); JSONObject json = JSONObject.parseObject(new String(req, Charset.forName("UTF-8"))); System.out.println("请求参数"+json); String code = json.get("code").toString(); //请求参数 String params = "appid=" + appid + "&secret=" + 微信密钥 + "&js_code=" + code + "&grant_type=" + grant_type; //发送请求 String sr = HttpUtils.sendGet("https://api.weixin.qq.com/sns/jscode2session" , params); JSONObject objects = JSONObject.parseObject(sr); Object openId = objects.get("openid"); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。