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

WBOY
Freigeben: 2016-07-25 08:51:10
Original
1264 Leute haben es durchsucht
下午看到空间开始流行一个,朋友好久联系了吧!联系我吧!谁在自己的空间看到,图片上就显示的谁的QQ和昵称!这个是怎么做的呢?我这里就写了一个小demo。获取QQ昵称是需要访问一个网页的,我这里有原来的类!就直接用了,获取方式有很多!不过说直接上代码!
  1. $ment = $_SERVER["HTTP_REFERER"];
  2. preg_match("#[0-9]{5,11}#",$ment,$rr);
  3. $r=$rr[0];
  4. include_once("Curl.class.php");
  5. $curl=new Curl();
  6. $webtext=$curl->get('http://redstones.sinaapp.com/apis/qqinfo-service.php?qq='.$r);
  7. preg_match('#"nickname":"(.*?)"#',$webtext,$rr);
  8. $rrr=$rr[1];
  9. header("Content-type:image/png");
  10. $im=imagecreatefromjpeg("1.jpg");
  11. $black = ImageColorAllocate($im, 56,73,136);
  12. $fnt="shenfenzheng.TTF";
  13. imagettftext($im,26,0,110,100,$black,"shenfenzheng.TTF",$rrr);
  14. imagettftext($im,26,0,100,180,$black,"shenfenzheng.TTF",$r);
  15. imagejpeg($im);
  16. imagedestroy($im);
  17. ?>
复制代码
  1. class Curl{
  2. //CURL句柄
  3. private $ch = null;
  4. //CURL执行前后所设置或服务器端返回的信息
  5. private $info = array();
  6. //CURL SETOPT 信息
  7. private $setopt = array(
  8. //访问的端口,http默认是 80
  9. 'port'=>80,
  10. //客户端 USERAGENT,如:"Mozilla/4.0",为空则使用用户的浏览器
  11. 'userAgent'=>'',
  12. //连接超时时间
  13. 'timeOut'=>30,
  14. //是否使用 COOKIE 建议打开,因为一般网站都会用到
  15. 'useCookie'=>true,
  16. //是否支持SSL
  17. 'ssl'=>false,
  18. //客户端是否支持 gzip压缩
  19. 'gzip'=>true,
  20. //是否使用代理
  21. 'proxy'=>false,
  22. //代理类型,可选择 HTTP 或 SOCKS5
  23. 'proxyType'=>'HTTP',
  24. //代理的主机地址,如果是 HTTP 方式则要写成URL形式如:"http://www.proxy.com"
  25. //SOCKS5 方式则直接写主机域名为IP的形式,如:"192.168.1.1"
  26. 'proxyHost'=>'http://www.proxy.com',
  27. //代理主机的端口
  28. 'proxyPort'=>1234,
  29. //代理是否要身份认证(HTTP方式时)
  30. 'proxyAuth'=>false,
  31. //认证的方式.可选择 BASIC 或 NTLM 方式
  32. 'proxyAuthType'=>'BASIC',
  33. //认证的用户名和密码
  34. 'proxyAuthUser'=>'user',
  35. 'proxyAuthPwd'=>'password',
  36. );
  37. /**
  38. * 构造函数
  39. *
  40. * @param array $setopt :请参考 private $setopt 来设置
  41. */
  42. public function __construct($setopt=array())
  43. {
  44. //合并用户的设置和系统的默认设置
  45. $this->setopt = array_merge($this->setopt,$setopt);
  46. //如果没有安装CURL则终止程序
  47. function_exists('curl_init') || die('CURL Library Not Loaded');
  48. //初始化
  49. $this->ch = curl_init();
  50. //设置CURL连接的端口
  51. curl_setopt($this->ch, CURLOPT_PORT, $this->setopt['port']);
  52. //使用代理
  53. if($this->setopt['proxy']){
  54. $proxyType = $this->setopt['proxyType']=='HTTP' ? CURLPROXY_HTTP : CURLPROXY_SOCKS5;
  55. curl_setopt($this->ch, CURLOPT_PROXYTYPE, $proxyType);
  56. curl_setopt($this->ch, CURLOPT_PROXY, $this->setopt['proxyHost']);
  57. curl_setopt($this->ch, CURLOPT_PROXYPORT, $this->setopt['proxyPort']);
  58. //代理要认证
  59. if($this->setopt['proxyAuth']){
  60. $proxyAuthType = $this->setopt['proxyAuthType']=='BASIC' ? CURLAUTH_BASIC : CURLAUTH_NTLM;
  61. curl_setopt($this->ch, CURLOPT_PROXYAUTH, $proxyAuthType);
  62. $user = "[{$this->setopt['proxyAuthUser']}]:[{$this->setopt['proxyAuthPwd']}]";
  63. curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $user);
  64. }
  65. }
  66. if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off'))
  67. //启用时会将服务器服务器返回的“Location:”放在header中递归的返回给服务器
  68. curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
  69. //打开的支持SSL
  70. if($this->setopt['ssl']){
  71. //不对认证证书来源的检查
  72. curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
  73. //从证书中检查SSL加密算法是否存在
  74. curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, true);
  75. }
  76. //设置http头,支持lighttpd服务器的访问
  77. $header[]= 'Expect:';
  78. curl_setopt($this->ch, CURLOPT_HTTPHEADER, $header);
  79. //设置 HTTP USERAGENT
  80. $userAgent = $this->setopt['userAgent'] ? $this->setopt['userAgent'] : $_SERVER['HTTP_USER_AGENT'];
  81. curl_setopt($this->ch, CURLOPT_USERAGENT, $userAgent);
  82. //设置连接等待时间,0不等待
  83. curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $this->setopt['timeOut']);
  84. //设置curl允许执行的最长秒数
  85. curl_setopt($this->ch, CURLOPT_TIMEOUT, $this->setopt['timeOut']);
  86. //设置客户端是否支持 gzip压缩
  87. if($this->setopt['gzip']){
  88. curl_setopt($this->ch, CURLOPT_ENCODING, 'gzip');
  89. }
  90. //是否使用到COOKIE
  91. if($this->setopt['useCookie']){
  92. //生成存放临时COOKIE的文件(要绝对路径)
  93. $cookfile = tempnam(sys_get_temp_dir(),'cuk');
  94. //连接关闭以后,存放cookie信息
  95. curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookfile);
  96. curl_setopt($this->ch, CURLOPT_COOKIEFILE, $cookfile);
  97. }
  98. //是否将头文件的信息作为数据流输出(HEADER信息),这里保留报文
  99. curl_setopt($this->ch, CURLOPT_HEADER, true);
  100. //获取的信息以文件流的形式返回,而不是直接输出。
  101. curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true) ;
  102. curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, true) ;
  103. }
  104. /**
  105. * 以 GET 方式执行请求
  106. *
  107. * @param string $url :请求的URL
  108. * @param array $params :请求的参数,格式如: array('id'=>10,'name'=>'yuanwei')
  109. * @param array $referer :引用页面,为空时自动设置,如果服务器有对这个控制的话则一定要设置的.
  110. * @return 错误返回:false 正确返回:结果内容
  111. */
  112. public function get($url,$params=array(), $referer='')
  113. {
  114. return $this->_request('GET', $url, $params, array(), $referer);
  115. }
  116. /**
  117. * 以 POST 方式执行请求
  118. *
  119. * @param string $url :请求的URL
  120. * @param array $params :请求的参数,格式如: array('id'=>10,'name'=>'yuanwei')
  121. * @param array $uploadFile :上传的文件,支持相对路径,格式如下
  122. * 单个文件上传:array('img1'=>'./file/a.jpg')
  123. * 同字段多个文件上传:array('img'=>array('./file/a.jpg','./file/b.jpg'))
  124. * @param array $referer :引用页面,引用页面,为空时自动设置,如果服务器有对这个控制的话则一定要设置的.
  125. * @return 错误返回:false 正确返回:结果内容
  126. */
  127. public function post($url,$params=array(),$uploadFile=array(), $referer='')
  128. {
  129. return $this->_request('POST', $url, $params, $uploadFile, $referer);
  130. }
  131. /**
  132. * 得到错误信息
  133. *
  134. * @return string
  135. */
  136. public function error()
  137. {
  138. return curl_error($this->ch);
  139. }
  140. /**
  141. * 得到错误代码
  142. *
  143. * @return int
  144. */
  145. public function errno()
  146. {
  147. return curl_errno($this->ch);
  148. }
  149. /**
  150. * 得到发送请求前和请求后所有的服务器信息和服务器Header信息,其中
  151. * [before] :请求前所设置的信息
  152. * [after] :请求后所有的服务器信息
  153. * [header] :服务器Header报文信息
  154. *
  155. * @return array
  156. */
  157. public function getInfo()
  158. {
  159. return $this->info;
  160. }
  161. /**
  162. * 析构函数
  163. *
  164. */
  165. public function __destruct()
  166. {
  167. //关闭CURL
  168. curl_close($this->ch);
  169. }
  170. /**
  171. * 私有方法:执行最终请求
  172. *
  173. * @param string $method :HTTP请求方式
  174. * @param string $url :请求的URL
  175. * @param array $params :请求的参数
  176. * @param array $uploadFile :上传的文件(只有POST时才生效)
  177. * @param array $referer :引用页面
  178. * @return 错误返回:false 正确返回:结果内容
  179. */
  180. private function _request($method, $url, $params=array(), $uploadFile=array(), $referer='')
  181. {
  182. //如果是以GET方式请求则要连接到URL后面
  183. if($method == 'GET'){
  184. $url = $this->_parseUrl($url,$params);
  185. }
  186. //设置请求的URL
  187. curl_setopt($this->ch, CURLOPT_URL, $url);
  188. //如果是POST
  189. if($method == 'POST'){
  190. //发送一个常规的POST请求,类型为:application/x-www-form-urlencoded
  191. curl_setopt($this->ch, CURLOPT_POST, true) ;
  192. //设置POST字段值
  193. $postData = $this->_parsmEncode($params,false);
  194. /*
  195. //如果有上传文件
  196. if($uploadFile){
  197. foreach($uploadFile as $key=>$file){
  198. if(is_array($file)){
  199. $n = 0;
  200. foreach($file as $f){
  201. //文件必需是绝对路径
  202. $postData[$key.'['.$n++.']'] = '@'.realpath($f);
  203. }
  204. }else{
  205. $postData[$key] = '@'.realpath($file);
  206. }
  207. }
  208. }
  209. */
  210. //pr($postData); die;
  211. curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postData);
  212. }
  213. //设置了引用页,否则自动设置
  214. if($referer){
  215. curl_setopt($this->ch, CURLOPT_REFERER, $referer);
  216. }else{
  217. curl_setopt($this->ch, CURLOPT_AUTOREFERER, true);
  218. }
  219. //得到所有设置的信息
  220. $this->info['before'] = curl_getinfo($this->ch);
  221. //开始执行请求
  222. $result = curl_exec($this->ch);
  223. //得到报文头
  224. $headerSize = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
  225. $this->info['header'] = substr($result, 0, $headerSize);
  226. //去掉报文头
  227. $result = substr($result, $headerSize);
  228. //得到所有包括服务器返回的信息
  229. $this->info['after'] = curl_getinfo($this->ch);
  230. //如果请求成功
  231. if($this->errno() == 0){ //&& $this->info['after']['http_code'] == 200
  232. return $result;
  233. }else{
  234. return false;
  235. }
  236. }
  237. /**
  238. * 返回解析后的URL,GET方式时会用到
  239. *
  240. * @param string $url :URL
  241. * @param array $params :加在URL后的参数
  242. * @return string
  243. */
  244. private function _parseUrl($url,$params)
  245. {
  246. $fieldStr = $this->_parsmEncode($params);
  247. if($fieldStr){
  248. $url .= strstr($url,'?')===false ? '?' : '&';
  249. $url .= $fieldStr;
  250. }
  251. return $url;
  252. }
  253. /**
  254. * 对参数进行ENCODE编码
  255. *
  256. * @param array $params :参数
  257. * @param bool $isRetStr : true:以字符串返回 false:以数组返回
  258. * @return string || array
  259. */
  260. private function _parsmEncode($params,$isRetStr=true)
  261. {
  262. $fieldStr = '';
  263. $spr = '';
  264. $result = array();
  265. foreach($params as $key=>$value){
  266. $value = urlencode($value);
  267. $fieldStr .= $spr.$key .'='. $value;
  268. $spr = '&';
  269. $result[$key] = $value;
  270. }
  271. return $isRetStr ? $fieldStr : $result;
  272. }
  273. }
复制代码
p你看到QQ空间那个朋友好久没有联系了么


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!