發送短信

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章