QQ号码转QQ昵称代码

  • 发表于
  • 前端

PHP源代码:

<?php
if(isset($_POST['u'])){
header('Content-Type: text/html; charset=utf-8');
$ret = '';
if(preg_match('/\"nickname\":\"([^\"]+)\"/', file_get_contents('http://r.qzone.qq.com/cgi-bin/user/cgi_personal_card?uin='.$_POST['u']), $QQInfo)){
$ret = $QQInfo[1];
}
echo '<script>parent.document.getElementById("nickname").innerHTML = "QQ号:[',$_POST['u'],']对应的QQ昵称为:',$ret,'";</script>';
}else{?>
<!DOCTYPE html>
<html>
<head>
<title>QQ号码转QQ昵称</title>
<meta name="generator" content="editplus" />
<meta name="author" content="土豆" />
<meta name="keywords" content="小秦,QQ号码转QQ昵称" />
<meta name="description" content="QQ号码转QQ昵称" />
</head>
<body>
<h1>如果显示的昵称为空,则为未找到.</h1>
<div id="nickname"></div>
<iframe name="hiddenIframe" style="display:none;"></iframe>
<form action="" method="POST" target="hiddenIframe">
<input type="text" name="u" />
<input type="submit" value="查询该QQ号对应的QQ昵称" />
</form>
</body>
</html>
<?php
}
?>

就是请求这个URL地址:

http://r.qzone.qq.com/cgi-bin/user/cgi_personal_card?uin=280235119

将里面的 "280235119" 改为你想要取得昵称的QQ号码,就可以得到类似下面的结果:

_Callback(
{"uin":280235119,
"qzone":2,
"nickname":"土豆",
"gender":1,
"astro":10,
"from":"平顶山",
"offsetBirth":267,
"isExpo":1,
"avatarUrl":"http://qlogo4.store.qq.com/qzonelogo/280235119/1/0"});

里面的 nickname 就是该QQ号的昵称