当前位置:网站首页>微信公众号网页授权登录实现起来如此简单
微信公众号网页授权登录实现起来如此简单
2022-07-05 16:14:00 【华为云】
前言
这篇文章带大家掌握 从0到1实现微信公众平台授权登录
- 微信公众号授权登录到底哪几步
- 回调地址,安全域名怎么配置
- 代码怎么写
- 出了问题怎么办
一、微信公众号授权登录到底哪几步
官方文档介绍
文档看似很复杂,实际上前端只需要两步:
1、去访问微信提供的一个url地址
或者
两种的区别是:scope为snsapi_base和scope为snsapi_userinfo,区别就是是否弹出用户授权;
| 应用授权作用域,snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),snsapi_userinfo (弹出授权页面,可通过 openid 拿到昵称、性别、所在地。并且, 即使在未关注的情况下,只要用户授权,也能获取其信息 ) |
这个地址需要你配置的地方有:appid(微信公众号id)和redirect_uri(回调地址)
2、访问这个地址后,微信会回跳你设置的redirect_uri地址,并且带回来一个code,
把这个code传给后台,后台去访问微信的接口,获取用户的openid和access_token,
到这里也用实现了微信的授权登录。
二、回调地址,安全域名怎么配置
- 1、在申请到认证公众号之前,你可以先通过测试号申请系统,快速申请一个接口测试号,立即开始接口测试开发。(测试号申请地址)
redirect_uri的配置:
只需要 (请注意,这里填写的是域名(是一个字符串),而不是URL,因此请勿加 http:// 等协议头;)。
(1)打开微信公众号测试号(方便开发调式),修改js安全域名,也可以设置192的地址
(2)找到体验接口权限表-网页账户-修改
(3)设置回调域名
(4)微信公众号正式号设置
三、代码怎么写
代码如下(示例):
四、出现问题怎么办
在开发出现问题时,可以通过接口调用的返回码,以及报警排查指引(在公众平台官网 - 开发者中心处可以设置接口报警),来发现和解决问题
最后
原创不易,还希望各位大佬支持一下 !
点赞,你的认可是我创作的动力!
️收藏,你的青睐是我努力的方向!
️评论,你的意见是我进步的财富!
边栏推荐
- Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
- Practice independent and controllable 3.0 and truly create the open source business of the Chinese people
- 10 minutes to help you get ZABBIX monitoring platform alarm pushed to nail group
- Keras crash Guide
- 搜索 正排索引 和 倒排索引 区别
- Yarn common commands
- How to use FRP intranet penetration +teamviewer to quickly connect to the intranet host at home when mobile office
- Jarvis OJ Webshell分析
- 【学术相关】多位博士毕业去了三四流高校,目前惨不忍睹……
- Clear restore the scene 31 years ago, volcanic engine ultra clear repair beyond classic concert
猜你喜欢

Jarvis OJ Flag

Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found

If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats

机器学习编译第2讲:张量程序抽象

Jarvis OJ webshell analysis

数据访问 - EntityFramework集成

Jarvis OJ shell流量分析

Benji Bananas 会员通行证持有人第二季奖励活动更新一览

Enter a command with the keyboard

Domestic API management artifact used by the company
随机推荐
中间表是如何被消灭的?
tf. sequence_ Mask function explanation case
Yarn common commands
Twig数组合并的写法
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Enter a command with the keyboard
Single merchant v4.4 has the same original intention and strength!
[echart] resize lodash 实现窗口缩放时图表自适应
Sentinel flow guard
[61dctf]fm
文件操作--I/O
搜索 正排索引 和 倒排索引 区别
Cheer yourself up
如何将mysql卸载干净
Seaborn绘制11个柱状图
深潜Kotlin协程(二十一):Flow 生命周期函数
Combined use of vant popup+ other components and pit avoidance Guide
Jarvis OJ shell traffic analysis
Cartoon: what is distributed transaction?
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html




