RTX是騰訊公司推出的企業級即時通信平台,大多數公司都在使用它,但是我們很多時候需要將自己系統或者產品的一些通知實時推送給RTX,這就需要用到RTX的服務端SDK,建議先去看看RTX的SDK開發文檔(客戶端,服務器),我們先看看功能效果:
當然,現在很多公司都已經在RTX的基礎上升級成了企業微信,沒關系,這個API同樣可以使用,還是同樣的接口,只是展示效果不一樣而已:
下面是用PHP實現RTX發送消息提醒:
1、首先在服務器端安裝RTX的服務端和客戶端,再安裝SDK開發包(對於發送消息提醒的功能,只需要安裝服務端sdk即可)(下載地址:http://rtx.tencent.com/rtx/download/index.shtml)
2、然後再RTX服務器的安裝路徑下有個WebRoot文件夾,文件夾下有個SendNotify.cgi文件,這就是RTX發送消息的接口文件,打開文件是懂PHP的都能看懂的代碼,不過需要在頭部加入header頭,以及需要處理一些參數的編碼
header("Content-Type:text/html;charset=GBK"); $msg = iconv("utf-", "GBK", $msg); $title = iconv("utf-", "GBK", $title);
如果你的所有安裝都是在本地的,那麼只需要訪問(默認端口8012)即可:
http://127.0.0.1:8012/SendNotify.cgi?msg=消息內容&receiver=RTX的賬號(多個用逗號格開)&title=通知的標題
以下是修改後的SendNotify.cgi代碼:
<?php /** * Created by PhpStorm. * User: Steven * Date: // * Time: : */ header("Content-Type:text/html;charset=GBK"); require_once "IPLimit.php"; $receiver = $_GET["receiver"]; $msg = $_GET["msg"]; $title = $_GET["title"]; $delaytime = $_GET["delaytime"]; $okurl = $_GET["okurl"]; $errurl = $_GET["errurl"]; if ((strlen($receiver) == ) && (strlen($msg) == ) && (strlen($title) == ) && (strlen($delaytime) == ) && (strlen($okurl) == ) && (strlen($errurl) == ) ) { $receiver = $_POST["receiver"]; $msg = $_POST["msg"]; $title = $_POST["title"]; $delaytime = $_POST["delaytime"]; $okurl = $_POST["okurl"]; $errurl = $_POST["errurl"]; } if (strlen($receiver) == ) { $receiver = ""; } if (strlen($msg) == ) { $msg = ""; } if (strlen($title) == ) { $title = ""; } if (strlen($delaytime) == ) { $delaytime = ; } if (strlen($okurl) == ) { $okurl = ""; } if (strlen($errurl) == ) { $errurl = ""; } $msg = iconv("utf-", "GBK", $msg); $title = iconv("utf-", "GBK", $title); $php_errormsg = NULL; $ObjApi = new COM("Rtxserver.rtxobj"); $objProp = new COM("Rtxserver.collection"); $Name = "ExtTools"; $ObjApi->Name = $Name; $objProp->Add("msgInfo", $msg); $objProp->Add("MsgID", ""); $objProp->Add("Type", ""); $objProp->Add("AssType", ""); if (strlen($title) == ) { $objProp->Add("Title", "֪ͨ"); } else { $objProp->Add("Title", $title); } $objProp->Add("DelayTime", $delaytime); if (strtolower($receiver) == "all") { $objProp->Add("Username", $receiver); $objProp->Add("SendMode", ""); } else { $objProp->Add("Username", $receiver); } $Result = @$ObjApi->Call(x, $objProp); $errstr = $php_errormsg; if (strcmp($nullstr, $errstr) == ) { if (strlen($okurl) > ) { header("Location: " . $okurl); } else { // echo "<script language=\"JavaScript\">\r\n"; // echo "alert(\"success\")"; //echo "</script>\r\n"; return true; } } else { //send err if (strlen($errurl) > ) { header("Location: " . $errurl); } else { echo $errstr . "<br>"; } } ?>
3、需要注意的是代碼中引入了IPLimit.php文件,所以,訪問的時候可能會提示IP受限,這就需要在RTX服務端安裝文件下找到一個叫SDKProperty.xml的文件,加入你發送請求的服務器IP保存即可
<?xml version="."?> <Property> <APIClient> <IPLimit Enabled=""> <IP>...</IP> <IP>這裡是IP地址</IP> </IPLimit> </APIClient> <sdkhttp> <IPLimit Enabled=""> </IPLimit> </sdkhttp> </Property>
4、開發者只需要封裝一個發送GET或者POST的方法,例如:
$arr = array( 'title' => $title, //消息的標題 'receiver' => $receiver_list, //消息的接受者 'msg' => $msg, //消息內容 ); $this->httpsPost('http://...:/SendNotify.cgi', $arr);
即可向RTX發送消息通知,以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持幫客之家。