1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <?php
header('Access-Control-Allow-Origin:*'); header('Content-type: application/json');
header('content-type: application/json;charset=utf8');
$qq = $_REQUEST['qq'] ?? null; if (!$qq || !is_numeric($qq)) { sendResponse(201, '参数错误'); exit; }
$uin = ''; $skey = ''; $p_skey = ''; $cookie = "uin=$uin;skey=$skey;p_skey=$p_skey;";
$url = 'https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?g_tk=' . getbkn($skey) . '&uins=' . $qq; $response = getCurl($url, ["Cookie: $cookie"]);
$data = json_decode(substr(mb_convert_encoding($response, "UTF-8", "GBK"), 17, -1), true);
if ($data) { $server = rand(1, 4); $txUrl = "https://q$server.qlogo.cn/headimg_dl?dst_uin=$qq&spec=640"; $json = [ 'code' => 200, "msg" => "success", "data" => [ 'qq' => $qq, 'name' => $data[$qq][6], "img" => $txUrl, 'mail' => $qq.'@qq.com', ] ]; sendResponse(200, 'success', $json['data']); } else { sendResponse(201, '接口错误,请联系管理员'); }
function getbkn($skey) { $hash = 5381; $len = strlen($skey); for ($i = 0; $i < $len; $i++) { $hash += ($hash << 5) + ord($skey[$i]); } return $hash & 0x7FFFFFFF; }
function getCurl($url, $header = []) { $con = curl_init($url); curl_setopt_array($con, [ CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_AUTOREFERER => true, CURLOPT_HTTPHEADER => $header, CURLOPT_TIMEOUT => 5000 ]); $result = curl_exec($con); curl_close($con); return $result; }
function sendResponse($code, $msg, $data = null) { $response = [ 'code' => $code, 'msg' => $msg, 'data' => $data ]; echo json_encode($response, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE); exit; }
|