微信(网页、内置浏览器)接入微信登录(授权登录 + 静默登录)(测试版)

实现微信登录步骤:

官方文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
一、 获取code
(1)scope为snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid)

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx520c15f417810387&redirect_uri=https%3A%2F%2Fchong.qq.com%2Fphp%2Findex.php%3Fd%3D%26c%3DwxAdapter%26m%3DmobileDeal%26showwxpaytitle%3D1%26vb2ctag%3D4_2030_5_1194_60&response_type=code&scope=snsapi_base&state=123#wechat_redirect

(2)snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且, 即使在未关注的情况下,只要用户授权,也能获取其信息 )

scope为snsapi_userinfo
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf0e81c3bee622d60&redirect_uri=http%3A%2F%2Fnba.bluewebgame.com%2Foauth_response.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
  • 参数列表
    在这里插入图片描述
    **tips参数须知:
  • 使用的参数需要去公众后台配置
    -在这里插入图片描述
    - 配置参数测试公众平台信息
  • js接口安全域名(用于微信扫码等功能)

在这里插入图片描述

  • 扫码关注测试公众号
    在这里插入图片描述
  • 修改网页授权地址(此处的地址为redirect_uri)
    在这里插入图片描述
    在这里插入图片描述
    以上信息配置正确后。将参数传给后端(redirect_uri 需要 urlEncode 对链接进行处理后端更好处理)拼接起来。用返回的地址window.locahost.href=‘xxxx’。调整新的地址并携带code

二、利用code获取access_token 和 openId .
三、用access_token 和openid获取用户信息

总结:微信授权和静默登录,主要是配置信息获取到code。

下一篇讲解正式服微信授权登录

发布了70 篇原创文章 · 获赞 67 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_37896578/article/details/101615860