public class MySendAnMessage{
private static String mCurrentDate = PubFun.getCurrentDate();
//private static String mCurrentTime = PubFun.getCurrentTime();
public boolean sendMessage(String xiaoxi,String warncode,String n) {
String mXMLToString;
Element tRoot,tSubRoot, tMessage, tReceiver, tContents;
Document tDocument;
// 首先建立根元素
tRoot = new Element("Messages");
tDocument = new Document(tRoot);
//--机构代码
tSubRoot = new Element("Organization");
//tSubRoot.setText("106");
tSubRoot.setText("63");
tRoot.addContent(tSubRoot);
//--机构名称
tSubRoot = new Element("ServiceType");
//tSubRoot.setText("监控平台");
tSubRoot.setText("系统监控");
tRoot.addContent(tSubRoot);
//--是否使用扩展尾号
tSubRoot = new Element("Extension");
tSubRoot.setText("true");
tRoot.addContent(tSubRoot);
//--开始日期
tSubRoot = new Element("StartDate");
tSubRoot.setText(mCurrentDate);
tRoot.addContent(tSubRoot);
//--结束日期
tSubRoot = new Element("EndDate");
tSubRoot.setText(PubFun.calDate(mCurrentDate, 1, "D", ""));
tRoot.addContent(tSubRoot);
//--开始时间
tSubRoot = new Element("StartTime");
tSubRoot.setText("00:00:00");
tRoot.addContent(tSubRoot);
//--结束时间
tSubRoot = new Element("EndTime");
tSubRoot.setText("23:59:59");
tRoot.addContent(tSubRoot);
ExeSQL texeSQL = new ExeSQL();
String sql = "select phonenum from EmailPlan where warnnames='"+n+"' and warncode='"+warncode+"'";
SSRS ssrs = texeSQL.execSQL(sql);
//循环收件人列表,依次发送消息集
for (int i = 1; i <=ssrs.getMaxRow(); i++) {
String recive=ssrs.GetText(i, 1);
String[] recivef=recive.split(";");
//收信人截取
for (int m=0;m<recivef.length;m++){
System.out.println(recivef[m]);
//--短息节点--一个号码对应一个message节点
tMessage=new Element("Message");
tRoot.addContent(tMessage);
//--接收人
tReceiver=new Element("Receiver");
tReceiver.setText(recivef[m]);
//--短信内容
tContents=new Element("Contents");
tContents.setText(xiaoxi);
tMessage.addContent(tReceiver);
tMessage.addContent(tContents);
}
}
// xml导出对象
XMLOutputter tXMLOutputter = new XMLOutputter();
OutputStream tOutputStream = new ByteArrayOutputStream();
try {
//tXMLOutputter.setEncoding("UTF-8");//216和228上的编码
tXMLOutputter.setEncoding("GBK");//本地编码
tXMLOutputter.setTrimText(true);
tXMLOutputter.setIndent(" ");// 调整输出xml的缩进值
tXMLOutputter.setExpandEmptyElements(true);// 是否扩展空值标签
tXMLOutputter.setNewlines(true);// 是否分行输出
tXMLOutputter.output(tDocument, tOutputStream);
mXMLToString = tOutputStream.toString();
System.out.println(mXMLToString);
//短信测试环境
//String wsdl ="http://******";
//短信生产环境
String wsdl ="http://******";
Options opts = new Options(null);
opts.setDefaultURL(wsdl);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(opts.getURL()));
//执行发送短信
//call.invoke("sendSMS", new Object[]{"jkpt","jkpt","106",mXMLToString});
call.invoke("sendSMS", new Object[]{"xitongjk","xitongjk","63",mXMLToString});
System.out.println("短信发送执行结束...");
} catch (Exception e) {
System.out.println("短信发送失败。。。。。。。");
e.printStackTrace();
return false;
}
return true;
}
}
发送短信
最新推荐文章于 2021-02-13 12:23:58 发布