美文网首页
APP三方登录及绑定

APP三方登录及绑定

作者: 8813d76fee36 | 来源:发表于2017-12-06 12:32 被阅读147次

    微信登录

    官方文档链接
    https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419317851&token=&lang=zh_CN

    • 获取openid、access_token等

    AppID、AppSecret保存在后台

    App通过SDK发起授权请求,从微信获取临时票据code,将code传给后台,后台结合code、AppID、AppSecret换得openid和access_token等。

    请求方式:GET https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code

    获取access_token及openid等数据


    请求参数说明
    正确返回
    错误返回

    将获取的openid、access_token、refresh_token、unionid保存在后台数据库,其中access_token的过期时间由后台根据获取access_token时的当前系统时间加上过期时间得出过期时间戳存入数据库,如expireTime,用于判断access_token是否过期。

    将openid返回给前端。

    • 获取微信用户信息
      前端将openid传给后台,后台根据openid到微信用户表查询access_token,并判断是否过期,若过期则调用refrest_token接口刷新token,不过期则进行获取用户信息操作。
      使用openid和access_token请求如下接口获取用户信息。并记得保存unionid

    请求方式:GET
    https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID

    获取用户信息请求参数
    正确返回结果
    正确返回结果说明
    错误返回结果
    • access_token刷新
      刷新\续期说明
      1.若access_token已超时,那么进行refresh_token会获取一个新的access_token,新的超时时间;
      2.若access_token未超时,那么进行refresh_token不会改变access_token,但超时时间会刷新,相当于续期access_token。
      refresh_token拥有较长的有效期(30天)且无法续期,当refresh_token失效的后,需要用户重新授权后才可以继续获取用户头像昵称。
      后台使用openid和refresh_token请求token刷新接口。

    请求方式:GET
    https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN

    请求参数说明
    正确返回结果及说明
    错误返回结果

    后台更新该用户access_token、refresh_token、token过期时间

    相关文章

      网友评论

          本文标题:APP三方登录及绑定

          本文链接:https://www.haomeiwen.com/subject/nhmkixtx.html