lincanbin
lincanbin
4598 10 0

QQ登陆get_openid失败是怎么回事?

返回403错误

0

See Also

Nearby


Discussion (10)

admin
admin 2013-08-22 13:27

这一页引发403的原因是下面一句

if(!$openid) exit('error: 403 Access Denied, no openid');

$openid = $_SESSION["openid"];

0
admin
admin 2013-08-22 13:30

是我搞错,1楼权当没发,

所说的应该是qq 返回的一个403 代码,这个应该是应用还没提交或通过QQ审核。

0
lincanbin
lincanbin 2013-08-22 14:13

@admin

我注释掉

//error_reporting(0);
session_start();

$name = $_SESSION["nick"];
$openid = $_SESSION["openid"];

//if(!$openid) exit('error: 403 Access Denied');

然后成功登陆了

0
lincanbin
lincanbin 2013-08-22 14:15

@admin 哦,不对,是因为openid为空成功写入了QQweibo表
所以任意账号都能登陆了
我这边怎么无法获取到openid

0
admin
admin 2013-08-22 14:22

@lincanbin 在站内搜索 openid 403 看到这个帖子了 https://www.youbbs.org/t/912

0
lincanbin
lincanbin 2013-08-22 14:50

一步步排查过去
在获取access_token那一步就失败了

0
lincanbin
lincanbin 2013-08-22 15:06

@admin

function get_url_contents($url)
{
    if (ini_get("allow_url_fopen") == "1")
        return file_get_contents($url);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result =  curl_exec($ch);
    curl_close($ch);

    return $result;
}

这里有检测file_get_contents函数支持的
应该不是file_get_contents函数的问题吧?

0
lincanbin
lincanbin 2013-08-22 15:07

@admin 新浪微博登陆是成功的

0
lincanbin
lincanbin 2013-08-22 15:14

@admin 好吧,写了几个测试,发现确实是https的问题
我的是买的虚拟主机,无解了

0
lincanbin
lincanbin 2013-08-22 15:23

已解决

function get_url_contents($url)
{
    //if (ini_get("allow_url_fopen") == "1")
    //return file_get_contents($url);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	//debug
	curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	//debug end
    curl_setopt($ch, CURLOPT_URL, $url);
    $result =  curl_exec($ch);
    curl_close($ch);

    return $result;
}

注释掉了对 file_get_contents函数支持的判断
改用curl

0
Login Topics