class PHPFetion { protected $_mobile; protected $_password; protected $_cookie = ''; protected $_uids = array(); protected $_csrfToten = null; public function __construct($mobile, $password) { if ($mobile === '' || $password === '') { return; } $this->_mobile = $mobile; $this->_password = $password; $this->_login(); } public function __destruct() { $this->_logout(); } 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); preg_match_all('/.*?\r\nSet-Cookie: (.*?);.*?/si', $result, $matches); if (isset($matches[1])) { $this->_cookie = implode('; ', $matches[1]); } $result = $this->_postWithCookie('/im/login/cklogin.action', ''); return $result; } public function send($mobile, $message) { if ($message === '') { return ''; } if ($mobile == $this->_mobile) { return $this->_toMyself($message); } else { $uid = $this->_getUid($mobile); return $uid === '' ? '' : $this->_toUid($uid, $message); } } protected function _getUid($mobile) { if (empty($this->_uids[$mobile])) { $uri = '/im/index/searchOtherInfoList.action'; $data = 'searchText='.$mobile; $result = $this->_postWithCookie($uri, $data); //匹配 preg_match('/toinputMsg\.action\?touserid=(\d+)/si', $result, $matches); $this->_uids[$mobile] = isset($matches[1]) ? $matches[1] : ''; } return $this->_uids[$mobile]; } 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; } 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; } protected function _toMyself($message) { $uri = '/im/user/sendMsgToMyselfs.action'; $result = $this->_postWithCookie($uri, 'msg='.urlencode($message)); return $result; } protected function _logout() { $uri = '/im/index/logoutsubmit.action'; $result = $this->_postWithCookie($uri, ''); return $result; } protected function _postWithCookie($uri, $data) { $fp = fsockopen('f.10086.cn', 80); fputs($fp, "POST $uri HTTP/1.1\r\n"); fputs($fp, "Host: f.10086.cn\r\n"); fputs($fp, "Cookie: {$this->_cookie}\r\n"); fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($fp, "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1\r\n"); fputs($fp, "Content-Length: ".strlen($data)."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = ''; while (!feof($fp)) { $result .= fgets($fp); } fclose($fp); return $result; } } function curl($url, $postFields = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } if (is_array($postFields) && 0 < count($postFields)) { $postBodyString = ""; $postMultipart = false; foreach ($postFields as $k => $v) { if("@" != substr($v, 0, 1)) { $postBodyString .= "$k=" . urlencode($v) . "&"; } else { $postMultipart = true; } } unset($k, $v); curl_setopt($ch, CURLOPT_POST, true); if ($postMultipart) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); } else { curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1)); } } $reponse = curl_exec($ch); if (curl_errno($ch)) { throw new Exception(curl_error($ch),0); } else { $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (200 !== $httpStatusCode) { throw new Exception($reponse,$httpStatusCode); } } curl_close($ch); return $reponse; } function object_to_array($obj) { $_arr = is_object($obj) ? get_object_vars($obj) : $obj; foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val; $arr[$key] = $val; } return $arr; }
以上就是模拟飞信fetion发送类[直接调用官方]的内容,更多相关内容请关注PHP中文网(www.php.cn)!
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
1 週前ByDDD
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
在哪裡可以找到原子中的起重機控制鑰匙卡
1 週前ByDDD

熱工具

WebStorm Mac版
好用的JavaScript開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver CS6
視覺化網頁開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。