您的位置:首页 > 移动开发 > 微信开发

微信登录,获取access_token,openid 记录

2018-01-29 15:30 651 查看
$code = input('code');$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=&redirect_uri=&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect";if (!isset($code)){Header("HTTP/1.1 303 See Other");Header("Location: ".$url);exit;}$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=&secret=&code=".$code."&grant_type=authorization_code";$weixin=file_get_contents($url);//通过code换取网页授权access_token$array=json_decode($weixin,true); //对JSON格式的字符串进行编码$accessToken = $array['access_token'];$url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$array['access_token']."&openid=".$array['openid']."&lang=zh_CN";$weixin=file_get_contents($url);$array=json_decode($weixin,true); //对JSON格式的字符串进行编码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: