QQInfo.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Components;
  3. class QQInfo {
  4. /**
  5. * 通过QQ号查询头像与昵称信息
  6. *
  7. * @param string $qq QQ号
  8. *
  9. * @return string
  10. */
  11. public static function getName($qq) {
  12. //向接口发起请求获取json数据
  13. $url = 'https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?get_nick=1&uins='.$qq;
  14. $ret = mb_convert_encoding(Curl::send($url), "UTF-8", "GBK");
  15. // 接口是否异常
  16. //echo $ret;
  17. if(strpos($ret, $qq) !== false){
  18. //对获取的json数据进行截取并解析成数组
  19. $ret = json_decode(substr($ret, 17, -1), true);
  20. return stripslashes($ret[$qq][6]);
  21. }
  22. echo $qq.PHP_EOL;
  23. return false;
  24. }
  25. public static function getName2($qq) {
  26. //向接口发起请求获取json数据
  27. $url = 'https://api.toubiec.cn/qq?qq='.$qq.'&size=100';
  28. $ret = json_decode(Curl::send($url), true);
  29. // 接口是否异常
  30. if($ret){
  31. if($ret['code'] == 200){
  32. return $ret['name'];
  33. }
  34. }
  35. echo $qq.PHP_EOL;
  36. return false;
  37. }
  38. public static function getName3($qq) {
  39. //向接口发起请求获取json数据
  40. $url = 'https://api.unipay.qq.com/v1/r/1450000186/wechat_query?cmd=1&pf=mds_storeopen_qb-__mds_qqclub_tab_-html5&pfkey=pfkey&from_h5=1&from_https=1&openid=openid&openkey=openkey&session_id=hy_gameid&session_type=st_dummy&qq_appid=&offerId=1450000186&sandbox=&provide_uin='.$qq;
  41. $ret = json_decode(Curl::send($url), true);
  42. // 接口是否异常
  43. if($ret){
  44. if($ret['ret'] == 0){
  45. return urldecode($ret['nick']);
  46. }
  47. }
  48. echo $qq.PHP_EOL;
  49. return false;
  50. }
  51. }