admin管理员组

文章数量:1640576

前期准备

接入微信授权

分静默授权和非静默授权两种

静默授权: scope=snsapi_base,没有弹窗,只能获取用户的openId。

非静默授权: scope=snsapi_userinfo,有弹框弹出需要用户手动点击确认授权。可以获取openId,用户的头像、昵称等

授权步骤如下:

判断URL有没有code

有是已经授权,无是未授权

未授权,跳转微信授权链接 这里采用静默授权

https://open.weixin.qq/connect/oauth2/authorize?appid=${DefaultConfig.appId}&redirect_uri=${url}&response_type=code&scope=${DefaultConfig.loginWay}&state=#wechat_redirect

注意: redirect_uri是授权成功,跳转的地址,微信会帮我们跳转到该链接,并且通过?的形式拼接code

本地开发测试,在测试公众号的网页授权回调配置 当前电脑的IP就行了

function login() {

let url = encodeURIComponent(DefaultConfig.redirectUriWx); // 注意一定要encodeURIComponent

window.location.href = `https://open.weixin.qq/connect/oauth2/authorize?appid=${DefaultConfig.appI

本文标签: 页面首页html