微信获取用户详细信息

 //详细授权1
    public function grant(){
        //1户同意授权  获取code
        $appid='8888888888888888888888888';
        $redirect_uri=urlencode("http://wwwwwwwwwwwww/fruits/public/index.php/home/wei/role");
        $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
        header('location:'.$url);
    }
    ///详细授权2
    public function role(){
        //2 通过code 换取网页授权access_token
        $appid="8888888888888888888888";
        $secret="788888888888888888888888882";
        $code=$_GET['code'];
        $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code";
        //3 获取用户openId
        $res=$this->httpCurl($url,'get');
        $openid=$res['openid'];
        $access_token=$res['access_token'];
        //拉去用户的详细信息
        $urls="https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
        $reslist=$this->httpCurl($urls);
        var_dump($reslist);
    }


你可能感兴趣的:(微信获取用户详细信息)