📄 sgipdemo.java
字号:
jScrollPane1.getViewport().add(allRecvContent, null);
this.getContentPane().add(RecvMsgSum, null);
this.getContentPane().add(jLabel15, null);
this.getContentPane().add(jLabel16, null);
this.getContentPane().add(SuccessSendSum, null);
this.getContentPane().add(SendMsgSum, null);
this.getContentPane().add(jLabel17, null);
this.getContentPane().add(myProxyState, null);
this.getContentPane().add(jLabel22, null);
this.getContentPane().add(dest_Terminal_Id, null);
this.getContentPane().add(src_Terminal_Id, null);
this.getContentPane().add(jLabel6, null);
this.getContentPane().add(jLabel5, null);
this.getContentPane().add(msg_Content, null);
this.getContentPane().add(jLabel7, null);
this.getContentPane().add(SendButton, null);
this.getContentPane().add(loginbutton, null);
this.getContentPane().add(jLabel4, null);
this.getContentPane().add(initbutton, null);
this.getContentPane().add(stopbutton, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(calledFrom, null);
this.getContentPane().add(jLabel18, null);
this.getContentPane().add(calledTo, null);
}
/**
* 处理用户发送短消息的测试请求.
*/
void SendButton_actionPerformed(ActionEvent e)
{
int threadNum = 0;
int runInterval = 0;
int sleepInterval = 0;
//如果没有成成功登录
if(!loginSmProxy)
{
return ;
}
try
{
threadNum= Integer.parseInt(ThreadNum.getText().trim());
runInterval = Integer.parseInt(threadRunInterval.getText().trim());
sleepInterval = Integer.parseInt(threadSleepInterval.getText().trim());
cmppSubmitFrom = Integer.parseInt(calledFrom.getText().trim());
cmppSubmitTo = Integer.parseInt(calledTo.getText().trim());
calledIndex = cmppSubmitFrom;
//begin
msgContent = msg_Content.getText().trim().getBytes();
//end
}
catch(Exception ex) //such as 用户没有输入线程数或者是其他非法字符的时候
{ //我们只发送短消息,而不启动线程
threadNum =0;
runInterval = 0;
}
//对输入的参数做有效性判断
if((threadNum>0)&&(runInterval>0))
{
//submitMsg = getSubmitMsg();
StartSendThread(threadNum,runInterval,sleepInterval);
}
else
{
try
{
sendMsgSum ++;
ProcessSubmitRep(smp.send(getSubmitMsg(0)));
}
catch(IllegalArgumentException ex)
{
//add
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
/* if(smp!=null)
{
try
{
smp.close();
smp = null;
loginSmProxy = false;
showStateMsg("断开连接");
}
catch(Exception ex)
{
ex.printStackTrace();
showStateMsg("与SMG断连出现异常");
}
}*/
}
/**
*登陆到SMG
*/
void loginbutton_actionPerformed(ActionEvent e)
{
boolean result = smp.connect(loginName.getText(), loginPass.getText());
if ( result ) {
showStateMsg("登陆成功");
}
else {
showStateMsg("登陆失败");
}
}
/**
* 断开与SMG的连接
*/
void logoutbutton_actionPerformed(ActionEvent e)
{
if(smp!=null)
{
smp.close();
}
}
/**
* 处理用户的退出请求
*/
void ExitButton_actionPerformed(ActionEvent e)
{
//如果没有成成功登录
if(!loginSmProxy)
{
showStateMsg("系统没有成功登录");
return ;
}
if(smp!=null)
{
try
{
smp.close();
}
catch(Exception ex)
{
ex.printStackTrace();
showStateMsg("与ISMG断连出现异常");
}
}
}
/**
* 根据用户输入的消息生成SubmitMsg
* @return CMPPSubmitMessage 对象
*/
private SGIPSubmitMessage getSubmitMsg(int index)
{
/*
String serviceId = service_Id.getText().trim();
String feeTerminalId = fee_Terminal_Id.getText().trim();
String msgSrc = msg_src.getText().trim();
//测试中不做处理,原来C版的Demo中是空字符串
Date valid_Time = null;//new Date();
Date at_Time = null;//new Date();
String srcTerminalId = src_Terminal_Id.getText().trim();
String destTerminalId [] = new String[1];
destTerminalId[0] = dest_Terminal_Id.getText().trim();
byte[] msgContent = msg_Content.getText().trim().getBytes();
*/
if(calledIndex<cmppSubmitTo)
{
calledIndex++;
}
else
{
calledIndex = cmppSubmitFrom;
}
UserNumber[0] = "130123456";
try
{
return new SGIPSubmitMessage(
"302",
"000000000000000000000",
UserNumber,
"22222",
"test",
1,
"100",
"100",
0,
0,
0,
null,
null,
3, //ReportFlag
1,
1,
0,
0,
msgContent.length,
msgContent,
"");
}
catch(IllegalArgumentException e)
{
showStateMsg("提交短消息请求的输入参数不合法");
e.printStackTrace();
return null;
}
catch(Exception e)
{
showStateMsg("提交短消息请求处理异常");
e.printStackTrace();
return null;
}
}
/**
* 对提交请求后收到的响应消息进行处理。
* @param msg 提交短消息请求后收到的响应消息
* @return 返回处理CMPP_Submit_REP的操作结果
*/
private void ProcessSubmitRep(SGIPMessage msg)
{
//收到的响应消息转换成repMsg
SGIPSubmitRepMessage repMsg = (SGIPSubmitRepMessage)msg;
if(repMsg!=null && repMsg.getResult()==0)
{
sendSuccessMsgSum ++;
}
}
/**
* 对收到短讯中心下发的短消息的处理。
* @param msg 短讯中心下发的短消息
*/
public void ProcessRecvDeliverMsg(SGIPMessage msg)
{
SGIPDeliverMessage deliverMsg = (SGIPDeliverMessage)msg;
showStateMsg(deliverMsg.toString());
//下发的消息
recvDeliverMsgSum++;
}
/**
* 通知SMC下发的Terminate消息
*/
public void Terminate()
{
showStateMsg("SMC下发终断消息");
loginSmProxy = false;
smp = null;
}
/**
* 显示SmProxy运行程序的状态
* @str 显示的内容
*/
private void showStateMsg(String str)
{
if((str==null)||(str==""))
{
return ;
}
allRecvContent.insert(sdf.format(new Date())+str+"\n",0);
//防止内存耗尽
if (allRecvContent.getText().length()>2*1024)
{
allRecvContent.setText(allRecvContent.getText().substring(0,1024));
}
allRecvContent.setCaretPosition(0);
}
/**
*显示统计消息
*/
private void showStatisticData()
{
SendMsgSum.setText(new Integer(sendMsgSum).toString());
SuccessSendSum.setText(new Integer(sendSuccessMsgSum).toString());
RecvMsgSum.setText(new Integer(recvDeliverMsgSum).toString());
}
/**
* 检查系统连接状态消息
*/
class MoniterThread extends Thread
{
public MoniterThread()
{
setDaemon(true);
}
public void run()
{
String connState=null;
try
{
while(smp != null)
{
connState = smp.getConnState();
showStatisticData();
if(connState==null) connState = "系统运行正常";
myProxyState.setText(connState);
//一秒钟检查10次
sleep(100);
}
}
catch(Exception e)
{
showStateMsg("状态监控线程出现异常退出");
e.printStackTrace();
}
}
}
/**
* 使用SmProxy应用程序,必须登录系统
*/
void initbutton_actionPerformed(ActionEvent e)
{
//判断系统是否已经初始化了
if(loginSmProxy)
{
showStateMsg("系统已经初始化");
return ;
}
try
{
args.set("login-name",loginName.getText().trim());
args.set("login-pass",loginPass.getText().trim());
showStateMsg("系统正在初始化");
smp = new MySGIPSMProxy(this,args);
showStateMsg("系统初始化成功");
loginSmProxy = true;
new MoniterThread().start();
}
catch(Exception ex)
{
showStateMsg("系统初始化失败");
this.myProxyState.setText(ex.getMessage());
ex.printStackTrace();
loginSmProxy = false;
}
}
/**
* 关闭监听端口
*/
void stopbutton_actionPerformed(ActionEvent e)
{
try
{
smp.stopService();
}
catch(Exception ex)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -