springboot通过code获取微信公众号openId


    @RequestMapping("/getOpenId")
    public String wxcallback(String code){
        // 第二步:通过code换取网页授权access_token
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxAppID +
                "&secret=" + secret +
                "&code=" + code +
                "&grant_type=authorization_code";

        ResponseEntity res = restTemplate.getForEntity(url, String.class);
        JSONObject jsonObject = JSONObject.parseObject(res.getBody());
        return jsonObject.get("openid").toString();
    }

你可能感兴趣的:(微信开发,springboot,微信公众号)