CGI方式发送RTX消息

      在上一遍中讲到,用java调用RTX的API实现发送消息的功能。经测试在Windows平台下tomcat上面是没问题的,可以实现想要的功能;但将代码部署至Linxu平台WAS下就行不通咯。因为这样写的代码是不能实现跨平台操作的,可我现在做的这个项目恰好是要发布在Linux平台中的WAS服务器上,所以之前的代码又得重新编写:

      要实现通过代码跨平台发送RTX消息可有以下两种方式:

      1、写一个中转程序,就是将写好的java调用代码封装成一个web应用程序。

      2、改用CGI方式发送RTX消息。

      我采用的是第二种方式,下面就为大家介绍下本人的操作过程:

第一步:RTX服务端IP授权

     1.用记事本打开System32下的rtxServerApi.ini文件,把Host改为RTX服务器的IP地址。

    2.进入RTX服务器安装目录../RTXServer下,用记事本打开SDKPorperty.xml文件,在里面增加开发机器地址(如下图所示),保存后重启RTX服务。

 

             

第二步:实现代码:

View Code
/**
*
*
@param rtxb RTX消息实体
*
@return 成功能失败标示
* 2012-2-6 chengxingxin
*/

public static int CgiSendNotice(RtxSendNoticeBean rtxb){

String sendImg = "/SendNotify.cgi?" ; // RTX发送消息接口

StringBuffer sendMsgParams = new StringBuffer(sendImg);

int tag=1;

sendMsgParams.append( "&receiver=" + rtxb.getRecivers().toString());
try {
if(rtxb.getContent() !=null ){
sendMsgParams.append( "&msg=" + URLEncoder.encode(rtxb.getContent(),"gbk"));
if (rtxb.getTitle() != null ) {
sendMsgParams.append( "&title=" + URLEncoder.encode(rtxb.getTitle(),"gbk"));
}
}
URL url = new URL( "HTTP" , rtxb.getServerip(), rtxb.getServerprot(), sendMsgParams.toString());
HttpURLConnection httpconn = (HttpURLConnection) url.openConnection();

BufferedReader in = new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println("======sendnotifyCgi========"+line);
//tag=Integer.parseInt(line);
}
in.close();

httpconn.disconnect();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tag=0;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tag=0;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tag=0;
}
return tag;
}

第三步:如果RTX账号中有纯数字账号还得做以下操作,不能数字账号还是不行

     找到RTXServer的安装目录..\Tencent\RTXServer\WebRoot\SendNotify.cgi红色部分为添加内容)

<?PHP
........
$Name = "ExtTools";
$ObjApi->Name = $Name;
$objProp->Add("UINTYPE", "Account"); //允许操作纯数字账号
$objProp->Add("msgInfo", $msg);
.............
?>


有兴趣的或正在开发此功能的朋友可以去实下,希望对你有所帮助.....




 

posted @ 2012-02-06 23:41  跳动的音符^Web  阅读(2138)  评论(1编辑  收藏  举报