PHP 获取 QQ 昵称代码官方接口

代码

<?php
function get_qq_nick($qqCode) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=' . $qqCode);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($curl, CURLOPT_POSTFIELDS, '------WebKitFormBoundaryYTwvlk5brGmyD3Mn');
    curl_setopt($curl, CURLOPT_HTTPHEADER, [
        'Content-Type: multipart/form-data; boundary=---011000010111000001101001',
    ]);
    $response = curl_exec($curl);
    $encode = mb_detect_encoding($response, array("ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5'));
    $response = mb_convert_encoding($response, 'UTF-8', $encode);
    $name = json_decode(substr($response, 17, -1), true);
    curl_close($curl);
    return $name[$qqCode][6];
}
echo get_qq_nick('1562730031');
?>