当前位置:网站首页>微信扫码登陆(1)—扫码登录流程讲解、获取授权登陆二维码
微信扫码登陆(1)—扫码登录流程讲解、获取授权登陆二维码
2022-08-10 13:45:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
扫码登录流程讲解、获取授权登陆二维码
具体流程可以看微信官网的扫码登录文档
其实官方文档已经讲的非常清楚而且讲的也很明白。
一、扫码登录流程讲解
1、首先准备工作
网站应用微信登录是基于OAuth2.0协议标准构建的微信OAuth2.0授权登录系统。
在进行微信OAuth2.在进行微信OAuth2.0授权登录接入之前,在微信开放平台注册开发者帐号,并拥有一个已审核通过的网站应用,并获得相应的AppID和AppSecret
申请微信登录且通过审核后,可开始接入流程。就是你的网站要想实现微信扫码登陆功能首先要在微信备案通过,它才会给你个AppID和AppSecret。
2、时序流程图
时序图总结流程:
1、用户点击网站微信登陆图标。
2、网站带上AppID和AppSecret和回调域名参数请求微信OAuth2.0授权登陆。
3、第二步通过后,微信返回二维码供用户扫码。
4、用户扫码确定授权。
5、微信带上code参数回调java后端相关接口。
6、java后端获取到code后,在带上带上AppID和AppSecret和code再去调微信接口。
7、获取access_token后就可以解析用户的一些基本信息,比如:微信用户头像、用户名、性别、城市等一些基本参数。
具体接口参数说明看官方文档。
二、获取授权登陆二维码
1、微信登陆接口
@Controller
@RequestMapping("/api/v1/wechat")
public class WechatController {
/**
* 微信开放平台二维码连接
*/
private final static String OPEN_QRCODE_URL= "https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_login&state=%s#wechat_redirect";
/**
* 开放平台回调url
* 注意:test16web.tunnel.qydev.com 域名地址要和在微信端 回调域名配置 地址一直,否则会报回调地址参数错误
*/
private final static String OPEN_REDIRECT_URL= "http://test16web.tunnel.qydev.com/pub/api/v1/wechat/user/callback1";
/**
* 微信审核通过后的appid
*/
private final static String OPEN_APPID= "wx0255752c69a2d5b";
/**
* 拼装微信扫一扫登录url
*/
@GetMapping("login_url")
@ResponseBody
public JsonData loginUrl(@RequestParam(value = "access_page",required = true)String accessPage) throws UnsupportedEncodingException {
//官方文档说明需要进行编码
String callbackUrl = URLEncoder.encode(OPEN_REDIRECT_URL,"GBK"); //进行编码
//格式化,返回拼接后的url,去调微信的二维码
String qrcodeUrl = String.format(OPEN_QRCODE_URL,OPEN_APPID,callbackUrl,accessPage);
return JsonData.buildSuccess(qrcodeUrl);
}
}2、通过调用接口前端获得详细URL地址
3、访问data数据中URL地址
成功!
下一步需要做的是用户扫完登陆二维码后,进行回调:http://test16web.tunnel.qydev.com/pub/api/v1/wechat/user/callback1 接口
我只是偶尔安静下来,对过去的种种思忖一番。那些曾经的旧时光里即便有过天真愚钝,也不值得谴责。毕竟,往后的日子,还很长。不断鼓励自己,
天一亮,又是崭新的起点,又是未知的征程(上校12)
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129987.html原文链接:https://javaforall.cn
边栏推荐
- Open Office XML 格式里如何描述多段具有不同字体设置的段落
- 2022年中国软饮料市场洞察
- 1W word detailed thread local storage ThreadLocal
- ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
- WebView的优化与常见问题解决方案
- Circle 创始人回应美财政部禁止 Tornado :隐私与安全之间关系紧张
- 2022-08-09: What does the following go code output?A: No, it will panic; B: Yes, it can run correctly; C: Not sure, see the voting result.package main import (“fmt“ “syn
- 重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!
- Fragment's show and hide
- 一种能让大型数据聚类快2000倍的方法,真不戳
猜你喜欢

Open Office XML 格式里如何描述多段具有不同字体设置的段落
![[target detection] small script: extract training set images and labels and update the index](/img/9d/0f88b484cee1b85df6bc1153d9b6b4.png)
[target detection] small script: extract training set images and labels and update the index

【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解

商汤自研机械臂,首款产品是AI下棋机器人:还请郭晶晶作代言

发送post请求前台无法获取数据

Short read or OOM loading DB. Unrecoverable error, aborting now
![[Study Notes] Persistence of Redis](/img/e4/d3c09754ca5ac4fdad2653ccca6d82.png)
[Study Notes] Persistence of Redis

实现一个深克隆

矩阵键盘&基于51(UcosII)计算器小项目

【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写
随机推荐
[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files
Drive IT Modernization with Low Code
Network Saboteur
作业8.9 构建TCP协议的服务器
[target detection] small script: extract training set images and labels and update the index
Send a post request at the front desk can't get the data
vivado闪退或者message无显示
【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding
C#实现访问OPC UA服务器
【JS高级】ES5标准规范之创建子对象以及替换this_10
写不完的数学试卷-----试卷生成器(Qt含源码)
池化技术有多牛?来,告诉你阿里的Druid为啥如此牛逼!
网络安全——XSS之被我们忽视的Cookie
简单的写一个防抖跟节流
X5WebView使用
什么?你还不会JVM调优?
注意力模型---Attention Model
bgp dual plane experiment routing strategy to control traffic
awk的简单使用
Cloud Migration Practice of Redis