不管用户是否已经关注,授权获取用户的基本信息

基本信息包括openid  headming 。。
思路:
  1.微信公众号后台接口权限配置吧,需要填写验证服务器的域名例如 wx.xxx.com下面的所有目录下的都能可以作为接收信息页面
  2.获取code
  3.用code拼装成授权链接即可
步骤:

1.

2.

$wxid = $_GET['wxid'];
    // 获取appid
    $data = M('userbindingwxconfig')->where('id ='.$wxid)->select();
 
    $appid = $data[0]['appId'];
 
    // 获取用户头像
    $REDIRECT_URI='http://wx.xsxsx.com/index.php?m=front&c=wxclient&a=wxauthorize&wxid='.$wxid;//回调页面    
    // $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);
   3.
    public function wxauthorize(){
    	$code = $_GET['code'];
        $state = $_GET['state'];
        $wxid = $_GET['wxid'];
        $data = M('userbindingwxconfig')->where('id ='.$wxid)->select();
        $appid = $data[0]['appId'];
        $secret = $data[0]['appSecret'];
        $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code";
        $abs = file_get_contents($url);     
        $obj=json_decode($abs);
        $access_token = $obj->access_token;
        $openid = $obj->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,true);
       	return $obj_data;
    }

最终结果就是需要的信息了

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gjanuary

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值