之前的获取QQ昵称的接口都会出现乱码的问题,最近看到了一个使用 form-data 的提交方式,我也不知道怎么来的,但是确实有用,就改成了PHP的了
function get_qq_nick($qqCode) {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins='.$qqCode,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS => '------WebKitFormBoundaryYTwvlk5brGmyD3Mn',
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);
return $name[$qqCode][6];
}