日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php提交飞信,php发送飞信消息

發布時間:2024/7/19 php 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php提交飞信,php发送飞信消息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實例結構:

1. demo.php

// 獲取天氣數據

$w = json_decode( file_get_contents(‘http://www.weather.com.cn/data/cityinfo/101280601.html‘) ) ;

$wi = $w->weatherinfo;

$str = "【{$wi->city}】".date(‘Y-m-d‘).‘ 天氣: ‘;

$str.= "{$wi->weather}, {$wi->temp1}-{$wi->temp2}";

// 開始發送飛信

require_once(‘PHPFetion.class.php‘);

header ( "Content-Type:text/html; charset=utf-8" );

$fetion = new PHPFetion(‘18898927320‘, ‘c*****00‘);

$rs = $fetion->send(‘18898927320‘, $str);

if(strpos($rs,‘200‘)){

echo ‘發送成功‘;

}else{

echo ‘發送失敗‘;

}

2. ?PHPFetion.class.php

/**

* PHP飛信發送類

*

* @author quanhengzhuang

* @version 1.5.0

*/

class PHPFetion

{

/**

* 發送者手機號

* @var string

*/

protected $_mobile;

/**

* 飛信密碼

* @var string

*/

protected $_password;

/**

* Cookie字符串

* @var string

*/

protected $_cookie = ‘‘;

/**

* Uid緩存

* @var array

*/

protected $_uids = array();

/**

* csrfToken

* @var string

*/

protected $_csrfToten = null;

/**

* 構造函數

* @param string $mobile 手機號(登錄者)

* @param string $password 飛信密碼

*/

public function __construct($mobile, $password)

{

if ($mobile === ‘‘ || $password === ‘‘)

{

return;

}

$this->_mobile = $mobile;

$this->_password = $password;

$this->_login();

}

/**

* 析構函數

*/

public function __destruct()

{

$this->_logout();

}

/**

* 登錄

* @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);

//解析Cookie

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;

}

/**

* 向指定的手機號發送飛信

* @param string $mobile 手機號(接收者)

* @param string $message 短信內容

* @return string

*/

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);

}

}

/**

* 獲取飛信ID

* @param string $mobile 手機號

* @return string

*/

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];

}

/**

* 獲取csrfToken,給好友發飛信時需要這個字段

* @param string $uid 飛信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;

}

/**

* 向好友發送飛信

* @param string $uid 飛信ID

* @param string $message 短信內容

* @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;

}

/**

* 給自己發飛信

* @param string $message

* @return string

*/

protected function _toMyself($message)

{

$uri = ‘/im/user/sendMsgToMyselfs.action‘;

$result = $this->_postWithCookie($uri, ‘msg=‘.urlencode($message));

return $result;

}

/**

* 退出飛信

* @return string

*/

protected function _logout()

{

$uri = ‘/im/index/logoutsubmit.action‘;

$result = $this->_postWithCookie($uri, ‘‘);

return $result;

}

/**

* 攜帶Cookie向f.10086.cn發送POST請求

* @param string $uri

* @param string $data

*/

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;

}

}

;

總結

以上是生活随笔為你收集整理的php提交飞信,php发送飞信消息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。