P. have you seen that friend in the QQ space hasn't been in touch for a long time?

Source: Internet
Author: User
P. have you seen that friend in the QQ space hasn't been in touch for a long time?
In the afternoon, I saw a popular space. my friends have been in touch for a long time! Contact me! The QQ and nickname of the person who sees it in his own space are displayed on the picture! How is this done? I wrote a demo here. To get QQ nicknames, you need to access a webpage. I have the original class here! It is used directly, and there are many ways to get it! But let's talk about code directly!

  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, 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 handle
  3. Private $ ch = null;
  4. // Information set before and after CURL execution or returned by the server
  5. Private $ info = array ();
  6. // Curl setopt information
  7. Private $ setopt = array (
  8. // The Access Port. the default http port is 80.
  9. 'Port' => 80,
  10. // Client USERAGENT, for example, "Mozilla/4.0". if it is null, use the user's browser.
  11. 'Useragent' => '',
  12. // Connection timeout
  13. 'Timeout' => 30,
  14. // Whether to use cookies. we recommend that you enable them because they are usually used by websites.
  15. 'Usecookier' => true,
  16. // Whether SSL is supported
  17. 'SSL '=> false,
  18. // Whether the client supports gzip compression
  19. 'Gzip' => true,
  20. // Use proxy?
  21. 'Proxy' => false,
  22. // Proxy type, which can be HTTP or SOCKS5
  23. 'Xytype' => 'http ',
  24. // The host address of the proxy, if it is HTTP, you need to write the URL form such as: "http://www.proxy.com"
  25. // In SOCKS5 mode, the host domain name is directly written as an IP address, for example, "192.168.1.1"
  26. 'Proxyhost' => 'http: // www.proxy.com ',
  27. // Proxy Host Port
  28. 'Proxyport' => 1234,
  29. // Whether the proxy needs identity authentication (in HTTP mode)
  30. 'Proxyauth' => false,
  31. // Authentication method. select BASIC or NTLM.
  32. 'Proxyauthtype' => 'basic ',
  33. // Authentication username and password
  34. 'Proxyauthuser' => 'user ',
  35. 'Proxyauthpwd' => 'password ',
  36. );
  37. /**
  38. * Constructor
  39. *
  40. * @ Param array $ setopt: refer to private $ setopt to set
  41. */
  42. Public function _ construct ($ setopt = array ())
  43. {
  44. // Merge user settings and default system settings
  45. $ This-> setopt = array_merge ($ this-> setopt, $ setopt );
  46. // Terminate the program if CURL is not installed
  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 ['xytype'] = '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 must 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 is put in the header and recursively returned to the server.
  68. Curl_setopt ($ this-> ch, CURLOPT_FOLLOWLOCATION, true );
  69. // Enable SSL
  70. If ($ this-> setopt ['SSL ']) {
  71. // Do not check the certificate source
  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 the http header to support access from the lighttpd server
  77. $ Header [] = 'CT :';
  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 wait time, 0 does not wait
  83. Curl_setopt ($ this-> ch, CURLOPT_CONNECTTIMEOUT, $ this-> setopt ['timeout']);
  84. // Sets the maximum number of seconds that curl can be executed.
  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 the COOKIE is used
  91. If ($ this-> setopt ['usecooker']) {
  92. // Generate a file for storing temporary cookies (absolute path required)
  93. $ Cookfile = tempnam (sys_get_temp_dir (), 'cuk ');
  94. // Store cookie information after the connection is closed
  95. Curl_setopt ($ this-> ch, CURLOPT_COOKIEJAR, $ cookfile );
  96. Curl_setopt ($ this-> ch, CURLOPT_COOKIEFILE, $ cookfile );
  97. }
  98. // Whether the HEADER file information is output as the data stream (HEADER information). The message is retained here.
  99. Curl_setopt ($ this-> ch, CURLOPT_HEADER, true );
  100. // The obtained information is returned in the form of a file stream, rather than directly output.
  101. Curl_setopt ($ this-> ch, CURLOPT_RETURNTRANSFER, true );
  102. Curl_setopt ($ this-> ch, CURLOPT_BINARYTRANSFER, true );
  103. }
  104. /**
  105. * Execute the request in GET mode.
  106. *
  107. * @ Param string $ url: The requested URL
  108. * @ Param array $ params: request parameter. Format: array ('id' => 10, 'name' => 'yuanwei ')
  109. * @ Param array $ referer: reference page. it is automatically set when it is null. if the server has this control, it must be set.
  110. * @ Return: false: The Returned result is correct.
  111. */
  112. Public function get ($ url, $ params = array (), $ referer = '')
  113. {
  114. Return $ this-> _ request ('GET', $ url, $ params, array (), $ referer );
  115. }
  116. /**
  117. * Execute the request in POST mode
  118. *
  119. * @ Param string $ url: The requested URL
  120. * @ Param array $ params: request parameter. Format: array ('id' => 10, 'name' => 'yuanwei ')
  121. * @ Param array $ uploadFile: the uploaded file. it supports relative paths. the format is as follows:
  122. * Upload a single file: array ('img1' => './file/a.jpg ')
  123. * Upload multiple files in the same field: array ('IMG '=> array ('./file/a.jpg ','./file/B .jpg '))
  124. * @ Param array $ referer: reference page, reference page. it is automatically set when it is null. if the server has this control, it must be set.
  125. * @ Return: false: The Returned result is correct.
  126. */
  127. Public function post ($ url, $ params = array (), $ uploadFile = array (), $ referer = '')
  128. {
  129. Return $ this-> _ request ('post', $ url, $ params, $ uploadFile, $ referer );
  130. }
  131. /**
  132. * Get error message
  133. *
  134. * @ Return string
  135. */
  136. Public function error ()
  137. {
  138. Return curl_error ($ this-> ch );
  139. }
  140. /**
  141. * Get the error code
  142. *
  143. * @ Return int
  144. */
  145. Public function errno ()
  146. {
  147. Return curl_errno ($ this-> ch );
  148. }
  149. /**
  150. * Obtain the server information and server Header information before and after the request is sent.
  151. * [Before]: information set before the request
  152. * [After]: all server information after the request
  153. * [Header]: Server Header message
  154. *
  155. * @ Return array
  156. */
  157. Public function getInfo ()
  158. {
  159. Return $ this-> info;
  160. }
  161. /**
  162. * Destructor
  163. *
  164. */
  165. Public function _ destruct ()
  166. {
  167. // Disable CURL
  168. Curl_close ($ this-> ch );
  169. }
  170. /**
  171. * Private method: execute the final request
  172. *
  173. * @ Param string $ method: HTTP request method
  174. * @ Param string $ url: The requested URL
  175. * @ Param array $ params: request parameter
  176. * @ Param array $ uploadFile: the uploaded file (effective only when POST is enabled)
  177. * @ Param array $ referer: Reference Page
  178. * @ Return: false: The Returned result is correct.
  179. */
  180. Private function _ request ($ method, $ url, $ params = array (), $ uploadFile = array (), $ referer = '')
  181. {
  182. // If the request is in GET mode, connect to the end of the URL
  183. If ($ method = 'get '){
  184. $ Url = $ this-> _ parseUrl ($ url, $ params );
  185. }
  186. // Set the request URL
  187. Curl_setopt ($ this-> ch, CURLOPT_URL, $ url );
  188. // If it is POST
  189. If ($ method = 'post '){
  190. // Send a regular POST request in the type of application/x-www-form-urlencoded
  191. Curl_setopt ($ this-> ch, CURLOPT_POST, true );
  192. // Set the POST field value
  193. $ PostData = $ this-> _ parsmEncode ($ params, false );
  194. /*
  195. // If a file is uploaded
  196. If ($ uploadFile ){
  197. Foreach ($ uploadFile as $ key => $ file ){
  198. If (is_array ($ file )){
  199. $ N = 0;
  200. Foreach ($ file as $ f ){
  201. // The file must be an absolute path
  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. // Set the reference page. Otherwise, the page is automatically set.
  214. If ($ referer ){
  215. Curl_setopt ($ this-> ch, CURLOPT_REFERER, $ referer );
  216. } Else {
  217. Curl_setopt ($ this-> ch, CURLOPT_AUTOREFERER, true );
  218. }
  219. // Get all settings
  220. $ This-> info ['before'] = curl_getinfo ($ this-> ch );
  221. // Start to execute the request
  222. $ Result = curl_exec ($ this-> ch );
  223. // Obtain the packet header
  224. $ HeaderSize = curl_getinfo ($ this-> ch, CURLINFO_HEADER_SIZE );
  225. $ This-> info ['head'] = substr ($ result, 0, $ headerSize );
  226. // Remove the packet header
  227. $ Result = substr ($ result, $ headerSize );
  228. // Obtain all information including the information returned by the server
  229. $ This-> info ['after'] = curl_getinfo ($ this-> ch );
  230. // If the request is successful
  231. If ($ this-> errno () = 0) {// & $ this-> info ['after'] ['http _ Code'] = 200
  232. Return $ result;
  233. } Else {
  234. Return false;
  235. }
  236. }
  237. /**
  238. * Returns the parsed URL, which is used in GET mode.
  239. *
  240. * @ Param string $ url: URL
  241. * @ Param array $ params: the parameter added after the 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 the parameter
  255. *
  256. * @ Param array $ params: parameter
  257. * @ Param bool $ isRetStr: true: returns false with a string: returns an array
  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. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.