微信掃碼一直空白頁,大家的代碼也測試過依然空白
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>';
}
2018-08-08
也可以不調用$this->http_curl(); 直接用
2017-08-11
我也是空白一片,,,樓主解決了么?
2017-07-27
親,可能是你,還沒有抓取網頁中的基本的信息,所以就獲取不到用戶的信息了
并且這個方法你寫了? $this->http_curl();沒有的話,肯定是獲取不到信息的了,這個方法可以在提升篇中-第六章-第三小節可以獲取的到方法