今天就跟大家聊聊有关怎么在PHP项目中实现一个RTX发送消息提醒功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
1、首先在服务器端安装RTX的服务端和客户端,再安装SDK开发包
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);
看完上述内容,你们对怎么在PHP项目中实现一个RTX发送消息提醒功能有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。