php代码
<?php /** * 用Socket向DDpush服务器发送消息 * * @author Wang Wenbing<binny_w@qq.com> */ class DDpusher { /* Socket resource */ private $socket = null; /** * 构造函数 * @param string $strHost * @param int $intPort * @throws Exception */ public function __construct($strHost, $intPort = 9999) { $strHost = strval($strHost); $intPort = intval($intPort); if (empty($strHost) || !$intPort) { throw new Exception('Wrong strHost or Wrong intPort'); } elseif (($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { throw new Exception('Error at socket_create(): ' . socket_strerror(socket_last_error())); } elseif (socket_connect($this->socket, $strHost, $intPort) === false) { throw new Exception('Error at socket_connect(): ' . socket_strerror(socket_last_error())); } } /** * 生成32位的UUID,可以重写此函数 * @param string $strUser * @return string(32) */ private function getUUID($strUser) { $strUser = trim($strUser); return strlen($strUser) ? md5($strUser) : false; } /** * 检查Version和Appid参数 * @param int $intVersion * @param int $intAppid * @return boolen */ private function checkVersionAndAppid($intVersion, $intAppid) { return ($intVersion > 0 && $intVersion < 256 && $intAppid > 0 && $intAppid < 256); } /** * 发送通知 * @param string $strUser * @return boolean $blnRe */ public function push0x10($strUser, $intVersion = 1, $intAppid = 1) { $blnRe = false; $intVersion = intval($intVersion); $intAppid = intval($intAppid); if ($this->checkVersionAndAppid($intVersion, $intAppid) && ($strUUID = $this->getUUID($strUser)) !== false && $this->socket) { $strBin = pack('CCCH32n', $intVersion, $intAppid, 16, $strUUID, 0); socket_write($this->socket, $strBin, strlen($strBin)) && $blnRe = (bindec(socket_read($this->socket, 1)) == 0); } else { throw new Exception('Error at push0x10()'); } return $blnRe; } /** * 发送分类信息 * @param string $strUser * @param string $strHex 16位长的16进制字符 * @param int $intVersion * @param int $intAppid * @return boolen $blnRe */ public function push0x11($strUser, $strHex, $intVersion = 1, $intAppid = 1) { $blnRe = false; $intVersion = intval($intVersion); $intAppid = intval($intAppid); $strHex = trim($strHex); if ($this->checkVersionAndAppid($intVersion, $intAppid) && ($strUUID = $this->getUUID($strUser)) !== false && $this->socket && strlen($strHex) == 16) { $strBin = pack('CCCH32nH16', $intVersion, $intAppid, 17, $strUUID, 8, $strHex); socket_write($this->socket, $strBin, strlen($strBin)) && $blnRe = (bindec(socket_read($this->socket, 1)) == 0); } else { throw new Exception('Error at push0x11()'); } return $blnRe; } /** * 发送500字节以内的字符消息 * @param string $strUser * @param string $strMsg 必须是utf8编码的字符 * @param int $intVersion * @param int $intAppid * @return boolen $blnRe * @throws Exception */ public function push0x20($strUser, $strMsg, $intVersion = 1, $intAppid = 1) { $blnRe = false; $intVersion = intval($intVersion); $intAppid = intval($intAppid); // $strMsg = mb_convert_encoding($strMsg, 'utf8', 'gbk'); $strMsg = trim($strMsg); $intLen = strlen($strMsg); $blnTemp = ($intLen > 0 && $intLen <= 500); if ($this->checkVersionAndAppid($intVersion, $intAppid) && ($strUUID = $this->getUUID($strUser)) !== false && $this->socket && $blnTemp) { $strBin = pack('CCCH32nA' . $intLen, $intVersion, $intAppid, 32, $strUUID, $intLen, $strMsg); socket_write($this->socket, $strBin, strlen($strBin)) && $blnRe = (bindec(socket_read($this->socket, 1)) == 0); } else { throw new Exception('Error at push0x20()'); } return $blnRe; } /** * 断开连接 */ public function __destruct() { if ($this->socket) { socket_close($this->socket); $this->socket = null; } } } /** * 使用Demo */ try { $obj = new DDpusher('172.16.14.7'); $obj->push0x10('user01') && print('通知已发送<br />'); $obj->push0x11('user01', '0000000000000001') && print('分类已发送<br />'); $obj->push0x20('user01', '我爱你DDpush') && print('字符串消息已发送<br />'); } catch (Exception $ex) { echo $ex->getMessage(); }
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
刺客信條陰影:貝殼謎語解決方案
4 週前ByDDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
3 週前ByDDD
在哪裡可以找到原子中的起重機控制鑰匙卡
4 週前ByDDD
<🎜>:死鐵路 - 如何完成所有挑戰
1 個月前ByDDD
Atomfall指南:項目位置,任務指南和技巧
1 個月前ByDDD

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

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

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中