微信授权
1配置token验证接口
2配置服务器url
3ip白名单
4根目录文件验证
5回调地址等
配置成功可进行测试
1 请求 获取code
let appid = "公众号id";
let redirect_uri = '服务器回调地址' //前端页面
window.location.href =`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=3#wechat_redirect`
//成功后回调地址参数携带code
2 请求 获取token appid
let appid = "公众号id";
let code = '上一个地址请求回来的code'
let secret = "公众号的secret码";
window.location.href =`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appid}&secret=${secret}&code=${code}&grant_type=authorization_code`
//成功后返回 token openid
3 请求获取 信息
let access_token ='上一个地址请求回来的token'
let openid = '上一个地址请求回来的openid'
window.location.href =`https://api.weixin.qq.com/sns/userinfo?access_token=${access_token}&openid=${openid}&lang=zh_CN`
//成功后可查看收到的微信用户头像 姓名等
微信授权登陆
于 2022-05-28 14:17:32 首次发布