1.参考开发文档:
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0
2.先调起微信授权页面,获取code。(如果用户同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE)。用如下连接生成二维码,微信扫码可以调起授权页面。
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxbf1f83d35ba69d&redirect_uri=http://www.dd.com.cn&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect
3.用户同意后回调redirect_uri配置的接口,获取code:
https://www.dd.com.cn/?code=001Ut4Ha1yuI3F05mEJa1DlLq64Ut4HG&state=STATE
4.通过access_token接口,传入code,获取到用户的openId,unionid和access_token信息:
https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxbf1f83d3a69d&secret=c28917fc609f3a6f6780b60702ff0d89&code=001Ut4Ha1yuI3F05mEJa1DlLq64Ut4HG&grant_type=authorization_code
{"access_token": "67_xtTNGAMFQw6r5HVWajUmw5P1E7L9rTvF6YeFSKZwxMr3RdSww00WoM6y8dGv6rQdVEZAtV8nLtGID0MI4-hM74h0tWD941nYdbSULG46QgI","expires_in": 7200,"refresh_token": "67_y1jqaGqpojn2IzVzvGBdGIuH4t_Iy1PLSE_ccR-2_dkz8hOCRpiEMrCfGaY4UP0EDqvQlLJf2wwusjadbetZhUcskk_MlCzhRd-suUckqms","openid": "oFVCr549_IkCU_u46_v0","scope": "snsapi_userinfo","unionid": "oSBoT6StcN2EHswnOunQ0XVx0"
}
5.通过这个接口,传入openId,access_token参数,获取用户的基本信息:
https://api.weixin.qq.com/sns/userinfo?access_token=67_xtTNGAMFQw6r5HVWajUmw5P1E7L9rTvF6YeFSKZwxMr3RdSww00WoM6y8dGv6rQdVEZAtV8nLtGID0MI4-hM74h0tWD941nYdbSULG46QgI&openid=oFVCr549_IvbcT3iZskCU_u46_v0&lang=zh_CN
{"openid": "oFVCr549_IT3iZskCU_u46_v0","nickname": "ooo","sex": 0,"language": "","city": "","province": "","country": "","headimgurl": "https:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/vdR2Ria3VobffzGBi8NZUIEdaiat4fwhzNzURwFQu7K2o1RI33yibibJkO9GjWQJY2eibCw4oFMeWM1yvUYCEiaQ\/132","privilege": [],"unionid": "oSBoT6WGswnOunQ0XVx0"
}