QQ昵称API接口分享
在评论时输入QQ号会自动调取QQ头像、QQ昵称、QQ邮箱等信息。
前阵子发现在评论时 输入qq号获取不到昵称了,提示“allback({"error":{"type":"need login","msg":"请先登录"}})”
听说需要Cookie登陆状态下才能获取QQ昵称,于是网上整理了几个免COOKIE获取QQ昵称接口。
qq.php 原方案:
<?php
header("content-Type: text/html; charset=gb2312");
$qq = @$_GET['qq'] ? $_GET['qq'] : '';
$url='https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins='.$qq;
if(empty($qq)){
header("Location: ../");
exit;
}else{
if(!empty($qq) && is_numeric($qq) && strlen($qq) > 4 && strlen($qq) < 13){
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$start1 = strpos($file_contents, ',"', 0);
$end1 = strpos($file_contents, '",0]})', $start1);
$content1 = substr($file_contents, $start1+2, $end1-$start1-2);
echo $content1;
}else{
echo 'QQ:'.$qq.'';
}
}
?>
一、@贝塔先生方案:
接口地址:https://api.liuzhuai.com/v1/GetQqNick
返回格式:json
请求方式:get/post
请求示例:https://api.liuzhuai.com/v1/GetQqNick?qq=1043897710
示例代码:
header("Content-Type:text/html;charset=UTF-8");
date_default_timezone_set("PRC");
$result = file_get_contents("https://api.liuzhuai.com/v1/GetQqNick?qq=1043897710");
$arr = json_decode($result,true);
if ($arr['code'] == 200) {
echo $arr['data']['nick'];
} else {
echo $arr['message'];
}
替换qq.php原方案 :
<?php
header("Content-Type:text/html;charset=UTF-8");
$qq = @$_GET['qq'] ? $_GET['qq'] : '';
date_default_timezone_set("PRC");
$result = file_get_contents('https://api.liuzhuai.com/v1/GetQqNick?qq='.$qq);
$arr = json_decode($result,true);
if ($arr['code'] == 200) {
echo $arr['data']['nick'];
} else {
echo $arr['msg'];
}
?>
2023-11-24 更以上贝塔先生方案已经失效
二、usuuu方案:
接口状态:正常
接口URL:GET https://api.usuuu.com/qq/547241650
返回结果:
{
"code": 200,
"msg": "success",
"data": {
"qq": "547241650",
"name": "游大漂亮",
"email": "547241650@qq.com",
"avatar": "https://q1.qlogo.cn/g?b=qq&nk=547241650&s=100"
}
}
替换qq.php方案 :
<?php
header("Content-Type:text/html;charset=UTF-8");
$qq = @$_GET['qq'] ? $_GET['qq'] : '';
date_default_timezone_set("PRC");
$result = file_get_contents('https://api.usuuu.com/qq/'.$qq);
$arr = json_decode($result,true);
if ($arr['code'] == 200) {
echo $arr['data']['name'];
} else {
echo $arr['msg'];
}
?>
三、教书先生API
接口地址:https://api.oioweb.cn/api/qq/info
返回格式:JSON
请求方式:GET
请求参数:https://api.oioweb.cn/api/qq/info?qq=1938292252
返回结果:
{
"code": 200,
"result": {
"user_id": 1938292252,
"nickname": "三笑",
"sex": "male",
"age": 27,
"area": "中国"
},
"msg": "success"
}
替换qq.php原方案 :
<?php
header("Content-Type:text/html;charset=UTF-8");
$qq = @$_GET['qq'] ? $_GET['qq'] : '';
date_default_timezone_set("PRC");
$result = file_get_contents('https://api.oioweb.cn/api/qq/info?qq='.$qq);
$arr = json_decode($result,true);
if ($arr['code'] == 200) {
echo $arr['result']['nickname'];
} else {
echo $arr['msg'];
}
?>
四、青桔-API
接口地址:https://api.qjqq.cn/api/qqinfo
返回格式:JSON
请求方式:GET
请求参数:https://api.qjqq.cn/api/qqinfo?qq=1938292252
返回结果:
{
"code": 200,
"imgurl": "https://qh.qlogo.cn/g?b=sdk&ek=AQAyyAJgctWhE6HibFLjBGvC46u4aehCPsEdvRfkAD0fCsOxlzMpicH1iagfHTQPynVG7X1KibwA&s=100&t=1676131553",
"name": "三笑",
"mail": "1938292252@qq.com"
}
替换qq.php原方案 :
<?php
header("Content-Type:text/html;charset=UTF-8");
$qq = @$_GET['qq'] ? $_GET['qq'] : '';
date_default_timezone_set("PRC");
$result = file_get_contents('https://api.qjqq.cn/api/qqinfo?qq='.$qq);
$arr = json_decode($result,true);
if ($arr['code'] == 200) {
echo $arr['name'];
} else {
echo $arr['msg'];
}
?>
五、风信子方案:
<?php
// 使用方法:qq.php?qq=qq号
header('content-type:application/json;charset=utf8');
$qq = isset($_GET['qq']) ? $_GET['qq'] : "";
if (empty($qq)) {
$json = array(
'code' => 400,
'msg' => '错误:未提供有效的参数'
);
exit(json_encode($json, 320));
}elseif(preg_match("/^[1-9]d{4,10}$/",$qq) !== 1){
$json = array(
'code' => 400,
'msg' => '错误:QQ格式不正确'
);
exit(json_encode($json, 320));
}
//cookie获取从QQ空间获取即可 包含uin skey pskey
//输入你获取cookie的QQ
$uin = '';
//输入你获取到的skey
$skey = '';
//输入你获取到的pskey
$pskey = '';
//结合cookie
$cookie = 'uin=o'.$uin.';skey='.$skey.';p_skey='.$pskey.';';
$get_info = MloocCurlGet('https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?g_tk='.getbkn($skey).'&uins='.$qq,$cookie);
//转换编码
$get_info = mb_convert_encoding($get_info, "UTF-8", "GBK");
//对获取的json数据进行截取并解析成数组
$name = json_decode(substr($get_info,17,-1),true);
if($name and $qq) {
$server = rand(1,4);
$qlogo = 'https://q'.$server.'.qlogo.cn/headimg_dl?dst_uin='.$qq.'&spec=100';
$json = array(
'code' => 200,
'qq' => $qq,
'name' => $name[$qq][6],
'mail' => $qq.'@qq.com',
'qzone' => 'http://user.qzone.qq.com/'.$qq,
'qlogo' => $qlogo,
'qzimg' => $name[$qq][0]
);
exit(json_encode($json,320));
}else{
$json = array(
'code' => 400,
'msg' => '错误:QQ信息获取异常'
);
exit(json_encode($json, 320));
}
//计算gtk/bkn
function getbkn($skey) {
$len = strlen($skey);
$hash = 5381;
for ($i = 0; $i < $len; $i++) {
$hash += ($hash << 5 & 2147483647) + ord($skey[$i]) & 2147483647;
$hash &= 2147483647;
}
return $hash & 2147483647;
}
//HTTP_Get封装方式
function MloocCurlGet($url = '', $cookie = '')
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('COOKIE:'.$cookie));
#关闭SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
#返回数据不直接显示
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
?>
上面代码只需要登陆QQ空间后获取Cookie对应填入即可使用,这里推荐使用谷歌浏览器Cookie插件(EditThisCookie)
,登陆后点击插件导出cookie即可。虽然以上代码可以获取QQ昵称了,但由于腾讯QQ的Cookie具有时效性,过一段时间便会失效需要再次重新获取并更新Cookie,所以以上代码只适合临时用用。
下面分享的便是本站(风信子博客)自用的接口,理论长期有效( •̀ ω •́ )✧。接口请勿滥用~
<?php
header("Content-Type:text/html;charset=UTF-8");
$qq = @$_GET['qq'] ? $_GET['qq'] : '';
$url='https://fxinz.cn/api/qq-query.php?qq='.$qq;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$name = curl_exec($ch);
curl_close($ch);
$qqname = json_decode($name,true);
if($qqname['code'] == 200) {
echo $qqname['data']['name'];
}else{
echo $qqname['msg'];
}
?>
<?php
header("Content-Type:text/html;charset=UTF-8");
$qq = @$_GET['qq'] ? $_GET['qq'] : '';
date_default_timezone_set("PRC");
$result = file_get_contents('https://fxinz.cn/api/qq-query.php?qq='.$qq);
$arr = json_decode($result,true);
if($arr['code'] == 200) {
echo $arr['data']['name'];
}else{
echo $arr['msg'];
}
?>
原文:https://fxinz.cn/QQnickname_api.html
发表吐槽
你肿么看?
既然没有吐槽,那就赶紧抢沙发吧!