微信公众号获取未关注的用户基本信息信息(已关注或者未关注都可以)

来源:互联网 发布:java游戏内购破解版 编辑:程序博客网 时间:2024/05/13 11:23


1、根据公众号的appid获取code    $APPID=APPID;//公众号在微信的appid    $REDIRECT_URI='http://www.ific.cc/check.php';//回调页面        // $scope='snsapi_base';    $scope='snsapi_userinfo';//需要授权    $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$APPID."&redirect_uri=".urlencode($REDIRECT_URI)."&response_type=code&scope=".$scope."&state=STATE#wechat_redirect";    header("Location:".$url);特: -->此处必须修改公众号的获取用户信息的回调url2.check.php页面$code = $_GET['code'];$state = $_GET['state'];/*根据code获取用户openid*/$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx72e1ef917e46fc68&secret=eb209bfaa8effa31f4508cea9788f5d0&code=".$code."&grant_type=authorization_code";$abs = file_get_contents($url);$obj=json_decode($abs);$access_token = $obj->access_token;$openid = $obj->openid;/*根据code获取用户openid end*//*根据用户openid获取用户基本信息*/$abs_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";$abs_url_data = file_get_contents($abs_url);$obj_data=json_decode($abs_url_data);echo $OpenId = $obj_data->openid;echo $NickName = $obj_data->nickname;/*根据用户openid获取用户基本信息*/ 

批注://这种方法适用于服务号或者其余的申请到接口的,但是不适用于测试号。。。
1 0
原创粉丝点击