BVB Source Codes

HP fetion automatic daily weather forecast v1.0 Show PHPFetion.php Source code

Return Download HP fetion automatic daily weather forecast v1.0: download PHPFetion.php Source code - Download HP fetion automatic daily weather forecast v1.0 Source code - Type:.php
  1. <?php
  2. /* *
  3.  * PHP飞信发送类
  4.  */
  5. class PHPFetion {
  6.        
  7.         /**
  8.          * 发送者手机号
  9.          * @var string
  10.          */
  11.         protected $_mobile;
  12.        
  13.         /**
  14.          * 飞信密码
  15.          * @param string
  16.          */
  17.         protected $_password;
  18.        
  19.         /**
  20.          * Cookie字符串
  21.          * @param string
  22.          */
  23.         protected $_cookie = '';
  24.        
  25.         /**
  26.          * 构造函数
  27.          * @param string $mobile 手机号(登录者)
  28.          * @param string $password 飞信密码
  29.          */
  30.         public function __construct($mobile, $password) {
  31.                 if($mobile === '' || $password === '') {
  32.                         return false;
  33.                 }
  34.                
  35.                 $this->_mobile = $mobile;
  36.                 $this->_password = $password;
  37.                
  38.                 $this->_login();
  39.         }
  40.        
  41.         /**
  42.          * 析构函数
  43.          */
  44.         public function __destruct() {
  45.                 $this->_logout();
  46.         }
  47.        
  48.         /**
  49.          * 登录
  50.          * @return string
  51.          */
  52.         protected function _login() {
  53.                 $uri = '/im/login/inputpasssubmit1.action';
  54.                 $data = 'm='.$this->_mobile.'&pass='.urlencode($this->_password).'&loginstatus=1';
  55.                
  56.                 $result = $this->_postWithCookie($uri, $data);
  57.                
  58.                 // 解析Cookie
  59.                 preg_match_all('/.*?\r\nSet-Cookie: (.*?);.*?/si', $result, $matches);
  60.                 if(isset($matches[1])) {
  61.                         $this->_cookie = implode('; ', $matches[1]);
  62.                 }
  63.  
  64.                 return $result;
  65.         }
  66.  
  67.         /**
  68.          * 向指定的手机号发送飞信
  69.          * @param string $mobile 手机号(接收者)
  70.          * @param string $message 短信内容
  71.          * @return string
  72.          */
  73.         public function send($mobile, $message) {
  74.                 if($message === '') {
  75.                         return '';
  76.                 }
  77.  
  78.                 // 判断是给自己发还是给好友发
  79.                 if($mobile == $this->_mobile) {
  80.                         return $this->_toMyself($message);
  81.                 } else {
  82.                         $uid = $this->_getUid($mobile);
  83.                         return $uid === '' ? '' : $this->_toUid($uid, $message);
  84.                 }
  85.         }
  86.  
  87.         /**
  88.          * 获取飞信ID
  89.          * @param string $mobile 手机号
  90.          * @return string
  91.          */
  92.         protected function _getUid($mobile) {
  93.                 $uri = '/im/index/searchOtherInfoList.action';
  94.                 $data = 'searchText='.$mobile;
  95.                
  96.                 $result = $this->_postWithCookie($uri, $data);
  97.                
  98.                 // 匹配
  99.                 preg_match('/toinputMsg\.action\?touserid=(\d+)/si', $result, $matches);
  100.                 if($matches[1]){return $matches[1];}else{die("fid not found");}
  101.                 //return isset($matches[1]) ? $matches[1] : '';
  102.         }
  103.        
  104.         /**
  105.          * 向好友发送飞信
  106.          * @param string $uid 飞信ID
  107.          * @param string $message 短信内容
  108.          * @return string
  109.          */
  110.         protected function _toUid($uid, $message) {
  111.                 $uri = '/im/chat/sendMsg.action?touserid='.$uid;
  112.                 $data = 'msg='.urlencode($message);
  113.                
  114.                 $result = $this->_postWithCookie($uri, $data);
  115.                 return "success";
  116.         }
  117.        
  118.         /**
  119.          * 给自己发飞信
  120.          * @param string $message
  121.          * @return string
  122.          */
  123.         protected function _toMyself($message) {
  124.                 $uri = '/im/user/sendMsgToMyselfs.action';
  125.                 $result = $this->_postWithCookie($uri, 'msg='.urlencode($message));
  126.                 return "success";
  127.         }
  128.        
  129.         /**
  130.          * 退出飞信
  131.          * @return string
  132.          */
  133.         protected function _logout() {
  134.                 $uri = '/im/index/logoutsubmit.action';
  135.                 $this->_postWithCookie($uri, '');
  136.                
  137.                 return $result;
  138.         }
  139.        
  140.         /**
  141.          * 携带Cookie向f.10086.cn发送POST请求
  142.          * @param string $uri
  143.          * @param string $uri
  144.          */
  145.         protected function _postWithCookie($uri, $data) {
  146.                 $fp = fsockopen('f.10086.cn', 80);
  147.                 fputs($fp, "POST $uri HTTP/1.1\r\n");
  148.                 fputs($fp, "Host: f.10086.cn\r\n");
  149.                 fputs($fp, "Cookie: {$this->_cookie}\r\n");
  150.                 fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
  151.                 fputs($fp, "Content-Length: ".strlen($data)."\r\n");
  152.                 fputs($fp, "Connection: close\r\n\r\n");
  153.                 fputs($fp, $data);
  154.  
  155.                 $result = '';
  156.                 while(!feof($fp)) {
  157.                         $result .= fgets($fp);
  158.                 }
  159.  
  160.                 fclose($fp);
  161.  
  162.                 return $result;
  163.         }
  164.  
  165. }
  166.  
downloadPHPFetion.php Source code - Download HP fetion automatic daily weather forecast v1.0 Source code
Related Source Codes/Software:
Project management software KisProject v1.0.3 - Kis (Keep it simple) is a free WEB-based team coll... 2016-10-23
MyProber PHP 0.26 a probe - MyProber v0.26 2016-10-23
Food science and technology chain edition v1.1 online reservation system - Treat chain version of the main functions of the o... 2016-10-23
Emlog for SAE v4.2.1 - Emlog for SAE is suitable for SAE emlog used modif... 2016-10-23
Easy website system v2.0 - Business easy built station system (Sunnyi Website... 2016-10-23
Valley dad imitate homepage search - Modified more concise and convenient, but there is... 2016-10-23
hpMyAdmin v3.4.11 For Linux - HpMyAdmin is a PHP based, architecture in Web - Ba... 2016-10-23
V1.4 jmapcms website development system - 1. Modify the CHKJS file loading animation has alw... 2016-10-23
More than the V6.2 taobao guest program - Amoy Taobao V6.2 for short procedures, adopted a P... 2016-10-23
According to the IP to identify local weather forecast - According to the visitor IP to the database to ext... 2016-10-23
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top