微信公众号获取openId流程

Qamar ·
更新时间:2024-09-21
· 855 次阅读

1、从微信后台获取code:用户请求微信后台,带上appid等参数
“https://open.weixin.qq.com/connect/oauth2/authorize?appid=” + appId + “&redirect_uri=” + redirectUri + “&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect”;
2、上一步请求成功后,微信会回调 redirectUri 地址,并在参数后带上code和state:
redirect_uri/?code=CODE&state=STATE。
3、后台根据code,向微信后台请求用户的openid:
String url = “https://api.weixin.qq.com/sns/oauth2/access_token?appid=” + appId
+ “&secret=” + appSecret + “&code=” + code
+ “&grant_type=authorization_code”;
4、从上一步的返回结果中可以获取openid


作者:xiaoniuxqq



公众号 openid 微信公众号

需要 登录 后方可回复, 如果你还没有账号请 注册新账号