PHP 獲取QQ 使用者暱稱 、頭像
阿新 • • 發佈:2018-11-03
public function getqqnickname(){ if (request()->isPost()){ $qq = input('param.qq'); if(!$qq || !preg_match('|^[1-9]\d{4,10}$|i',$qq)){ return json(array('code'=>0,'msg'=>'QQ格式錯誤')); } $nickname = file_get_contents('http://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins='.$qq); $image = 'http://q.qlogo.cn/headimg_dl?dst_uin='.$qq.'&spec=100'; if(strstr($nickname,'portraitCallBack')){ return json(array('code'=>1,'msg'=>'成功','image'=>$image,'data'=>isset(json_decode(trim(mb_convert_encoding($nickname, "UTF-8", "GBK"),'portraitCallBack()'),true)[$qq][6])?json_decode(trim(mb_convert_encoding($nickname, "UTF-8", "GBK"),'portraitCallBack()'),true)[$qq][6]:'遊客')); }else if(strstr($nickname,'_Callback')){ return json(array('code'=>0,'msg'=>'獲取暱稱失敗')); } return json(array('code'=>0,'msg'=>'獲取暱稱失敗')); } }