问答详情
源自:2-1 高级授权代码实现

微信扫码一直空白页,大家的代码也测试过依然空白

function getUserDetail(){
//        1.获取到code
$appid = "wxbc312a582bccb32e";
$redirect_uri = urlencode("http://www.yxgonce.xin/index.php/index/index/getUserInfo"); //将会重定向的uri(是自己在公众号绑定js的域名)

 $url =  "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri".$redirect_uri."&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
header('location:'.$url);
}

function getUserInfo(){
//        2.获取到网页授权的access_token
$appid = "wxbc312a582bccb32e";
$appsecret = "9ffbd473b9c54dda8697791dba6dff14";
header('content-type:text/html;charset=utf-8');
//2.获取网页授权access_token
$code = $_GET['code'];
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid
. '&secret=' . $appsecret
. '&code=' . $code . '&grant_type=authorization_code';
$res = $this->http_curl($url, 'get');
$openid = $res['openid'];
$access_token = $res['access_token'];
//3.拉取用户详细信息
$url = 'https://api.weixin.qq.com/sns/userinfo?access_token='
. $access_token . '&openid=' . $openid . '&lang=zh_CN';
$res = $this->http_curl($url);
echo '<hr>getUserInfo<br>';
var_dump($res);
echo '<hr>';
}


提问者:_秦王_ 2017-07-27 14:02

个回答

  • Donse胜
    2018-08-08 16:37:25

    也可以不调用$this->http_curl(); 直接用

    file_get_contents($url);也可以


  • 精慕门4127614
    2017-08-11 15:12:36

    我也是空白一片,,,楼主解决了么?

  • _蛰伏
    2017-07-27 17:55:58

    亲,可能是你,还没有抓取网页中的基本的信息,所以就获取不到用户的信息了

    并且这个方法你写了? $this->http_curl();没有的话,肯定是获取不到信息的了,这个方法可以在提升篇中-第六章-第三小节可以获取的到方法