欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP模拟登录QQ空间的例子

程序员文章站 2022-04-14 23:39:30
...
  1. include "include/http.class.php";
  2. $http = new http(1);
  3. $html = $http->get('http://check.ptlogin2.qq.com/check?uin=QQ账号&appid=15004501&r='.Math.rand(),1);
  4. $pattern = '/'.preg_quote("ptui_checkVC('0','",'/').'(.*?)'.preg_quote("',",'/').'/i';
  5. preg_match ( $pattern,$html, $matches);
  6. $yzm = $matches[1];
  7. $pattern = '/'.preg_quote("'\x",'/').'(.*?)'.preg_quote("');",'/').'/i';
  8. preg_match ( $pattern,$html, $matches);
  9. $yzmt = '\x'.$matches[1];
  10. $http -> get("http://ptlogin2.qq.com/login?u=QQ账号&p=".jspassword("QQ密码",$yzm,$yzmt)."&verifycode=".$yzm."&aid=15004501&u1=http%3A%2F%2Fctc.qzs.qq.com%2Fac%2Fqzone%2Flogin%2Fsucc.html%3Fpara%3Dtoolbar&h=1&ptredirect=0&ptlang=2052&from_ui=1&dumy=&fp=loginerroralert&mibao_css=&t=1&g=1");
  11. function jspassword($p, $vc, $vt) {
  12. $p = strtoupper(md5($p));
  13. for ($i = 0; $i return strtoupper(md5(strtoupper(md5(hex2asc($temp) . hex2asc($vt))) . $vc));
  14. }
  15. function hex2asc($str) {
  16. $str = join('', explode('\x', $str));
  17. for ($i = 0;$i return $data;
  18. }
复制代码

如下图: PHP模拟登录QQ空间的例子

http.class.php文件代码:

  1. // +----------------------------------------------------------------------
  2. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  7. // +----------------------------------------------------------------------
  8. // | Author: liu21st
  9. // +----------------------------------------------------------------------
  10. // $Id$
  11. /**
  12. +------------------------------------------------------------------------------
  13. * Http 工具类
  14. * 提供一系列的Http方法
  15. +------------------------------------------------------------------------------
  16. * @category ORG
  17. * @package ORG
  18. * @subpackage Net
  19. * @author liu21st
  20. * @version $Id$
  21. +------------------------------------------------------------------------------
  22. */
  23. class Http
  24. {//类定义开始
  25. /**
  26. +----------------------------------------------------------
  27. * 采集远程文件
  28. +----------------------------------------------------------
  29. * @access public
  30. +----------------------------------------------------------
  31. * @param string $remote 远程文件名
  32. * @param string $local 本地保存文件名
  33. +----------------------------------------------------------
  34. * @return mixed
  35. +----------------------------------------------------------
  36. */
  37. static public function curl_download($remote,$local) {
  38. $cp = curl_init($remote);
  39. $fp = fopen($local,"w");
  40. curl_setopt($cp, CURLOPT_FILE, $fp);
  41. curl_setopt($cp, CURLOPT_HEADER, 0);
  42. curl_exec($cp);
  43. curl_close($cp);
  44. fclose($fp);
  45. }
  46. /**
  47. +----------------------------------------------------------
  48. * 下载文件
  49. * 可以指定下载显示的文件名,并自动发送相应的Header信息
  50. * 如果指定了content参数,则下载该参数的内容
  51. +----------------------------------------------------------
  52. * @static
  53. * @access public
  54. +----------------------------------------------------------
  55. * @param string $filename 下载文件名
  56. * @param string $showname 下载显示的文件名
  57. * @param string $content 下载的内容
  58. * @param integer $expire 下载内容浏览器缓存时间
  59. +----------------------------------------------------------
  60. * @return void
  61. +----------------------------------------------------------
  62. * @throws ThinkExecption
  63. +----------------------------------------------------------
  64. */
  65. static public function download ($filename, $showname='',$content='',$expire=180) {
  66. if(is_file($filename)) {
  67. $length = filesize($filename);
  68. }elseif(is_file(UPLOAD_PATH.$filename)) {
  69. $filename = UPLOAD_PATH.$filename;
  70. $length = filesize($filename);
  71. }elseif($content != '') {
  72. $length = strlen($content);
  73. }else {
  74. throw_exception($filename.L('下载文件不存在!'));
  75. }
  76. if(empty($showname)) {
  77. $showname = $filename;
  78. }
  79. $showname = basename($showname);
  80. if(!empty($filename)) {
  81. $type = mime_content_type($filename);
  82. }else{
  83. $type = "application/octet-stream";
  84. }
  85. //发送Http Header信息 开始下载
  86. header("Pragma: public");
  87. header("Cache-control: max-age=".$expire);
  88. //header('Cache-Control: no-store, no-cache, must-revalidate');
  89. header("Expires: " . gmdate("D, d M Y H:i:s",time()+$expire) . "GMT");
  90. header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT");
  91. header("Content-Disposition: attachment; filename=".$showname);
  92. header("Content-Length: ".$length);
  93. header("Content-type: ".$type);
  94. header('Content-Encoding: none');
  95. header("Content-Transfer-Encoding: binary" );
  96. if($content == '' ) {
  97. readfile($filename);
  98. }else {
  99. echo($content);
  100. }
  101. exit();
  102. }
  103. /**
  104. +----------------------------------------------------------
  105. * 显示HTTP Header 信息
  106. +----------------------------------------------------------
  107. * @return string
  108. +----------------------------------------------------------
  109. */
  110. static function get_header_info($header='',$echo=true)
  111. {
  112. ob_start();
  113. $headers = getallheaders();
  114. if(!empty($header)) {
  115. $info = $headers[$header];
  116. echo($header.':'.$info."\n"); ;
  117. }else {
  118. foreach($headers as $key=>$val) {
  119. echo("$key:$val\n");
  120. }
  121. }
  122. $output = ob_get_clean();
  123. if ($echo) {
  124. echo (nl2br($output));
  125. }else {
  126. return $output;
  127. }
  128. }
  129. /**
  130. * HTTP Protocol defined status codes
  131. * @param int $num
  132. */
  133. static function send_http_status($code) {
  134. static $_status = array(
  135. // Informational 1xx
  136. 100 => 'Continue',
  137. 101 => 'Switching Protocols',
  138. // Success 2xx
  139. 200 => 'OK',
  140. 201 => 'Created',
  141. 202 => 'Accepted',
  142. 203 => 'Non-Authoritative Information',
  143. 204 => 'No Content',
  144. 205 => 'Reset Content',
  145. 206 => 'Partial Content',
  146. // Redirection 3xx
  147. 300 => 'Multiple Choices',
  148. 301 => 'Moved Permanently',
  149. 302 => 'Found', // 1.1
  150. 303 => 'See Other',
  151. 304 => 'Not Modified',
  152. 305 => 'Use Proxy',
  153. // 306 is deprecated but reserved
  154. 307 => 'Temporary Redirect',
  155. // Client Error 4xx
  156. 400 => 'Bad Request',
  157. 401 => 'Unauthorized',
  158. 402 => 'Payment Required',
  159. 403 => 'Forbidden',
  160. 404 => 'Not Found',
  161. 405 => 'Method Not Allowed',
  162. 406 => 'Not Acceptable',
  163. 407 => 'Proxy Authentication Required',
  164. 408 => 'Request Timeout',
  165. 409 => 'Conflict',
  166. 410 => 'Gone',
  167. 411 => 'Length Required',
  168. 412 => 'Precondition Failed',
  169. 413 => 'Request Entity Too Large',
  170. 414 => 'Request-URI Too Long',
  171. 415 => 'Unsupported Media Type',
  172. 416 => 'Requested Range Not Satisfiable',
  173. 417 => 'Expectation Failed',
  174. // Server Error 5xx
  175. 500 => 'Internal Server Error',
  176. 501 => 'Not Implemented',
  177. 502 => 'Bad Gateway',
  178. 503 => 'Service Unavailable',
  179. 504 => 'Gateway Timeout',
  180. 505 => 'HTTP Version Not Supported',
  181. 509 => 'Bandwidth Limit Exceeded'
  182. );
  183. if(array_key_exists($code,$_status)) {
  184. header('HTTP/1.1 '.$code.' '.$_status[$code]);
  185. }
  186. }
  187. }//类定义结束
  188. if( !function_exists ('mime_content_type')) {
  189. /**
  190. +----------------------------------------------------------
  191. * 获取文件的mime_content类型
  192. +----------------------------------------------------------
  193. * @return string
  194. +----------------------------------------------------------
  195. */
  196. function mime_content_type($filename)
  197. {
  198. static $contentType = array(
  199. 'ai' => 'application/postscript',
  200. 'aif' => 'audio/x-aiff',
  201. 'aifc' => 'audio/x-aiff',
  202. 'aiff' => 'audio/x-aiff',
  203. 'asc' => 'application/pgp', //changed by skwashd - was text/plain
  204. 'asf' => 'video/x-ms-asf',
  205. 'asx' => 'video/x-ms-asf',
  206. 'au' => 'audio/basic',
  207. 'avi' => 'video/x-msvideo',
  208. 'bcpio' => 'application/x-bcpio',
  209. 'bin' => 'application/octet-stream',
  210. 'bmp' => 'image/bmp',
  211. 'c' => 'text/plain', // or 'text/x-csrc', //added by skwashd
  212. 'cc' => 'text/plain', // or 'text/x-c++src', //added by skwashd
  213. 'cs' => 'text/plain', //added by skwashd - for C# src
  214. 'cpp' => 'text/x-c++src', //added by skwashd
  215. 'cxx' => 'text/x-c++src', //added by skwashd
  216. 'cdf' => 'application/x-netcdf',
  217. 'class' => 'application/octet-stream',//secure but application/java-class is correct
  218. 'com' => 'application/octet-stream',//added by skwashd
  219. 'cpio' => 'application/x-cpio',
  220. 'cpt' => 'application/mac-compactpro',
  221. 'csh' => 'application/x-csh',
  222. 'css' => 'text/css',
  223. 'csv' => 'text/comma-separated-values',//added by skwashd
  224. 'dcr' => 'application/x-director',
  225. 'diff' => 'text/diff',
  226. 'dir' => 'application/x-director',
  227. 'dll' => 'application/octet-stream',
  228. 'dms' => 'application/octet-stream',
  229. 'doc' => 'application/msword',
  230. 'dot' => 'application/msword',//added by skwashd
  231. 'dvi' => 'application/x-dvi',
  232. 'dxr' => 'application/x-director',
  233. 'eps' => 'application/postscript',
  234. 'etx' => 'text/x-setext',
  235. 'exe' => 'application/octet-stream',
  236. 'ez' => 'application/andrew-inset',
  237. 'gif' => 'image/gif',
  238. 'gtar' => 'application/x-gtar',
  239. 'gz' => 'application/x-gzip',
  240. 'h' => 'text/plain', // or 'text/x-chdr',//added by skwashd
  241. 'h++' => 'text/plain', // or 'text/x-c++hdr', //added by skwashd
  242. 'hh' => 'text/plain', // or 'text/x-c++hdr', //added by skwashd
  243. 'hpp' => 'text/plain', // or 'text/x-c++hdr', //added by skwashd
  244. 'hxx' => 'text/plain', // or 'text/x-c++hdr', //added by skwashd
  245. 'hdf' => 'application/x-hdf',
  246. 'hqx' => 'application/mac-binhex40',
  247. 'htm' => 'text/html',
  248. 'html' => 'text/html',
  249. 'ice' => 'x-conference/x-cooltalk',
  250. 'ics' => 'text/calendar',
  251. 'ief' => 'image/ief',
  252. 'ifb' => 'text/calendar',
  253. 'iges' => 'model/iges',
  254. 'igs' => 'model/iges',
  255. 'jar' => 'application/x-jar', //added by skwashd - alternative mime type
  256. 'java' => 'text/x-java-source', //added by skwashd
  257. 'jpe' => 'image/jpeg',
  258. 'jpeg' => 'image/jpeg',
  259. 'jpg' => 'image/jpeg',
  260. 'js' => 'application/x-javascript',
  261. 'kar' => 'audio/midi',
  262. 'latex' => 'application/x-latex',
  263. 'lha' => 'application/octet-stream',
  264. 'log' => 'text/plain',
  265. 'lzh' => 'application/octet-stream',
  266. 'm3u' => 'audio/x-mpegurl',
  267. 'man' => 'application/x-troff-man',
  268. 'me' => 'application/x-troff-me',
  269. 'mesh' => 'model/mesh',
  270. 'mid' => 'audio/midi',
  271. 'midi' => 'audio/midi',
  272. 'mif' => 'application/vnd.mif',
  273. 'mov' => 'video/quicktime',
  274. 'movie' => 'video/x-sgi-movie',
  275. 'mp2' => 'audio/mpeg',
  276. 'mp3' => 'audio/mpeg',
  277. 'mpe' => 'video/mpeg',
  278. 'mpeg' => 'video/mpeg',
  279. 'mpg' => 'video/mpeg',
  280. 'mpga' => 'audio/mpeg',
  281. 'ms' => 'application/x-troff-ms',
  282. 'msh' => 'model/mesh',
  283. 'mxu' => 'video/vnd.mpegurl',
  284. 'nc' => 'application/x-netcdf',
  285. 'oda' => 'application/oda',
  286. 'patch' => 'text/diff',
  287. 'pbm' => 'image/x-portable-bitmap',
  288. 'pdb' => 'chemical/x-pdb',
  289. 'pdf' => 'application/pdf',
  290. 'pgm' => 'image/x-portable-graymap',
  291. 'pgn' => 'application/x-chess-pgn',
  292. 'pgp' => 'application/pgp',//added by skwashd
  293. 'php' => 'application/x-httpd-php',
  294. 'php3' => 'application/x-httpd-php3',
  295. 'pl' => 'application/x-perl',
  296. 'pm' => 'application/x-perl',
  297. 'png' => 'image/png',
  298. 'pnm' => 'image/x-portable-anymap',
  299. 'po' => 'text/plain',
  300. 'ppm' => 'image/x-portable-pixmap',
  301. 'ppt' => 'application/vnd.ms-powerpoint',
  302. 'ps' => 'application/postscript',
  303. 'qt' => 'video/quicktime',
  304. 'ra' => 'audio/x-realaudio',
  305. 'rar'=>'application/octet-stream',
  306. 'ram' => 'audio/x-pn-realaudio',
  307. 'ras' => 'image/x-cmu-raster',
  308. 'rgb' => 'image/x-rgb',
  309. 'rm' => 'audio/x-pn-realaudio',
  310. 'roff' => 'application/x-troff',
  311. 'rpm' => 'audio/x-pn-realaudio-plugin',
  312. 'rtf' => 'text/rtf',
  313. 'rtx' => 'text/richtext',
  314. 'sgm' => 'text/sgml',
  315. 'sgml' => 'text/sgml',
  316. 'sh' => 'application/x-sh',
  317. 'shar' => 'application/x-shar',
  318. 'shtml' => 'text/html',
  319. 'silo' => 'model/mesh',
  320. 'sit' => 'application/x-stuffit',
  321. 'skd' => 'application/x-koan',
  322. 'skm' => 'application/x-koan',
  323. 'skp' => 'application/x-koan',
  324. 'skt' => 'application/x-koan',
  325. 'smi' => 'application/smil',
  326. 'smil' => 'application/smil',
  327. 'snd' => 'audio/basic',
  328. 'so' => 'application/octet-stream',
  329. 'spl' => 'application/x-futuresplash',
  330. 'src' => 'application/x-wais-source',
  331. 'stc' => 'application/vnd.sun.xml.calc.template',
  332. 'std' => 'application/vnd.sun.xml.draw.template',
  333. 'sti' => 'application/vnd.sun.xml.impress.template',
  334. 'stw' => 'application/vnd.sun.xml.writer.template',
  335. 'sv4cpio' => 'application/x-sv4cpio',
  336. 'sv4crc' => 'application/x-sv4crc',
  337. 'swf' => 'application/x-shockwave-flash',
  338. 'sxc' => 'application/vnd.sun.xml.calc',
  339. 'sxd' => 'application/vnd.sun.xml.draw',
  340. 'sxg' => 'application/vnd.sun.xml.writer.global',
  341. 'sxi' => 'application/vnd.sun.xml.impress',
  342. 'sxm' => 'application/vnd.sun.xml.math',
  343. 'sxw' => 'application/vnd.sun.xml.writer',
  344. 't' => 'application/x-troff',
  345. 'tar' => 'application/x-tar',
  346. 'tcl' => 'application/x-tcl',
  347. 'tex' => 'application/x-tex',
  348. 'texi' => 'application/x-texinfo',
  349. 'texinfo' => 'application/x-texinfo',
  350. 'tgz' => 'application/x-gtar',
  351. 'tif' => 'image/tiff',
  352. 'tiff' => 'image/tiff',
  353. 'tr' => 'application/x-troff',
  354. 'tsv' => 'text/tab-separated-values',
  355. 'txt' => 'text/plain',
  356. 'ustar' => 'application/x-ustar',
  357. 'vbs' => 'text/plain', //added by skwashd - for obvious reasons
  358. 'vcd' => 'application/x-cdlink',
  359. 'vcf' => 'text/x-vcard',
  360. 'vcs' => 'text/calendar',
  361. 'vfb' => 'text/calendar',
  362. 'vrml' => 'model/vrml',
  363. 'vsd' => 'application/vnd.visio',
  364. 'wav' => 'audio/x-wav',
  365. 'wax' => 'audio/x-ms-wax',
  366. 'wbmp' => 'image/vnd.wap.wbmp',
  367. 'wbxml' => 'application/vnd.wap.wbxml',
  368. 'wm' => 'video/x-ms-wm',
  369. 'wma' => 'audio/x-ms-wma',
  370. 'wmd' => 'application/x-ms-wmd',
  371. 'wml' => 'text/vnd.wap.wml',
  372. 'wmlc' => 'application/vnd.wap.wmlc',
  373. 'wmls' => 'text/vnd.wap.wmlscript',
  374. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  375. 'wmv' => 'video/x-ms-wmv',
  376. 'wmx' => 'video/x-ms-wmx',
  377. 'wmz' => 'application/x-ms-wmz',
  378. 'wrl' => 'model/vrml',
  379. 'wvx' => 'video/x-ms-wvx',
  380. 'xbm' => 'image/x-xbitmap',
  381. 'xht' => 'application/xhtml+xml',
  382. 'xhtml' => 'application/xhtml+xml',
  383. 'xls' => 'application/vnd.ms-excel',
  384. 'xlt' => 'application/vnd.ms-excel',
  385. 'xml' => 'application/xml',
  386. 'xpm' => 'image/x-xpixmap',
  387. 'xsl' => 'text/xml',
  388. 'xwd' => 'image/x-xwindowdump',
  389. 'xyz' => 'chemical/x-xyz',
  390. 'z' => 'application/x-compress',
  391. 'zip' => 'application/zip',
  392. );
  393. $type = strtolower(substr(strrchr($filename, '.'),1));
  394. if(isset($contentType[$type])) {
  395. $mime = $contentType[$type];
  396. }else {
  397. $mime = 'application/octet-stream';
  398. }
  399. return $mime;
  400. }
  401. }
  402. if(!function_exists('image_type_to_extension'))
  403. {
  404. function image_type_to_extension($imagetype)
  405. {
  406. if(empty($imagetype)) return false;
  407. switch($imagetype)
  408. {
  409. case IMAGETYPE_GIF : return '.gif';
  410. case IMAGETYPE_JPEG : return '.jpg';
  411. case IMAGETYPE_PNG : return '.png';
  412. case IMAGETYPE_SWF : return '.swf';
  413. case IMAGETYPE_PSD : return '.psd';
  414. case IMAGETYPE_BMP : return '.bmp';
  415. case IMAGETYPE_TIFF_II : return '.tiff';
  416. case IMAGETYPE_TIFF_MM : return '.tiff';
  417. case IMAGETYPE_JPC : return '.jpc';
  418. case IMAGETYPE_JP2 : return '.jp2';
  419. case IMAGETYPE_JPX : return '.jpf';
  420. case IMAGETYPE_JB2 : return '.jb2';
  421. case IMAGETYPE_SWC : return '.swc';
  422. case IMAGETYPE_IFF : return '.aiff';
  423. case IMAGETYPE_WBMP : return '.wbmp';
  424. case IMAGETYPE_XBM : return '.xbm';
  425. default : return false;
  426. }
  427. }
  428. }
  429. ?>
复制代码

>>> 更多 php模拟登录 文章,专题链接:php模拟登录 php curl模拟登录教程大全