微信公众号和微信小程序获取OPENID的方法

无论是微信小程序还是微信公众号获取OPENID都需要先获取code

获取code

        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + ticketWxConfig.getCustomAppId() +
                "&redirect_uri=" + URLEncoder.encode(redirect_uri, UTF_8) +
                "&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect";

微信公众号获取OPENID

            String getAccessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?"
                    + "appid=" + wxConfig.getCustomAppId()
                    + "&secret=" + wxConfig.getCustomSecret()
                    + "&code=" + code + "&grant_type=authorization_code";

微信小程序获取OPENID

            String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" +
                    wxConfig.getAppletsAppId() +
                    "&secret=" + wxConfig.getAppletsSecret() +
                    "&js_code=" + code + "&grant_type=authorization_code";

微信官方文档

你可能感兴趣的:(问题整理,小程序,openid,java)