From 7f54a7aae8ae394e6b41da7573cdbcc7e724dbeb Mon Sep 17 00:00:00 2001 From: biexiande Date: Thu, 21 Nov 2024 10:23:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E5=8F=91=E9=80=81=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RuoYi-Vue-Oracle/pom.xml | 40 +- .../com/ruoyi/common/wsdl/WebServiceUtil.java | 93 ++-- .../ruoyi/common/wsdl/WebServiceUtils.java | 399 +++++++++--------- .../service/impl/SysSendInfoServiceImpl.java | 4 +- 4 files changed, 296 insertions(+), 240 deletions(-) diff --git a/RuoYi-Vue-Oracle/pom.xml b/RuoYi-Vue-Oracle/pom.xml index 0b18833..df4140a 100644 --- a/RuoYi-Vue-Oracle/pom.xml +++ b/RuoYi-Vue-Oracle/pom.xml @@ -196,21 +196,32 @@ - - org.apache.axis - axis - 1.4 - - - org.apache.axis - axis-jaxrpc - 1.4 - + + + + + + + + + + + + + org.apache.cxf + cxf-spring-boot-starter-jaxws + 3.2.1 + + + org.apache.cxf + cxf-rt-transports-http + 3.2.1 + @@ -294,6 +305,15 @@ ${velocity.version} + + + com.banboocloud + banboocloudCodec + 1.0 + system + ${project.basedir}/src/main/java/com/ruoyi/project/system/lib/banboocloud_Codec-0.0.jar + + org.quartz-scheduler diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtil.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtil.java index 6b4b0c7..71a59c9 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtil.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtil.java @@ -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 phones, String msg) throws Exception { - - System.out.println("开始调用webservice"); - List> 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 phones, String msg) throws Exception { +// +// System.out.println("开始调用webservice"); +// List> 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 objects = new ArrayList<>(); @@ -47,4 +51,37 @@ public class WebServiceUtil { // e.printStackTrace(); // } // } +public static String sendMessage(List 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; +} } diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtils.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtils.java index 4d0a716..8a8f9f3 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtils.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/common/wsdl/WebServiceUtils.java @@ -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 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 call(String methodName, Map params, Class 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 parameterList = Lists.newArrayList(); - if (params != null) { - Set 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 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 parameterList = Lists.newArrayList(); - if (params != null) { - Set 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 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 parameterList = Lists.newArrayList(); - if (params != null) { - Set 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" + result); - return result; - } catch (Exception e) { -// log.error("调用 WebService 接口错误信息==>" + e.getMessage()); - } - return null; - } -} \ No newline at end of file +//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 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 call(String methodName, Map params, Class 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 parameterList = Lists.newArrayList(); +// if (params != null) { +// Set 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 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 parameterList = Lists.newArrayList(); +// if (params != null) { +// Set 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 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 parameterList = Lists.newArrayList(); +// if (params != null) { +// Set 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" + result); +// return result; +// } catch (Exception e) { +//// log.error("调用 WebService 接口错误信息==>" + e.getMessage()); +// } +// return null; +// } +//} \ No newline at end of file diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/SysSendInfoServiceImpl.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/SysSendInfoServiceImpl.java index a7b6e31..feae8fc 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/SysSendInfoServiceImpl.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/SysSendInfoServiceImpl.java @@ -37,10 +37,10 @@ public class SysSendInfoServiceImpl implements ISysSendInfoService { if(sendMessageDTO.getIsSendPhone() !=null && sendMessageDTO.getIsSendPhone()){//发送短信 List phoneList= sendMessageDTO.getPhoneList(); String phone = String.join(",", phoneList); - Collection phones = new ArrayList<>(phoneList); + List phones = new ArrayList<>(phoneList); String msg=sendMessageDTO.getSendText(); - String dwdm="SGJT-山港集团"; + String dwdm="SGJT"; //todo 调用发送短信接口 WebServiceUtil.sendMessage(phones,msg);