根据QQ号获取昵称

   public  function getQQNickName(){
            $qq = input('param.qq/d');
            $returnArr=['code'=>0,'msg'=>'获取失败'];

            if(!$qq || !preg_match('|^[1-9]\d{4,10}$|i',$qq)){
                $returnArr['msg']='QQ格式错误';
                return json($returnArr);
            }
            $cache_key='qq_nickname' . $qq;
            $cache_nickname=cache($cache_key);
            if($cache_nickname != false){
                return $cache_nickname;
            }
            $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')){
                $name=trim(mb_convert_encoding($nickname, "UTF-8", "GBK"),'portraitCallBack()');
                $name=json_decode($name,true);
                if(isset($name[$qq][6]) && !empty($name[$qq][6])){
                    $name=$name[$qq][6];
                }else{
                    $name='游客';
                }

                $returnArr= array('code'=>1, 'msg'=>'成功', 'image'=>$image, 'name'=> $name,'qq'=>$qq);
                cache($cache_key , $returnArr , 3600);

            }else if(strstr($nickname,'_Callback')){
                $returnArr['msg']='获取昵称失败';
            }
            return json($returnArr);
        }

评论

(= ̄ω ̄=)··· 暂无内容!

回复

您还未登录,请先登录或者注册