您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

p你看到QQ空间那个朋友好久没有联系了么

2024/3/31 11:22:04发布20次查看
下午看到空间开始流行一个,朋友好久联系了吧!联系我吧!谁在自己的空间看到,图片上就显示的谁的qq和昵称!这个是怎么做的呢?我这里就写了一个小demo。获取qq昵称是需要访问一个网页的,我这里有原来的类!就直接用了,获取方式有很多!不过说直接上代码! get('http://redstones.sinaapp.com/apis/qqinfo-service.php?qq='.$r);preg_match('#nickname:(.*?)#',$webtext,$rr);$rrr=$rr[1];header(content-type:image/png);$im=imagecreatefromjpeg(1.jpg);$black = imagecolorallocate($im, 56,73,136);$fnt=shenfenzheng.ttf;imagettftext($im,26,0,110,100,$black,shenfenzheng.ttf,$rrr);imagettftext($im,26,0,100,180,$black,shenfenzheng.ttf,$r);imagejpeg($im);imagedestroy($im);?>
复制代码
80, //客户端 useragent,如:mozilla/4.0,为空则使用用户的浏览器 'useragent'=>'', //连接超时时间 'timeout'=>30, //是否使用 cookie 建议打开,因为一般网站都会用到 'usecookie'=>true, //是否支持ssl 'ssl'=>false, //客户端是否支持 gzip压缩 'gzip'=>true, //是否使用代理 'proxy'=>false, //代理类型,可选择 http 或 socks5 'proxytype'=>'http', //代理的主机地址,如果是 http 方式则要写成url形式如:http://www.proxy.com //socks5 方式则直接写主机域名为ip的形式,如:192.168.1.1 'proxyhost'=>'http://www.proxy.com', //代理主机的端口 'proxyport'=>1234, //代理是否要身份认证(http方式时) 'proxyauth'=>false, //认证的方式.可选择 basic 或 ntlm 方式 'proxyauthtype'=>'basic', //认证的用户名和密码 'proxyauthuser'=>'user', 'proxyauthpwd'=>'password', ); /** * 构造函数 * * @param array $setopt :请参考 private $setopt 来设置 */ public function __construct($setopt=array()) { //合并用户的设置和系统的默认设置 $this->setopt = array_merge($this->setopt,$setopt); //如果没有安装curl则终止程序 function_exists('curl_init') || die('curl library not loaded'); //初始化 $this->ch = curl_init(); //设置curl连接的端口 curl_setopt($this->ch, curlopt_port, $this->setopt['port']); //使用代理 if($this->setopt['proxy']){ $proxytype = $this->setopt['proxytype']=='http' ? curlproxy_http : curlproxy_socks5; curl_setopt($this->ch, curlopt_proxytype, $proxytype); curl_setopt($this->ch, curlopt_proxy, $this->setopt['proxyhost']); curl_setopt($this->ch, curlopt_proxyport, $this->setopt['proxyport']); //代理要认证 if($this->setopt['proxyauth']){ $proxyauthtype = $this->setopt['proxyauthtype']=='basic' ? curlauth_basic : curlauth_ntlm; curl_setopt($this->ch, curlopt_proxyauth, $proxyauthtype); $user = [{$this->setopt['proxyauthuser']}]:[{$this->setopt['proxyauthpwd']}]; curl_setopt($this->ch, curlopt_proxyuserpwd, $user); } } if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'off')) //启用时会将服务器服务器返回的“location:”放在header中递归的返回给服务器 curl_setopt($this->ch, curlopt_followlocation, true); //打开的支持ssl if($this->setopt['ssl']){ //不对认证证书来源的检查 curl_setopt($this->ch, curlopt_ssl_verifypeer, false); //从证书中检查ssl加密算法是否存在 curl_setopt($this->ch, curlopt_ssl_verifyhost, true); } //设置http头,支持lighttpd服务器的访问 $header[]= 'expect:'; curl_setopt($this->ch, curlopt_httpheader, $header); //设置 http useragent $useragent = $this->setopt['useragent'] ? $this->setopt['useragent'] : $_server['http_user_agent']; curl_setopt($this->ch, curlopt_useragent, $useragent); //设置连接等待时间,0不等待 curl_setopt($this->ch, curlopt_connecttimeout, $this->setopt['timeout']); //设置curl允许执行的最长秒数 curl_setopt($this->ch, curlopt_timeout, $this->setopt['timeout']); //设置客户端是否支持 gzip压缩 if($this->setopt['gzip']){ curl_setopt($this->ch, curlopt_encoding, 'gzip'); } //是否使用到cookie if($this->setopt['usecookie']){ //生成存放临时cookie的文件(要绝对路径) $cookfile = tempnam(sys_get_temp_dir(),'cuk'); //连接关闭以后,存放cookie信息 curl_setopt($this->ch, curlopt_cookiejar, $cookfile); curl_setopt($this->ch, curlopt_cookiefile, $cookfile); } //是否将头文件的信息作为数据流输出(header信息),这里保留报文 curl_setopt($this->ch, curlopt_header, true); //获取的信息以文件流的形式返回,而不是直接输出。 curl_setopt($this->ch, curlopt_returntransfer, true) ; curl_setopt($this->ch, curlopt_binarytransfer, true) ; } /** * 以 get 方式执行请求 * * @param string $url :请求的url * @param array $params :请求的参数,格式如: array('id'=>10,'name'=>'yuanwei') * @param array $referer :引用页面,为空时自动设置,如果服务器有对这个控制的话则一定要设置的. * @return 错误返回:false 正确返回:结果内容 */ public function get($url,$params=array(), $referer='') { return $this->_request('get', $url, $params, array(), $referer); } /** * 以 post 方式执行请求 * * @param string $url :请求的url * @param array $params :请求的参数,格式如: array('id'=>10,'name'=>'yuanwei') * @param array $uploadfile :上传的文件,支持相对路径,格式如下 * 单个文件上传:array('img1'=>'./file/a.jpg') * 同字段多个文件上传:array('img'=>array('./file/a.jpg','./file/b.jpg')) * @param array $referer :引用页面,引用页面,为空时自动设置,如果服务器有对这个控制的话则一定要设置的. * @return 错误返回:false 正确返回:结果内容 */ public function post($url,$params=array(),$uploadfile=array(), $referer='') { return $this->_request('post', $url, $params, $uploadfile, $referer); } /** * 得到错误信息 * * @return string */ public function error() { return curl_error($this->ch); } /** * 得到错误代码 * * @return int */ public function errno() { return curl_errno($this->ch); } /** * 得到发送请求前和请求后所有的服务器信息和服务器header信息,其中 * [before] :请求前所设置的信息 * [after] :请求后所有的服务器信息 * [header] :服务器header报文信息 * * @return array */ public function getinfo() { return $this->info; } /** * 析构函数 * */ public function __destruct() { //关闭curl curl_close($this->ch); } /** * 私有方法:执行最终请求 * * @param string $method :http请求方式 * @param string $url :请求的url * @param array $params :请求的参数 * @param array $uploadfile :上传的文件(只有post时才生效) * @param array $referer :引用页面 * @return 错误返回:false 正确返回:结果内容 */ private function _request($method, $url, $params=array(), $uploadfile=array(), $referer='') { //如果是以get方式请求则要连接到url后面 if($method == 'get'){ $url = $this->_parseurl($url,$params); } //设置请求的url curl_setopt($this->ch, curlopt_url, $url); //如果是post if($method == 'post'){ //发送一个常规的post请求,类型为:application/x-www-form-urlencoded curl_setopt($this->ch, curlopt_post, true) ; //设置post字段值 $postdata = $this->_parsmencode($params,false); /* //如果有上传文件 if($uploadfile){ foreach($uploadfile as $key=>$file){ if(is_array($file)){ $n = 0; foreach($file as $f){ //文件必需是绝对路径 $postdata[$key.'['.$n++.']'] = '@'.realpath($f); } }else{ $postdata[$key] = '@'.realpath($file); } } } */ //pr($postdata); die; curl_setopt($this->ch, curlopt_postfields, $postdata); } //设置了引用页,否则自动设置 if($referer){ curl_setopt($this->ch, curlopt_referer, $referer); }else{ curl_setopt($this->ch, curlopt_autoreferer, true); } //得到所有设置的信息 $this->info['before'] = curl_getinfo($this->ch); //开始执行请求 $result = curl_exec($this->ch); //得到报文头 $headersize = curl_getinfo($this->ch, curlinfo_header_size); $this->info['header'] = substr($result, 0, $headersize); //去掉报文头 $result = substr($result, $headersize); //得到所有包括服务器返回的信息 $this->info['after'] = curl_getinfo($this->ch); //如果请求成功 if($this->errno() == 0){ //&& $this->info['after']['http_code'] == 200 return $result; }else{ return false; } } /** * 返回解析后的url,get方式时会用到 * * @param string $url :url * @param array $params :加在url后的参数 * @return string */ private function _parseurl($url,$params) { $fieldstr = $this->_parsmencode($params); if($fieldstr){ $url .= strstr($url,'?')===false ? '?' : '&'; $url .= $fieldstr; } return $url; } /** * 对参数进行encode编码 * * @param array $params :参数 * @param bool $isretstr : true:以字符串返回 false:以数组返回 * @return string || array */ private function _parsmencode($params,$isretstr=true) { $fieldstr = ''; $spr = ''; $result = array(); foreach($params as $key=>$value){ $value = urlencode($value); $fieldstr .= $spr.$key .'='. $value; $spr = '&'; $result[$key] = $value; } return $isretstr ? $fieldstr : $result; } }
复制代码
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product