Header (' content-type:text/html; Charset=utf-8 '); /** * PHP Letter Send Class * @author Quanhengzhuang * @version 1.5.0 */ Class Phpfetion { /** * Sender Cell phone number * @var String */ protected $_mobile; /** * Flying Letter Password * @param string */ protected $_password; /** * Cookie String * @param string */ protected $_cookie = '; /** * UID Cache * @var Array */ Protected $_uids = Array (); /** * Csrftoken * @param string */ protected $_csrftoten = null; /** * Constructor * @param string $mobile mobile phone number (login) * @param string $password letter Letter Password */ Public function __construct ($mobile, $password) { if ($mobile = = = ' | | $password = = = ') { Return } $this->_mobile = $mobile; $this->_password = $password; $this->_login (); } /** * destructor */ Public Function __destruct () { $this->_logout (); } /** * Login * @return String */ protected function _login () { $uri = '/huc/user/space/login.do?m=submit&fr=space '; $data = ' mobilenum= '. $this->_mobile. ' &password= '. UrlEncode ($this->_password); $result = $this->_postwithcookie ($uri, $data); Parsing cookies Preg_match_all ('/.*?rnset-cookie: (. *?);. *?/si ', $result, $matches); if (Isset ($matches [1])) { $this->_cookie = implode ('; ', $matches [1]); } $result = $this->_postwithcookie ('/im/login/cklogin.action ', '); return $result; } /** * Get Csrftoken, send a letter to a friend when you need this field * @param string $UID flying Letter Id * @return String */ protected function _getcsrftoken ($UID) { if ($this->_csrftoten = = null) { $uri = '/im/chat/toinputmsg.action?touserid= '. $uid; $result = $this->_postwithcookie ($uri, "); Preg_match ('/name= "Csrftoken". *?value= "(. *?)" /', $result, $matches); $this->_csrftoten = Isset ($matches [1])? $matches [1]: '; } return $this->_csrftoten; } /** * Send a letter to the designated mobile phone number * @param string $mobile cell phone number (receiver) * @param string $message SMS Content * @return String */ Public function Send ($mobile, $message) { if ($message = = = ") { Return "; } The judgment is to give oneself back is to the friend hair if ($mobile = = = $this->_mobile) { return $this->_tomyself ($message); } else if (strlen ($mobile) ===11) { $uid = $this->_getuid ($mobile); } else { $uid = $mobile; } return $uid = = = '? $this->_addfriend ($mobile): $this->_touid ($uid, $message); } protected function _getname () { $uri = '/im/index/index.action '; $result = $this->_postwithcookie ($uri, ' # '); The Preg_match ('/(. *?) </a>/si ', $result, $matches); return $matches [2]; } /* * Add friends through mobile phone number * @param string $number mobile phone number (to add a friend mobile phone) * @param string $nickname your name, appearing in the other person's verification message * @param string $buddylist grouped, default is null * @param string $localName friend screen name * @return String */ protected function _addfriend ($number) { $uri = '/im/user/insertfriendsubmit.action '; $data = ' nickname= '. UrlEncode ($this->_getname ()). ' &buddylist=1&localname=&number= '. $number. ' &type=0 '; $result = $this->_postwithcookie ($uri, $data); return $result; } /** * Get Letter Id * @param string $mobile cell phone number * @return String */ protected function _getuid ($mobile) { if (Empty ($this->_uids[$mobile])) { $uri = '/im/index/searchotherinfolist.action '; $data = ' searchtext= '. $mobile; $result = $this->_postwithcookie ($uri, $data); The Preg_match ('/toinputmsg.action?touserid= (d+)/si ', $result, $matches); $this->_uids[$mobile] = isset ($matches [1])? $matches [1]: '; } return $this->_uids[$mobile]; } /** * Send a letter to a friend * @param string $UID flying Letter Id * @param string $message SMS Content * @return String */ protected function _touid ($uid, $message) { $uri = '/im/chat/sendmsg.action?touserid= '. $uid; $csrfToken = $this->_getcsrftoken ($uid); $data = ' msg= '. UrlEncode ($message). ' &csrftoken= '. $csrfToken; $result = $this->_postwithcookie ($uri, $data); return $result; } /** * Send yourself a letter * @param string $message * @return String */ protected function _tomyself ($message) { $uri = '/im/user/sendmsgtomyselfs.action '; $result = $this->_postwithcookie ($uri, ' msg= '. UrlEncode ($message)); return $result; } /** * Quit flying * @return String */ protected function _logout () { $uri = '/im/index/logoutsubmit.action '; $result = $this->_postwithcookie ($uri, "); return $result; } protected function Getgroup () { $uri = '/im/index/index.action '; $data = ' Type=group '; $result = $this->_postwithcookie ($uri, $data); The Preg_match_all ('/contactlistview.action?idcontactlist= (d+)/si ', $result, $matches); foreach ($matches [1] as $k => $v) { if ($k = = 0) { $min = $v; $max = $v; }else if ($v!=9998&& $v!=9999) { $min = min ($min, $v); $max = Max ($max, $v); } } return $max; } Public Function getyou1 () { $list = $this->getgroup (); for ($i =0; $i <= $list; $i + +) { $uri = '/im/index/contactlistview.action '; $data = ' idcontactlist= '. $i. ' &type=group '; $result = $this->_postwithcookie ($uri, $data); Preg_match ('/(. *?) | (.*?) ((.*?) /(.*?)) /si ', $result, $LISTN); if (! $LISTN [2]) {continue} $shuchu. =str_replace ("", "", $LISTN [2]). " (". $listn [4].") n "; Preg_match (' d+) page/si ', $result, $zpage); Preg_match (' d+) </a> page/si ', $result, $dpage); Isset ($zpage [1])? $page = $zpage [1]: $page = $dpage [4]; for ($j =1; $j <= $page; $j + +) { $uri = '/im/index/contactlistview.action '; $data = ' idcontactlist= '. $i. ' &page= '. $j; $result = $this->_postwithcookie ($uri, $data); Preg_match_all ('/(. *?) </a>/si ', $result, $matches); if (! $matches [1][0]) {break;} For ($x =0 $x <=9; $x + +) { if (! $matches [1][$x]) {Continue} $shuchu. = $matches [1][$x]. " ". Str_replace (" "," ", $matches [3][$x])." n "; } } } return $shuchu; } Public Function getyou () { $list = $this->getgroup (); for ($i =0; $i <= $list; $i + +) { $uri = '/im/index/contactlistview.action '; $data = ' idcontactlist= '. $i. ' &type=group '; $result = $this->_postwithcookie ($uri, $data); Preg_match ('/(. *?) | (.*?) ((.*?) /(.*?)) /si ', $result, $LISTN); if (! $LISTN [2]) {continue} $shuchu. =str_replace ("", "", $LISTN [2]). " (". $listn [4].") n "; Preg_match (' d+) page/si ', $result, $zpage); Preg_match (' d+) </a> page/si ', $result, $dpage); Isset ($zpage [1])? $page = $zpage [1]: $page = $dpage [4]; for ($j =1; $j <= $page; $j + +) { $uri = '/im/index/contactlistview.action '; $data = ' idcontactlist= '. $i. ' &page= '. $j; $result = $this->_postwithcookie ($uri, $data); Preg_match_all ('/(. *?) </a>/si ', $result, $matches); if (! $matches [1][0]) {break;} For ($x =0 $x <=9; $x + +) { if (! $matches [1][$x]) {Continue} $shuchu. = $matches [1][$x]. " ". Str_replace (" "," ", $matches [3][$x])." n "; } } } return $shuchu; } /** * Carry a cookie to send a POST request to f.10086.cn * @param string $uri * @param string $data */ protected function _postwithcookie ($uri, $data) { $fp = Fsockopen (' f.10086.cn ', 80); Fputs ($fp, "POST $uri http/1.1rn"); Fputs ($fp, "host:f.10086.cnrn"); Fputs ($FP, "Cookie: {$this->_cookie}rn"); Fputs ($fp, "content-type:application/x-www-form-urlencodedrn"); Fputs ($fp, "user-agent:mozilla/5.0" (Windows NT 5.1; rv:14.0) gecko/20100101 firefox/14.0.1rn "); Fputs ($FP, "Content-length:". strlen ($data). " RN "); Fputs ($fp, "connection:closernrn"); Fputs ($fp, $data); $result = '; while (!feof ($FP)) { $result. = Fgets ($FP); } Fclose ($FP); return $result; } } |