pom导包
<!-- axis 1.4 jar start -->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.4</version>
</dependency>
<!-- axis 1.4 jar end -->
下面是一个调用短信接口的示例
package org.jeecg.modules.portstaffs.util;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.net.URL;
/**
* 功能描述:call调用webservice接口用具类
* @author FengChaoTao
* @date 2022/4/13 14:37
*/
public class WebServiceUtils {
static final String url = " WebService地址";
static final String username = "你的用户名";
static final String password = "你的密码";
public static void main(String[] args) {
sendNote("15512341234","测试短信");
}
/**
*sendbody 所需内容根据自己的业务场景调整
* @param mobileNum 接收号码,多个号码用逗号隔开
* @param content 发送内容
*/
public static void sendNote(String mobileNum,String content){
String orgCode = "50"; // 发送用户标记 一般两位数字
Integer needReport = 1; // 是否需要短信报告 1 需要 其他不需要
String sendbody = "<sendbody>\n" +
"\t<message>\n" +
"\t<orgaddr>%s</orgaddr><mobile>%s</mobile>" +
"<content><![CDATA[%s]]></content>" +
"<sendtime></sendtime>" +
"<needreport>%s</needreport>\n" +
"\t</message>\n" +
"\t<publicContent></publicContent>\n" +
"</sendbody>";
try {
//替换sendbody中的%s
sendbody=String.format(sendbody, orgCode, mobileNum, content, needReport);
InsertDownSms(sendbody);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 发送短信
* @param sendbody
* @return
* @throws Exception
*/
public static String InsertDownSms(String sendbody) throws Exception {
//创建客户端调用webservice的代理对象
Service service = new Service();
//创建一个调用对象,代表对web service 的一次调用
Call call = (Call) service.createCall();
//设置web service的url 地址
call.setTargetEndpointAddress(new URL(url));
//设置操作名称,QName 对象的两个参数分别为命名空间(没有可传"")和方法名称
call.setOperationName(new QName("", "InsertDownSms"));
//设置调用方法参数名和类型,有多少参数设置多少个
call.addParameter("username", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("batch", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("sendbody", XMLType.XSD_STRING, ParameterMode.IN);
//设置返回参数类型
call.setReturnType(XMLType.XSD_STRING);
//传入参数,顺序跟上面设置一样
String result = (String) call.invoke(new Object[]{username, password, "34", sendbody});
System.out.println(result);//打印返回的结果
return result;
}
}
感谢观看,如果对您有用记得点赞哦~