Home > Backend Development > PHP Tutorial > pDid you see that friend in QQ space that you haven't contacted for a long time?

pDid you see that friend in QQ space that you haven't contacted for a long time?

WBOY
Release: 2016-07-25 08:51:10
Original
1335 people have browsed it
In the afternoon, I saw a space becoming popular. My friends have been in touch for a long time! Contact me! Whoever sees it in your own space will have their QQ and nickname displayed on the picture! How is this done? I wrote a small demo here. To get a QQ nickname, you need to visit a web page. I have the original class here! Just use it directly, there are many ways to get it! But let’s go straight to the code!
  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. ?>
Copy code
  1. class Curl{
  2. //CURL handle
  3. private $ch = null;
  4. //Information set or returned by the server before and after CURL execution
  5. private $info = array();
  6. //CURL SETOPT information
  7. private $setopt = array(
  8. //The accessed port, http default is 80
  9. 'port'=>80,
  10. //Client USERAGENT, such as: "Mozilla/4.0", if it is empty Use the user's browser
  11. 'userAgent'=>'',
  12. //Connection timeout period
  13. 'timeOut'=>30,
  14. //Whether to use COOKIE is recommended to be turned on, because most websites will use it
  15. 'useCookie'= >true,
  16. //Whether to support SSL
  17. 'ssl'=>false,
  18. //Whether the client supports gzip compression
  19. 'gzip'=>true,
  20. //Whether to use a proxy
  21. 'proxy'=> ;false,
  22. //Proxy type, you can choose HTTP or SOCKS5
  23. 'proxyType'=>'HTTP',
  24. //The host address of the proxy, if it is HTTP mode, it should be written in the URL format, such as: "http://www .proxy.com"
  25. //SOCKS5 method directly writes the host domain name in the form of IP, such as: "192.168.1.1"
  26. 'proxyHost'=>'http://www.proxy.com',
  27. //Proxy The port of the host
  28. 'proxyPort'=>1234,
  29. //Whether the proxy requires identity authentication (in HTTP mode)
  30. 'proxyAuth'=>false,
  31. //Authentication method. You can choose BASIC or NTLM method
  32. 'proxyAuthType '=>'BASIC',
  33. //Authenticated username and password
  34. 'proxyAuthUser'=>'user',
  35. 'proxyAuthPwd'=>'password',
  36. );
  37. /**
  38. * Constructor
  39. *
  40. * @param array $setopt: Please refer to private $setopt to set
  41. * /
  42. public function __construct($setopt=array())
  43. {
  44. //Merge user settings and system default settings
  45. $this->setopt = array_merge($this->setopt,$setopt);
  46. / /If CURL is not installed, terminate the program
  47. function_exists('curl_init') || die('CURL Library Not Loaded');
  48. //Initialization
  49. $this->ch = curl_init();
  50. //Set the CURL connection Port
  51. curl_setopt($this->ch, CURLOPT_PORT, $this->setopt['port']);
  52. //Use proxy
  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. //The proxy needs to be authenticated
  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. //When enabled, the "Location:" returned by the server will be returned Put it in the header and return it to the server recursively
  68. curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
  69. //Open support for SSL
  70. if($this->setopt['ssl']){
  71. // No check on the source of the authentication certificate
  72. curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
  73. //Check whether the SSL encryption algorithm exists from the certificate
  74. curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, true);
  75. }
  76. //Set http header to support access to lighttpd server
  77. $header[]= 'Expect:';
  78. curl_setopt($this->ch, CURLOPT_HTTPHEADER, $header);
  79. //Set HTTP USERAGENT
  80. $userAgent = $ this->setopt['userAgent'] ? $this->setopt['userAgent'] : $_SERVER['HTTP_USER_AGENT'];
  81. curl_setopt($this->ch, CURLOPT_USERAGENT, $userAgent);
  82. // Set the connection waiting time, 0 does not wait
  83. curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $this->setopt['timeOut']);
  84. //Set the maximum number of seconds curl is allowed to execute
  85. curl_setopt($this ->ch, CURLOPT_TIMEOUT, $this->setopt['timeOut']);
  86. //Set whether the client supports gzip compression
  87. if($this->setopt['gzip']){
  88. curl_setopt($ this->ch, CURLOPT_ENCODING, 'gzip');
  89. }
  90. //Whether COOKIE is used? if($this->setopt['useCookie']){
  91. //Generate a file to store temporary COOKIE (must be absolute path)
  92. $cookfile = tempnam(sys_get_temp_dir(),'cuk');
  93. //After the connection is closed, store cookie information
  94. curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookfile);
  95. curl_setopt($this-> ;ch, CURLOPT_COOKIEFILE, $cookfile);
  96. }
  97. //Whether to output the header file information as a data stream (HEADER information), retain the message here
  98. curl_setopt($this->ch, CURLOPT_HEADER, true);
  99. / /The obtained information is returned in the form of a file stream instead of being output directly.
  100. curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true) ;
  101. curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, true) ;
  102. }
  103. /**
  104. * Execute the request in GET mode
  105. *
  106. * @param string $url: the URL of the request
  107. * @param array $params: the parameters of the request, the format is like: array('id'=>10,'name'=> ;'yuanwei')
  108. * @param array $referer: Reference page, automatically set when empty. If the server has control over this, it must be set.
  109. * @return Error return: false Correct return: result content
  110. */
  111. public function get($url,$params=array(), $referer='')
  112. {
  113. return $this->_request('GET', $url, $params, array(), $referer);
  114. }
  115. /**
  116. * Execute the request in POST mode
  117. *
  118. * @param string $url: the URL of the request
  119. * @param array $params: the parameters of the request, the format is like: array('id'=>10,'name'=> ;'yuanwei')
  120. * @param array $uploadFile: The uploaded file supports relative paths and the format is as follows
  121. * Single file upload: array('img1'=>'./file/a.jpg')
  122. * Same as Field multiple file upload: array('img'=>array('./file/a.jpg','./file/b.jpg'))
  123. * @param array $referer: reference page, reference page , automatically set when empty. If the server has control over this, it must be set.
  124. * @return Error return: false Correct return: result content
  125. */
  126. public function post($url,$params=array(),$uploadFile=array(), $referer='')
  127. {
  128. return $this->_request('POST', $url, $params, $uploadFile, $referer);
  129. }
  130. /**
  131. * Get error message
  132. *
  133. * @return string
  134. */
  135. public function error()
  136. {
  137. return curl_error($this->ch);
  138. }
  139. /**
  140. * Get error code
  141. *
  142. * @return int
  143. */
  144. public function errno()
  145. {
  146. return curl_errno($this->ch);
  147. }
  148. /**
  149. * Get all the server information and server header information before and after sending the request, where
  150. * [before]: the information set before the request
  151. * [after]: all the server information after the request
  152. * [header]: server Header message information
  153. *
  154. * @return array
  155. */
  156. public function getInfo()
  157. {
  158. return $this->info;
  159. }
  160. /**
  161. * Destructor
  162. *
  163. */
  164. public function __destruct()
  165. {
  166. //关闭CURL
  167. curl_close($this->ch);
  168. }
  169. /**
  170. * Private method: Execute the final request
  171. *
  172. * @param string $method: HTTP request method
  173. * @param string $url: Requested URL
  174. * @param array $params: Requested parameters
  175. * @param array $uploadFile :Uploaded file (valid only when POST)
  176. * @param array $referer: Reference page
  177. * @return Error return: false Correct return: result content
  178. */
  179. private function _request($method, $url, $params=array(), $uploadFile=array(), $referer='')
  180. {
  181. //如果是以GET方式请求则要连接到URL后面
  182. if($method == 'GET'){
  183. $url = $this->_parseUrl($url,$params);
  184. }
  185. //设置请求的URL
  186. curl_setopt($this->ch, CURLOPT_URL, $url);
  187. //如果是POST
  188. if($method == 'POST'){
  189. //发送一个常规的POST请求,类型为:application/x-www-form-urlencoded
  190. curl_setopt($this->ch, CURLOPT_POST, true) ;
  191. //设置POST字段值
  192. $postData = $this->_parsmEncode($params,false);
  193. /*
  194. //如果有上传文件
  195. if($uploadFile){
  196. foreach($uploadFile as $key=>$file){
  197. if(is_array($file)){
  198. $n = 0;
  199. foreach($file as $f){
  200. //文件必需是绝对路径
  201. $postData[$key.'['.$n++.']'] = '@'.realpath($f);
  202. }
  203. }else{
  204. $postData[$key] = '@'.realpath($file);
  205. }
  206. }
  207. }
  208. */
  209. //pr($postData); die;
  210. curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postData);
  211. }
  212. //设置了引用页,否则自动设置
  213. if($referer){
  214. curl_setopt($this->ch, CURLOPT_REFERER, $referer);
  215. }else{
  216. curl_setopt($this->ch, CURLOPT_AUTOREFERER, true);
  217. }
  218. //得到所有设置的信息
  219. $this->info['before'] = curl_getinfo($this->ch);
  220. //开始执行请求
  221. $result = curl_exec($this->ch);
  222. //得到报文头
  223. $headerSize = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
  224. $this->info['header'] = substr($result, 0, $headerSize);
  225. //去掉报文头
  226. $result = substr($result, $headerSize);
  227. //得到所有包括服务器返回的信息
  228. $this->info['after'] = curl_getinfo($this->ch);
  229. //如果请求成功
  230. if($this->errno() == 0){ //&& $this->info['after']['http_code'] == 200
  231. return $result;
  232. }else{
  233. return false;
  234. }
  235. }
  236. /**
  237. * Returns the parsed URL, which will be used in GET mode
  238. *
  239. * @param string $url:URL
  240. * @param array $params: Parameters added after the URL
  241. * @return string
  242. */
  243. private function _parseUrl($url,$params)
  244. {
  245. $fieldStr = $this->_parsmEncode($params);
  246. if($fieldStr){
  247. $url .= strstr($url,'?')===false ? '?' : '&';
  248. $url .= $fieldStr;
  249. }
  250. return $url;
  251. }
  252. /**
  253. * ENCODE encode the parameters
  254. *
  255. * @param array $params: parameters
  256. * @param bool $isRetStr: true: return as string false: return as array
  257. * @return string || array
  258. */
  259. private function _parsmEncode($params,$isRetStr=true)
  260. {
  261. $fieldStr = '';
  262. $spr = '';
  263. $result = array();
  264. foreach($params as $key=>$value){
  265. $value = urlencode($value);
  266. $fieldStr .= $spr.$key .'='. $value;
  267. $spr = '&';
  268. $result[$key] = $value;
  269. }
  270. return $isRetStr ? $fieldStr : $result;
  271. }
  272. }
复制代码
pDid you see that friend in QQ space that you haven't contacted for a long time?


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template