首先安装RTX的服务器端与客户端。具体安装请参考RTX官方网站的文档。
第一种方式使用RTX官方提供的API调用发送消息的接口。
public static void main(String[] args) {
RTXSvrApi RtxsvrapiObj = new RTXSvrApi();
RtxsvrapiObj.setServerPort(6000);
String receivers = "woailuo";
String title = "RTX测试";
String msg = "腾讯|http://www.qq.com";
String delayTime = "0";
String urlid = "";
String msgid = "";
int iRet = -1;
System.out.println(RtxsvrapiObj.Init());
if( RtxsvrapiObj.Init())
{
iRet = RtxsvrapiObj.sendNotify(receivers, title, msg, urlid, msgid,
delayTime);
if (iRet == 0)
{
System.out.println("发送成功");
}
else
{
System.out.println("发送失败");
}
}
RtxsvrapiObj.UnInit();
}
第二种通过调用RTX服务器CGI的方式实现。
public static void main(String[] args) throws IOException {
String sendImg = "/SendNotify.cgi?"; // RTX发送消息接口
String host = "127.0.0.1"; // RTX服务器地址
String getSessionkey = "/getsessionkey.cgi?"; // RTX获取会话接口
int port = 8012; // RTX服务器监听端口
String[] receiverss = { "woailuo" }; // 接收人,RTX帐号
String sender = "zilaiye"; // 发送人
String content = "[RTX培训|www.qq.com]"; // 内容
StringBuffer sendMsgParams = new StringBuffer(sendImg);
StringBuffer receiveUrlStr = new StringBuffer();
for (int i = 0; i < receiverss.length; ++i) {
if (receiveUrlStr.length() == 0) {
receiveUrlStr.append(receiverss[i]);
} else {
receiveUrlStr.append("," + receiverss[i]);
}
}
sendMsgParams.append("&receiver=" + receiveUrlStr);
if (content != null){
sendMsgParams.append("&msg=" + new String(content.getBytes("utf-8"), "utf-8"));
}
if (sender != null) {
sendMsgParams.append("&sender=" + sender);
}
URL url = new URL("HTTP", host, port, sendMsgParams.toString());
HttpURLConnection httpconn = (HttpURLConnection) url.openConnection();
String ret = httpconn.getHeaderField(3);
}