jsp获取微信公众号网页授权和用户信息(code、access_token、openid等)

讲解用户在微信客户端中访问第三方网页,公众号可以通过微信网页授权机制,来获取用户基本信息,进而实现业务逻辑。

获取code、access_token、openid、用户昵称、地区、性别、头像等

官方文档
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Web_Developer_Tools.html#1

开发步骤
1、引导用户进入授权页面同意授权,获取code
2、通过code换取网页授权access_token(与基础支持中的access_token不同)
3、如果需要,开发者可以刷新网页授权access_token,避免过期
4、通过网页授权access_token和openid获取用户基本信息(支持UnionID机制)

第一步获取网页授权

String url = "";
String canshu = "";
url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
canshu = canshu + "appid=wx377e4ee387********;
canshu = canshu + "&redirect_uri="  + java.net.URLEncoder.encode("http://www.yaoyiwangluo.com/wx_jsp2.jsp","UTF-8");
canshu = canshu + "&response_type=code";
//canshu = canshu + "&scope=snsapi_base";  //授权项snsapi_userinfo,snsapi_base
canshu = canshu + "&scope=snsapi_userinfo";
canshu = canshu + "&state=123#wechat_redirect";
url = url + canshu;

response.sendRedirect(url);

欢迎收看视频详细实战
https://edu.csdn.net/course/detail/27000
在这里插入图片描述

黄菊华老师QQ:45157718

发布了305 篇原创文章 · 获赞 45 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/u013818205/article/details/103608830