package demo.smgpdemo;
import java.util.*;
import java.sql.*;
import java.io.*;
import com.huawei.smproxy.SMGPSMProxy;
import com.huawei.smproxy.comm.smgp.*;
import com.huawei.smproxy.comm.smgp.message.*;
import com.huawei.smproxy.util.*;
public class SMReceiver extends SMGPSMProxy
implements Runnable{
//系统配置信息
private static Args arg = Env.getConfig().getArgs("SMGPConnect");
private static Thread instance;
public static Thread getInstance() {
if (instance == null) {
instance = new Thread(new SMReceiver());
}
return instance;
}
protected SMReceiver() {
super(SMReceiver.arg);
}
/**
* 连接终止的处理,由API使用者实现
* 短信中心连接终止后,需要执行动作的接口
*/
public void OnTerminate() {
System.out.println("Connection have been breaked! ");
}
/**
* 对SMGW主动下发的消息的处理接口。此例中只返回一个成功的响应。
* @param msg 收到的消息。
* @return 返回的相应消息。
*/
public SMGPMessage onDeliver(final SMGPDeliverMessage msg) {
if(msg.getIsReport() != 1){
System.out.println("\n**************************Received a new message!***************************");
System.out.println(msg.toString());
System.out.println("The Sender is: " + msg.getSrcTermID());
System.out.println("***************************End new message! **************************\n");
/*
String[] rcvMobile = new String[1];
rcvMobile[0] = msg.getSrcTermID();
//生成一个CNGP回复消息
System.out.print("Create new reply...\n");
CNGPSubmitMessage reply = new CNGPSubmitMessage(
"3001999995", //spid
1, //subtype
1, //needReport,
3, //priority
"+xkx", //serviceId
"01", //FeeType
0, //FeeUserType
"000000", //FeeCode
15, //msgFormat
null,
null, //定时发送时间(null:立即发送)
"94005", //srcTermId
"94005", //ChargeTermId
1, //destTermIdCount
rcvMobile, //destTermId
16, //msgLength
"你好,谢谢使用!", //msgmsgContent
0 //protocolValue
);
if (send(reply)) {
System.out.println("\nThe reply send OK!\n");
}
else {
System.out.println("\nThe reply send Fail!\n");
}
*/
}else{
System.out.println("\n++++++++++++++++++++++++++Received a new report!+++++++++++++++++++++++++");
System.out.println(msg.toString());
System.out.println("++++++++++++++++++++++++++End a new report!+++++++++++++++++++++++++\n");
}
return new SMGPDeliverRespMessage(msg.getMsgId(), 0);
}
/**
* 封装父类的send()方法
* 发送一条消息,完成真正的消息发送。
* @param msg 待发送的消息。
* @return true:发送成功。false:发送失败。
*/
/*
public boolean send(CNGPSubmitMessage msg) {
if (msg == null) {
return false;
}
CNGPSubmitRespMessage reportMsg = null;
PreparedStatement stat = null;
try {
reportMsg = (CNGPSubmitRespMessage)super.send(msg);
//System.out.println("发送状态: " + reportMsg.toString());
}
catch (IOException ex) {
ex.printStackTrace();
return false;
}catch (java.lang.NullPointerException e) {
return false;
}
return true;
}*/
public boolean send(SMGPSubmitMessage msg) {
if (msg == null) {
return false;
}
try{
super.send(msg);
}catch(IOException e){
}
return true;
}
public void run(){
while(true){
try {
Thread.sleep(500);
}
catch (Exception ex) {}
}
}
//测试用主函数
public static void main(String[] args) {
//生成100个接收短信的手机号码
//发送消息(发送多次)
Thread receiver = SMReceiver.getInstance();
receiver.start();
}
}
SMGP.rar_ISMP信息费_SMGP java_smgp_smgp3.0
版权申诉
87 浏览量
2022-09-14
16:02:43
上传
评论
收藏 64KB RAR 举报
alvarocfc
- 粉丝: 105
- 资源: 1万+
最新资源
- 4399GameSem_116_13955_207551_6.apk
- python 3.9.19源码编译包
- php-8.2.18-Win32-vs16-x64.rar
- 字节跳动青训营-抖音项目
- SQL资料手册,语句教程,高级查询语句语法
- 上位机和串口建立 Modbus 协议进行数据传输,并使用 Mysql 数据库存储,能够实现实时温湿度显示和动态变化曲线,历史数据
- Attachment 1_chazhi.xlsx
- 安卓项目,实现虚拟摇杆通过wifi串口发送nema-0183协议实现小吊舱方向控制
- 基于modbus协议的大屏数据监控,使用modbus slave模拟数据,串口服务器获取温湿度
- 下载资源.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0