• 博客访问: 491386
  • 博文数量: 126
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-05 11:19
个人简介

暂无介绍

文章分类

全部博文(126)

文章存档

2014年(6)

2013年(13)

2012年(10)

2011年(35)

2010年(48)

2007年(4)

2006年(2)

2005年(2)

2004年(6)

我的朋友

分类: 服务器/存储

2014-05-29 16:49:17

使用JAVA调用短信网关WebService


import java.text.SimpleDateFormat;
import org.apache.commons.lang.StringEscapeUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.PrintWriter;

public class AddSMSList {
       public static void main(String[] args) {
              try {
                     String endpoint = "http://10.1.0.128:8080/SMSG/services/SMS";
                     Service service = new Service();
                     Call call = (Call) service.createCall();
                     call.setTargetEndpointAddress(new java.net.URL(endpoint));
                     call.setOperationName(new QName(endpoint, "AddSMSList"));            
       call.addParameter("validation", org.apache.axis.encoding.XMLType.XSD_STRING,
                                   javax.xml.rpc.ParameterMode.IN);
                     call.addParameter("XML", org.apache.axis.encoding.XMLType.XSD_STRING,
                                   javax.xml.rpc.ParameterMode.IN);
       call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
                     String valid = "POWERU-SMS";

       SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSS");
       String dt = sdf.format(new Date());
       dt = dt.substring(0,16);
       dt = dt + "0";
       //System.out.println(dt);
   
       String ar = args[1];
       String content = StringEscapeUtils.escapeHtml(ar);
       //System.out.println(content);

       String xmlbody = "";  //短信接口格式
       //System.out.println(xmlbody);

       String result = (String)call.invoke(new Object[]{valid, xmlbody});
       System.out.println("result is "+result);

       File tofile=new File("/usr/local/nagios/var/sms.log"); 
       FileWriter fw=new FileWriter(tofile,true); 
       BufferedWriter bw=new BufferedWriter(fw); 
       PrintWriter pw=new PrintWriter(bw); 

       pw.println(dt + ":" + xmlbody + ":" + result);  //记录日志
       pw.close(); 
       bw.close(); 
       fw.close();
              }
              catch (Exception e) {
                     System.err.println(e.toString());
              }
       }
}


编译

javac -classpath .:./javaee.jar:./axis-1.4.jar:./commons-logging-1.1.1.jar:./commons-discovery-20040218.194635.jar:./wsdl4j-1.6.2.jar:./javax.activation.jar:./javax.mail-1.3.3.01.jar:./commons-lang-2.4.jar AddSMSList.java


发送脚本

sendSMS.sh

export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin

LOCAL_PATH=$(cd "$(dirname "$0")"; pwd)

java -classpath $LOCAL_PATH:$LOCAL_PATH/javaee.jar:$LOCAL_PATH/axis-1.4.jar:$LOCAL_PATH/commons-logging-1.1.1.jar:$LOCAL_PATH/commons-discovery-20040218.194635.jar:$LOCAL_PATH/wsdl4j-1.6.2.jar:$LOCAL_PATH/javax.activation.jar:$LOCAL_PATH/javax.mail-1.3.3.01.jar:$LOCAL_PATH/commons-lang-2.4.jar AddSMSList "$1" "$2"

阅读(3873) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chaoy2014-08-11 17:33:19

AddSMSList.java:11: cannot find symbol
symbol  : class Service
location: class AddSMSList
                     Service service = new Service();
                     ^
这是什么问题,我不动java,这样的错误共六个
AddSMSList.java:12: cannot find symbol
AddSMSList.java:14: cannot find&nbs

评论热议
请登录后评论。

登录 注册