|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我的这套线路可能跟许多学习PHP的爱好者不谋而合,这也算是一个循序渐进的学习过程,不过新手不要看到上面的概括就以为学习蛮简单的,默默在此不得不对您稍微泼一下冷水,任何东西其实都不简单。 QQ聊天机械人for PHP版 (登录,收、发动静)
01 <?php 02 // 不多说了,直接上转载请有名出处 php100.com 03 include "http.class.php"; 04 05 class qq { 06 07 public $sid; 08 public $http; 09 public $qq_num; 10 11 function __construct() { 12 $this->http = new http; 13 } 14 15 function login($qq_num, $qq_pwd) { 16 $data = $this->http->get("http://pt.3g.qq.com/"); 17 $action = preg_match("/action=\"(.+)?\"/", $data, $matches); 18 $action = $matches[1]; 19 $params = array(); 20 $params["login_url"] = "http://pt.3g.qq.com/s?aid=nLogin"; 21 $params["sidtype"] = 1; 22 $params["loginTitle"] = "手机腾讯网"; 23 $params["bid"] = 0; 24 $params["qq"] = $qq_num; 25 $params["pwd"] = $qq_pwd; 26 $params["loginType"] =1; 27 $data = $this->http->post($action, http_build_query($params)); 28 if(count(explode("验证码",$data))>1){ 29 preg_match("/<img src=\"(.+?)\"/", $data, $matches); 30 echo $matches[1]; 31 exit("需求输出验证码"); 32 } 33 $action = preg_match("/sid=(.+?)&/", $data, $matches); 34 $this->sid = $matches[1]; 35 return $this->sid; 36 } 37 38 function sendMsg($to_num, $msg, $sid = 0) { 39 $sid = $sid ? $sid : $this->sid; 40 if (!$sid) 41 exit("sid值未传入出来"); 42 $params = array(); 43 $params["msg"] = $msg; 44 $params["u"] = $to_num; 45 $params["saveURL"] = 0; 46 $params["do"] = "send"; 47 $params["on"] = 1; 48 $params["aid"] = "发送"; 49 $url = "http://q16.3g.qq.com/g/s?sid=" . $sid; 50 $data = $this->http->post($url, http_build_query($params)); 51 return $data; 52 } 53 54 function getMsg($qq_num = 0, $sid = 0) { 55 $qq_num = $qq_num ? $qq_num : $this->qq_num; 56 if (!$qq_num) 57 exit("qq_num值未传入出来"); 58 $sid = $sid ? $sid : $this->sid; 59 if (!$sid) 60 exit("sid值未传入出来"); 61 $url = "http://q16.3g.qq.com/g/s?sid=" . $sid . "&3G_UIN=" . $qq_num ."&saveURL=0&aid=nqqChat"; 62 $data = $this->http->get($url); 63 preg_match("/name=\"u\" value=\"(\d+)\"/", $data, $matches); 64 $result["qq"] = $matches[1]; 65 $data = explode("<form", $data); 66 $data = $data[0]; 67 preg_match_all("/<p>(.+)?<\/p>/", $data, $matches); 68 unset($matches[1][0]); 69 $result["content"] = $matches[1]; 70 return $result; 71 } 72 function logout($sid){ 73 $url="http://pt.3g.qq.com/s?sid=".$sid."&aid=nLogout"; 74 75 echo $this->http->get($url); 76 } 77 } [代码] http.class.php
01 <?php 02 03 class http { 04 05 private $curl; 06 public $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13"; 07 08 09 public function get($url) { 10 $this->curl = curl_init(); 11 curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 20); 12 curl_setopt($this->curl, CURLOPT_URL, $url); 13 curl_setopt($this->curl, CURLOPT_HEADER, 1); 14 curl_setopt($this->curl, CURLOPT_USERAGENT, $this->user_agent); 15 curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); 16 $data = curl_exec($this->curl); 17 curl_close($this->curl); 18 return $data; 19 } 20 21 public function post($url, $params) { 22 $this->curl = curl_init(); 23 curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 20); 24 curl_setopt($this->curl, CURLOPT_URL, $url); 25 curl_setopt($this->curl, CURLOPT_HEADER, 1); 26 //curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); 27 curl_setopt($this->curl, CURLOPT_POST, 1); 28 curl_setopt($this->curl, CURLOPT_USERAGENT, $this->user_agent); 29 curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params); 30 curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); 31 $data = curl_exec($this->curl); 32 curl_close($this->curl); 33 return $data; 34 } 35 36 } 37 38 ?> 39 原文:http://lvxinwei.sinaapp.com/961.html 也许您在学习PHP的时候只想尽快的开发一个网站,也就会想我做网站,干嘛要学什么网页这些小儿科?不难看出,眼高手低的新手不在少数,这种思想无疑于建造空中楼阁,你不建地基,何来的房顶呢? |
|