62,614
社区成员
发帖
与我相关
我的任务
分享
public static ZxsSGIPSMProxy sgipProxy = null;
/**
* 用SGIP长连接发送联通短信
*
* @param mobile
* @param content
* @return 1提交短信失败 0提交短信成功
*/
private static int sendUnicomMsgBySGIP(String content, String mobile, String serviceCode) {
byte[] contentByte = null;
try {
contentByte = content.getBytes("GBK");// 统一处理为汉字
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return 1;
}
String[] mobiles = new String[] { mobile };
SGIPSubmitMessage msg = new SGIPSubmitMessage(serviceCode, // SPNumber
"000000000000000000000", // ChargeNumber
mobiles, // UserNumber
"99999", // CorpId
"SHGRP", // ServiceType
0, // 1, //FeeType
"0", // "100", //FeeValue
"0", // "100", //GivenValue
0, // AgentFlag
2, // 0, //MorelatetoMTFlag
0, // Priority
null, // ExpireTime
null, // ScheduleTime
1, // 3, //ReportFlag
0, // 1, //TP_pid
0, // 1, //TP_udhi
15, // MessageCoding(15为GBK编码;0为ASCII码;8为UCS2编码)
0, // MessageType
contentByte.length, // MessageLength
contentByte, // MessageContent
"" // reserve
);
SGIPMessage resp = null;
try {
log.debug("getConn: "+sgipProxy.getConn()+" ,getConnState: "+sgipProxy.getConnState()+" ,sgipProxy: "+sgipProxy);
resp = sgipProxy.send(msg);
log.debug(resp + ",=======time:" + msg.getTimeStamp()
+ ",srcnod:" + msg.getSrcNodeId() + "cmdId"
+ msg.getCommandId());
if(resp == null) {
log.error("联通提交短信失败111!!!!!!!!!!!!!!!!!!!!!!!!!!");
reConn();
return 1;
}
} catch (IOException e1) {
sgipProxy.close();
log.error("联通提交短信失败2222!!!!!!!!!!!!!!!!!!!!!!!!!!");
log.error(e1.getMessage());
log.error("尝试重新连接!!!!!!!!!!!!!!!!!!!!!!!!!!");
getInstance();
return 1;
}
return 0;
}
public static void getInstance() {
if(sgipProxy==null || sgipProxy.getConnState()!=null) {
try {
String accountId = Constant.SMS_CHINAUNICOM_ACCOUNTID; // 服务登录名
String password = Constant.SMS_CHINAUNICOM_PASSWORD; // 服务登录密码
log.debug("开始连接联通接口:>>>>>>>>>>>>>>>>>"+accountId+" "+" "+password);
SimpleDateFormat formatter = new java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
Args ag = null;
sgipProxy = null;
try {
log.debug("=======================11111aaaa========================");
ag = new Cfg(Constant.LTConfig, true).getArgs("SGIPConnect");
log.debug("=======================11111========================: "
+ ag.get("host", new String())
+ ag.get("port", new String())
+ ag.get("transaction-timeout", new String())
+ ag.get("read-timeout", new String())
+ ag.get("source-addr", new String())
+ ag.get("version", new String())
+ ag.get("sequence-number", new String())
+ ag.get("debug", new String()));
log.debug("=======================11111bbbb========================");
} catch (IOException e) {
log.error("读取配置文件失败!!!!!!!!!!!!!!!!!!!!!!!");
log.error(e.getMessage());
e.printStackTrace();
}
log.debug("=======================222222========================");
sgipProxy = new ZxsSGIPSMProxy(ag);
log.debug("=======================333333========================");
boolean isUnicomCon = sgipProxy.connect(accountId, password);
log.debug("=======================444444========================");
if (isUnicomCon)
log.debug("成功登陆时间:"
+ formatter.format(Calendar.getInstance().getTime()));
log.debug("=======================555555========================");
} catch (Exception e2) {
sgipProxy.close();
log.error("联通接口连接失败!!!!!!!!!!!!!!!!!!!!!!!");
log.error(e2.getMessage(),e2);
log.error(e2.getMessage());
e2.printStackTrace();
}
}
}
private static void reConn() {
try {
log.debug("=======================reConn========================");
sgipProxy.close();
String accountId = Constant.SMS_CHINAUNICOM_ACCOUNTID; // 服务登录名
String password = Constant.SMS_CHINAUNICOM_PASSWORD; // 服务登录密码
log.debug("开始连接联通接口:>>>>>>>>>>>>>>>>>"+accountId+" "+" "+password);
SimpleDateFormat formatter = new java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
Args ag = null;
sgipProxy = null;
try {
log.debug("=======================11111aaaa========================");
ag = new Cfg(Constant.LTConfig, true).getArgs("SGIPConnect");
log.debug("=======================11111========================: "
+ ag.get("host", new String())
+ ag.get("port", new String())
+ ag.get("transaction-timeout", new String())
+ ag.get("read-timeout", new String())
+ ag.get("source-addr", new String())
+ ag.get("version", new String())
+ ag.get("sequence-number", new String())
+ ag.get("debug", new String()));
log.debug("=======================11111bbbb========================");
} catch (IOException e) {
log.error("读取配置文件失败!!!!!!!!!!!!!!!!!!!!!!!");
log.error(e.getMessage());
e.printStackTrace();
}
log.debug("=======================222222========================");
sgipProxy = new ZxsSGIPSMProxy(ag);
log.debug("=======================333333========================");
boolean isUnicomCon = sgipProxy.connect(accountId, password);
log.debug("=======================444444========================");
if (isUnicomCon)
log.debug("成功登陆时间:"
+ formatter.format(Calendar.getInstance().getTime()));
log.debug("=======================555555========================");
} catch (Exception e2) {
sgipProxy.close();
log.error("联通接口连接失败!!!!!!!!!!!!!!!!!!!!!!!");
log.error(e2.getMessage(),e2);
log.error(e2.getMessage());
e2.printStackTrace();
}
}