1.項(xiàng)目引入cxf包
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.5</version>
</dependency>
2.在項(xiàng)目下新建webservice文件,右邊點(diǎn)擊選擇WebService
1.png
3.填寫webservice接口信息(需要本機(jī)要能訪問該接口干像,不然會(huì)報(bào)錯(cuò))
2.png
4.自動(dòng)生成的代碼列表如下
3.png
5.webservice接口調(diào)用
package com.yudu.sms;
import com.yudu.sms.util.MD5;
import com.yudu.sms.webserviceFile.ISmsOperator;
import com.yudu.sms.webserviceFile.MtMessage;
import com.yudu.sms.webserviceFile.MtMessageRes;
import com.yudu.sms.webserviceFile.SmsOperatorImpService;
import java.util.ArrayList;
import java.util.List;
public class WebServiceCS {
public static void main(String[] args) {
String userName="xxxx"; //用戶名
String password="xxxx"; //密碼
password = MD5.GetMD5Code(password);
MtMessage mtMessage = new MtMessage();
List<String> phoneNumber = new ArrayList<>();
phoneNumber.add("15823522687");
mtMessage.setPhoneNumber(phoneNumber);
mtMessage.setContent("webservice短信接口測(cè)試1105");
SmsOperatorImpService smsOperatorImpService = new SmsOperatorImpService();
ISmsOperator sms = smsOperatorImpService.getSmsOperatorImpPort();
MtMessageRes mtMessageRes = sms.sendSms(userName,password,"",mtMessage);
if(mtMessageRes!=null){
if(mtMessageRes.getSubStat().equals("r:000")){
// TODO
}
}
}
}