当前位置:网站首页>Wechat mobile terminal development - account login authorization
Wechat mobile terminal development - account login authorization
2022-06-23 01:31:00 【hhzzcc_】
Login authorization to obtain openid
The process :
adopt appid And some other parameters splice the login authorization link of wechat official account , The callback address filled in will return a code Parameters come back , adopt code Send a request to the background to get openid, this code Can only be used once , Get once openid Later code To void , Acquired openid amount to token, Cache required (storage)
data () {
return {
// Fill in your appid
appid: '....',
}
},
methods: {
// obtain code
getWxCode () {
// Judge the present url Is there a code return
let noCode = window.location.href.indexOf('code=') === -1;
// If not code Parameter description login authorization is required when this page is just opened
if(noCode){
// code token url
let redirect_uri = location.origin + location.pathname;
// Jump to wechat login authorization , The function of each parameter can be checked on wechat public platform
window.location.href=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`;
}
// If belt code Parameter description login authorization successfully fetched code Pass it to the backstage openid
else {
let code = location.href.split('code=')[1].split('&')[0];
this.getOpenid(code);
}
},
getOpenid (code) {
// take code Send it to the background to get openid
....
}
}
Process assumptions :
The current login authorization page route is https://www.a.com/#/login
Suppose wechat callback code by 123456
Set the route to access / Automatically access /login Next
Callback results :
Through the above hypothesis , Then visit https://www.a.com/#/login when , The final result of callback jump will arrive at https://www.a.com Next , Its url The address is https://www.a.com?code=123456, Because the route is set to access / Automatically access /login Next , So it will return to the current authorization page , The address is https://www.a.com?code=123456/#/login, Now explain code The parameter is already in the current route url Next , Take it out and send it to the background to get openid, take openid cache , Then login authorization is completed
边栏推荐
- The road of architects starts from "storage selection"
- three. JS simulated driving tour art exhibition hall - creating super camera controller
- Population standard deviation and sample standard deviation
- Debian10 installing zabbix5.4
- [hdu] p7058 ink on paper finding the maximum edge of the minimum spanning tree
- C serializabledictionary serialization / deserialization
- Day575: divide candy
- 使用aggregation API扩展你的kubernetes API
- Installing MySQL for Linux
- Ansible learning summary (8) -- Summary of ansible control right raising related knowledge
猜你喜欢

A hundred lines of code to realize reliable delay queue based on redis

3D打印微组织

SQL programming task05 job -sql advanced processing

MySQL-Seconds_ behind_ Master accuracy error

SAP ui5 application development tutorial 102 - detailed trial version of print function implementation of SAP ui5 application

Ros2 summer school 2022 transfer-

SAP ui5 application development tutorial 102 - detailed explanation of the print function of SAP ui5 applications

SAP ui5 application development tutorial 103 - how to consume third-party libraries in SAP ui5 applications

Philosopher's walk gym divide and conquer + fractal

SFOD:无源域适配升级优化,让检测模型更容易适应新数据
随机推荐
Steps to implement a container global component
[template] KMP
New progress in the construction of meituan's Flink based real-time data warehouse platform
Sfod: passive domain adaptation and upgrade optimization, making the detection model easier to adapt to new data
a++,++a,!,~
Ansible learning summary (8) -- Summary of ansible control right raising related knowledge
You can also do NLP (classification)
Project directory navigation
Install MySQL (5.7+8.0) through docker and configure master-slave replication (gtid+ enhanced semi synchronization)
three. JS simulated driving tour art exhibition hall - creating super camera controller
Cadence spb17.4 - Chinese UI settings
SQL programming task06 assignment - Autumn recruit secret script ABC
There is no corresponding change on the page after the code runs at the Chrome browser break point
Char[], char *, conversion between strings
[cmake command notes]target_ compile_ options
Binary String
Shell view help
Ros2 summer school 2022 transfer-
Day500: keyboard line
Pat class a 1016 phone bills (time difference)