Compare commits

..

2 Commits

Author SHA1 Message Date
biexiande 7030656019 Merge remote-tracking branch 'origin/main' 2024-11-21 10:24:03 +08:00
biexiande 7f54a7aae8 短信发送 工具类 2024-11-21 10:23:47 +08:00
4 changed files with 296 additions and 240 deletions

View File

@ -200,21 +200,32 @@
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.axis</groupId>-->
<!-- <artifactId>axis</artifactId>-->
<!-- <version>1.4</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.axis</groupId>-->
<!-- <artifactId>axis-jaxrpc</artifactId>-->
<!-- <version>1.4</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.roufid.tutorials</groupId>-->
<!-- <artifactId>example-app</artifactId>-->
<!-- <version>1.0</version>-->
<!-- </dependency>-->
<!--cxf-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.banboocloud.Codec </groupId>
@ -331,6 +342,15 @@
<version>${velocity.version}</version>
</dependency>
<dependency>
<groupId>com.banboocloud</groupId>
<artifactId>banboocloudCodec</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/java/com/ruoyi/project/system/lib/banboocloud_Codec-0.0.jar</systemPath>
</dependency>
<!-- 定时任务 -->
<dependency>
<groupId>org.quartz-scheduler</groupId>

View File

@ -1,6 +1,10 @@
package com.ruoyi.common.wsdl;
import org.apache.axis.client.Call;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.springframework.util.*;
import javax.xml.namespace.QName;
import java.util.ArrayList;
@ -10,33 +14,33 @@ import java.util.Map;
public class WebServiceUtil {
public static String sendMessage(Collection<String> phones, String msg) throws Exception {
System.out.println("开始调用webservice");
List<Map<String, Object>> storeItemList_ = new ArrayList<>();
String endpoint = "http://10.171.19.193:8080/dxpt/ws/shortMessageWs?wsdl";
String soapaction = "http://service.cxf.com/";
String method = "returnMassages";
org.apache.axis.client.Service service = new org.apache.axis.client.Service();
Call call = (Call) service.createCall();// 通过service创建call对象
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName(soapaction, method));
call.addParameter(new QName(soapaction, "phone"),
org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName(soapaction, "msg"),
org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName(soapaction, "Dwdm"),
org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setUseSOAPAction(true);
//call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); //返回参数的类型
call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_VECTOR);
//call.setReturnType(XMLType.XSD_STRING);
call.setSOAPActionURI(soapaction + method);
java.util.Vector xmlStr = (java.util.Vector) call.invoke(new Object[]{StringUtils.collectionToCommaDelimitedString(phones), msg, "SGJT-山港集团"});
System.out.println("webservice response content :" + StringUtils.collectionToCommaDelimitedString(xmlStr));
return StringUtils.collectionToCommaDelimitedString(xmlStr);
}
// public static String sendMessage(Collection<String> phones, String msg) throws Exception {
//
// System.out.println("开始调用webservice");
// List<Map<String, Object>> storeItemList_ = new ArrayList<>();
// String endpoint = "http://10.171.19.193:8080/dxpt/ws/shortMessageWs?wsdl";
// String soapaction = "http://service.cxf.com/";
// String method = "returnMassages";
// org.apache.axis.client.Service service = new org.apache.axis.client.Service();
// Call call = (Call) service.createCall();// 通过service创建call对象
// call.setTargetEndpointAddress(endpoint);
// call.setOperationName(new QName(soapaction, method));
// call.addParameter(new QName(soapaction, "phone"),
// org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
// call.addParameter(new QName(soapaction, "msg"),
// org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
// call.addParameter(new QName(soapaction, "Dwdm"),
// org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
//
// call.setUseSOAPAction(true);
// //call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); //返回参数的类型
// call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_VECTOR);
// //call.setReturnType(XMLType.XSD_STRING);
// call.setSOAPActionURI(soapaction + method);
// java.util.Vector xmlStr = (java.util.Vector) call.invoke(new Object[]{StringUtils.collectionToCommaDelimitedString(phones), msg, "SGJT-山港集团"});
// System.out.println("webservice response content :" + StringUtils.collectionToCommaDelimitedString(xmlStr));
// return StringUtils.collectionToCommaDelimitedString(xmlStr);
// }
// public static void main(String[] args) {
// Collection<String> objects = new ArrayList<>();
@ -47,4 +51,37 @@ public class WebServiceUtil {
// e.printStackTrace();
// }
// }
public static String sendMessage(List<String> phones, String msg) throws Exception {
//
String result ;
try {
DynamicClientFactory dynamicClientFactory = DynamicClientFactory.newInstance();
Client client = dynamicClientFactory.createClient("http://10.171.19.193:8080/dxpt/ws/shortMessageWs?wsdl");
Endpoint endpoint = client.getEndpoint();
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), "returnMassages");
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
if (bindingInfo.getOperation(opName) == null) {
for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
if ("returnMassages".equals(operationInfo.getName().getLocalPart())) {
opName = operationInfo.getName();
break;}}}
Object[] res = client.invoke(opName, StringUtils.collectionToCommaDelimitedString(phones),msg,"SGJT");
//System.out.println();
result = String.valueOf(res[0]);
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
}
}

View File

@ -1,200 +1,199 @@
package com.ruoyi.common.wsdl;
import ch.qos.logback.core.net.server.Client;
import com.alibaba.fastjson2.JSONObject;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.types.Schema;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.compress.utils.Lists;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class WebServiceUtils {
// 接口调用地址
private static String url = "http://10.171.19.193:8080/dxpt/ws/shortMessageWs?wsdl";
// 命名空间
private static String namespace = "http://service.cxf.com/";
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<>();
map.put("phone","18437762352");
map.put("msg","ceshi");
map.put("Dwdm","SGJT-山港集团");
String call = call("returnMassages", map);
System.out.println(call);
}
/**
* WebService - 调用接口
*
* @param methodName 函数名
* @param params 参数
* @param clazz 返回对象class
* @return 返回结果(Object)
*/
public static <T> T call(String methodName, Map<String, String> params, Class<T> clazz) {
// log.info("调用 WebService 发送参数==>" + JsonUtil.object2Json(params));
String soapActionURI = namespace + methodName;
try {
Service service = new Service();
SOAPHeaderElement header = new SOAPHeaderElement(namespace, methodName);
header.setNamespaceURI(namespace);
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(namespace, methodName));
// 添加参数
List<String> parameterList = Lists.newArrayList();
if (params != null) {
Set<String> paramsKey = params.keySet();
for (String key : paramsKey) {
call.addParameter(new QName(namespace, key), XMLType.XSD_STRING, ParameterMode.IN);
String pValue = MapUtils.getString(params, key);
header.addChildElement(key).setValue(pValue);
parameterList.add(pValue);
}
}
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
call.addHeader(header);
// 进行序列化 实体类也要序列化 implements Serializable
call.registerTypeMapping(clazz, new QName(namespace, soapActionURI),
new BeanSerializerFactory(clazz, new QName(namespace, soapActionURI)),
new BeanDeserializerFactory(clazz, new QName(namespace, soapActionURI)));
// 设置输出的类
call.setReturnClass(clazz);
// 接口返回结果
T result = (T) call.invoke(parameterList.toArray());
// log.info("调用 WebService 接口返回===>" + result);
return result;
} catch (Exception e) {
// log.error("调用 WebService 接口错误信息==>" + e.getMessage());
}
return null;
}
/**
* WebService - 接口调用
*
* @param methodName 函数名
* @param params 参数
* @return 返回结果(String)
*/
public static String call(String methodName, Map<String, String> params) {
// log.info("调用 WebService 发送参数==>" + JsonUtil.object2Json(params));
System.out.println("调用 WebService 发送参数==>" + JSONObject.toJSONString(params));
String soapActionURI = namespace + methodName;
try {
Service service = new Service();
SOAPHeaderElement header = new SOAPHeaderElement(namespace, methodName);
header.setNamespaceURI(namespace);
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(namespace, methodName));
// 添加参数
List<String> parameterList = Lists.newArrayList();
if (params != null) {
Set<String> paramsKey = params.keySet();
for (String key : paramsKey) {
call.addParameter(new QName(namespace, key), XMLType.XSD_STRING, ParameterMode.IN);
String pValue = MapUtils.getString(params, key);
header.addChildElement(key).setValue(pValue);
parameterList.add(pValue);
}
}
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
call.addHeader(header);
// 设置返回类型
call.setReturnType(new QName(namespace, methodName), String.class);
// 接口返回结果
String result = (String) call.invoke(parameterList.toArray());
// log.info("调用 WebService 接口返回===>" + result);
System.out.println("调用 WebService 接口返回===>" + result);
return result;
} catch (Exception e) {
// log.error("调用 WebService 接口错误信息==>" + e.getMessage());
System.out.println("调用 WebService 接口返回===>" + e.getMessage());
}
return null;
}
/**
* WebService - 调用接口
*
* @param methodName 函数名
* @param params 参数
* @return 返回结果(String)
*/
public static String call2(String methodName, Map<String, String> params) {
// log.info("调用 WebService 发送参数==>" + JsonUtil.object2Json(params));
String soapActionURI = namespace + methodName;
try {
Service service = new Service();
SOAPHeaderElement header = new SOAPHeaderElement(namespace, methodName);
header.setNamespaceURI(namespace);
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(namespace, methodName));
// 添加参数
List<String> parameterList = Lists.newArrayList();
if (params != null) {
Set<String> paramsKey = params.keySet();
for (String key : paramsKey) {
call.addParameter(new QName(namespace, key), XMLType.XSD_STRING, ParameterMode.IN);
String pValue = MapUtils.getString(params, key);
header.addChildElement(key).setValue(pValue);
parameterList.add(pValue);
}
}
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
call.addHeader(header);
// 设置返回类型
call.setReturnType(XMLType.XSD_SCHEMA);
// 接口返回结果
Schema schemaResult = (Schema)call.invoke(parameterList.toArray());
String result = "";
for(int i = 0; i<schemaResult.get_any().length; i++){
result = result + schemaResult.get_any()[i];
}
// log.error("调用 WebService 接口返回===>" + result);
return result;
} catch (Exception e) {
// log.error("调用 WebService 接口错误信息==>" + e.getMessage());
}
return null;
}
}
//package com.ruoyi.common.wsdl;
//
//
//import ch.qos.logback.core.net.server.Client;
//import com.alibaba.fastjson2.JSONObject;
//import org.apache.axis.client.Call;
//import org.apache.axis.client.Service;
//import org.apache.axis.encoding.XMLType;
//import org.apache.axis.encoding.ser.BeanDeserializerFactory;
//import org.apache.axis.encoding.ser.BeanSerializerFactory;
//import org.apache.axis.message.SOAPHeaderElement;
//import org.apache.axis.types.Schema;
//import org.apache.commons.collections4.MapUtils;
//import org.apache.commons.compress.utils.Lists;
//
//import javax.xml.namespace.QName;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//
//
//
//public class WebServiceUtils {
// // 接口调用地址
// private static String url = "http://10.171.19.193:8080/dxpt/ws/shortMessageWs?wsdl";
// // 命名空间
// private static String namespace = "http://service.cxf.com/";
//
//
// public static void main(String[] args) {
// HashMap<String, String> map = new HashMap<>();
// map.put("phone","18437762352");
// map.put("msg","ceshi");
// map.put("Dwdm","SGJT-山港集团");
// String call = call("returnMassages", map);
// System.out.println(call);
// }
//
//
//
//
//
//
// /**
// * WebService - 调用接口
// *
// * @param methodName 函数名
// * @param params 参数
// * @param clazz 返回对象class
// * @return 返回结果(Object)
// */
// public static <T> T call(String methodName, Map<String, String> params, Class<T> clazz) {
//// log.info("调用 WebService 发送参数==>" + JsonUtil.object2Json(params));
// String soapActionURI = namespace + methodName;
// try {
// Service service = new Service();
//
// SOAPHeaderElement header = new SOAPHeaderElement(namespace, methodName);
// header.setNamespaceURI(namespace);
//
// Call call = (Call) service.createCall();
// call.setTargetEndpointAddress(url);
//
// call.setOperationName(new QName(namespace, methodName));
//
// // 添加参数
// List<String> parameterList = Lists.newArrayList();
// if (params != null) {
// Set<String> paramsKey = params.keySet();
// for (String key : paramsKey) {
// call.addParameter(new QName(namespace, key), XMLType.XSD_STRING, ParameterMode.IN);
// String pValue = MapUtils.getString(params, key);
// header.addChildElement(key).setValue(pValue);
// parameterList.add(pValue);
// }
// }
// call.setUseSOAPAction(true);
// call.setSOAPActionURI(soapActionURI);
// call.addHeader(header);
//
// // 进行序列化 实体类也要序列化 implements Serializable
// call.registerTypeMapping(clazz, new QName(namespace, soapActionURI),
// new BeanSerializerFactory(clazz, new QName(namespace, soapActionURI)),
// new BeanDeserializerFactory(clazz, new QName(namespace, soapActionURI)));
// // 设置输出的类
// call.setReturnClass(clazz);
// // 接口返回结果
// T result = (T) call.invoke(parameterList.toArray());
//// log.info("调用 WebService 接口返回===>" + result);
// return result;
// } catch (Exception e) {
//// log.error("调用 WebService 接口错误信息==>" + e.getMessage());
// }
// return null;
// }
//
// /**
// * WebService - 接口调用
// *
// * @param methodName 函数名
// * @param params 参数
// * @return 返回结果(String)
// */
// public static String call(String methodName, Map<String, String> params) {
//// log.info("调用 WebService 发送参数==>" + JsonUtil.object2Json(params));
// System.out.println("调用 WebService 发送参数==>" + JSONObject.toJSONString(params));
// String soapActionURI = namespace + methodName;
// try {
// Service service = new Service();
//
// SOAPHeaderElement header = new SOAPHeaderElement(namespace, methodName);
// header.setNamespaceURI(namespace);
//
// Call call = (Call) service.createCall();
// call.setTargetEndpointAddress(url);
//
// call.setOperationName(new QName(namespace, methodName));
//
// // 添加参数
// List<String> parameterList = Lists.newArrayList();
// if (params != null) {
// Set<String> paramsKey = params.keySet();
// for (String key : paramsKey) {
// call.addParameter(new QName(namespace, key), XMLType.XSD_STRING, ParameterMode.IN);
// String pValue = MapUtils.getString(params, key);
// header.addChildElement(key).setValue(pValue);
// parameterList.add(pValue);
// }
// }
// call.setUseSOAPAction(true);
// call.setSOAPActionURI(soapActionURI);
// call.addHeader(header);
// // 设置返回类型
// call.setReturnType(new QName(namespace, methodName), String.class);
// // 接口返回结果
//
// String result = (String) call.invoke(parameterList.toArray());
//// log.info("调用 WebService 接口返回===>" + result);
// System.out.println("调用 WebService 接口返回===>" + result);
// return result;
// } catch (Exception e) {
//// log.error("调用 WebService 接口错误信息==>" + e.getMessage());
// System.out.println("调用 WebService 接口返回===>" + e.getMessage());
// }
// return null;
// }
//
// /**
// * WebService - 调用接口
// *
// * @param methodName 函数名
// * @param params 参数
// * @return 返回结果(String)
// */
// public static String call2(String methodName, Map<String, String> params) {
//// log.info("调用 WebService 发送参数==>" + JsonUtil.object2Json(params));
// String soapActionURI = namespace + methodName;
// try {
// Service service = new Service();
//
// SOAPHeaderElement header = new SOAPHeaderElement(namespace, methodName);
// header.setNamespaceURI(namespace);
//
// Call call = (Call) service.createCall();
// call.setTargetEndpointAddress(url);
//
// call.setOperationName(new QName(namespace, methodName));
//
// // 添加参数
// List<String> parameterList = Lists.newArrayList();
// if (params != null) {
// Set<String> paramsKey = params.keySet();
// for (String key : paramsKey) {
// call.addParameter(new QName(namespace, key), XMLType.XSD_STRING, ParameterMode.IN);
// String pValue = MapUtils.getString(params, key);
// header.addChildElement(key).setValue(pValue);
// parameterList.add(pValue);
// }
// }
// call.setUseSOAPAction(true);
// call.setSOAPActionURI(soapActionURI);
// call.addHeader(header);
// // 设置返回类型
// call.setReturnType(XMLType.XSD_SCHEMA);
// // 接口返回结果
// Schema schemaResult = (Schema)call.invoke(parameterList.toArray());
// String result = "";
// for(int i = 0; i<schemaResult.get_any().length; i++){
// result = result + schemaResult.get_any()[i];
// }
//// log.error("调用 WebService 接口返回===>" + result);
// return result;
// } catch (Exception e) {
//// log.error("调用 WebService 接口错误信息==>" + e.getMessage());
// }
// return null;
// }
//}

View File

@ -37,10 +37,10 @@ public class SysSendInfoServiceImpl implements ISysSendInfoService {
if(sendMessageDTO.getIsSendPhone() !=null && sendMessageDTO.getIsSendPhone()){//发送短信
List<String> phoneList= sendMessageDTO.getPhoneList();
String phone = String.join(",", phoneList);
Collection<String> phones = new ArrayList<>(phoneList);
List<String> phones = new ArrayList<>(phoneList);
String msg=sendMessageDTO.getSendText();
String dwdm="SGJT-山港集团";
String dwdm="SGJT";
//todo 调用发送短信接口
WebServiceUtil.sendMessage(phones,msg);