美文网首页
微信oauth授权过程

微信oauth授权过程

作者: 泠泉 | 来源:发表于2019-05-24 11:04 被阅读0次

    概述


    1. 请求myPage
    2. myPage附带appid,转向到weChat。(通过appid获取code
    3. weChat询问用户是否同意授权
    4. 用户同意,weChat将附带code并跳转回myPage
    5. myPage附带code到myServer请求用户信息
    6. myServer附带 code,secret到 weChatServer获取token (通过code,secret获取token
    7. myServer 附带token到weChatServer获取用户信息 (通过token获取用户信息

    example


    1. 请求授权码,通过appid

    https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx42318faaaf0e15a7&redirect_uri=https://wxbackend.asvgo.com/buy.html&response_type=code&scope=snsapi_userinfo&state=myState#wechat_redirect

    1. 询问用户是否同意授权

    https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx42318faaaf0e15a7
    &redirect_uri=https://wxbackend.asvgo.com/buy.html
    &response_type=code&scope=snsapi_userinfo
    &state=myState
    &uin=Mjg4NTk4NzA4MA%3D%3D
    &key=d5bdbff1071c690447b3b0f64a4180202cb0c59bebee966dd636b21e9eb3ccf17ea2d370dca6037aafbed7010070e485
    &pass_ticket=etDdm90QQk5PEUbgWfn0nTC+pllfF2g61l8TZTIo+3VJbGYvXjTQ6UxbGACt32MBzcgt2sii/DSju5H0AFZURg==

    3 .转回myapp的页面(附带授权码)

    https://wxbackend.asvgo.com/buy.html?ref=NO_REFEREE_ID&td_channelid=myState&code=081xHgpG0epjee2B7zoG06EgpG0xHgpU&state=myState

    1. 到myServer获取用户信息 #后台遵循oauth规范: 1.通过code获取token;2.通过token获取用户信息

    https://open.api.asvgo.com/wechat-mp-pet-api/mp/pet/web/auth/wxuser-info/071qOk2k0REKIp1nsZ3k0Ooj2k0qOk2w
    --->
    {"subscribe":null,
    "openId":"oxY6BtyMH6QC2eXuBgajdTy22GUo",
    "nickname":"afasd",
    "sexDesc":"男",
    "sex":1,
    "language":"zh_CN",
    "city":"六盘水",
    "province":"贵州",
    "country":"中国",
    "headImgUrl":"http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLneMESMlYsVYv7O5sdpup4l3Es5HpElM2UzD7zTbbqGsoY7K7lSzu2FuQos4NQJgjHu90rFFriaCA/132",
    "subscribeTime":null,
    "unionId":"odJ29wHoxaaa5xAZego7fZsZ2Sdk",
    "remark":null,
    "groupId":null,
    "tagIds":null,
    "privileges":[]
    }

    相关文章

      网友评论

          本文标题:微信oauth授权过程

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