发送短信

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;
		}
	  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值