中國聯通:1 月 5G 套餐使用者淨增 556.8 萬戶,累計超 1.60 億戶
流程圖:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html
1.點選登陸按鈕
let link = location.href;
let uri = encodeURIComponent(link);
window.location.href =
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri
2.重定向後的頁面
http://sw.juzhonglw.cn/testwxh5/?code=001X7G1w36oG3Y2i111w3wYlPe0X7G1T&state=STATE#/packageBuild/common/projectList
截取出code的值
3.拿取code引數
let href = location.href.split('code=')[1];
if (href) {
let code = href.split('&')[0];
if (code) {
// 通過code拿取openid、unionid、access_token 等資訊
this.aotuLogin(code)
}
}
4.通過剛剛拿到的code,呼叫介面獲取 openid、unionid、access_token 等資訊(後端完成,然後提供介面給前端呼叫)
https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
5.呼叫微信登入介面,提供openid、unionid 給後端
request('/user/login',{
openid,unionid
}).then(d=>{
...
})