⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manager.java.svn-base

📁 短信猫发送程序java 版,可以适应西门子等多种短信猫使用。
💻 SVN-BASE
字号:
package com.yuther.sms.business;import java.io.Reader;import java.io.StringReader;import java.util.List;import javax.xml.rpc.ParameterMode;import javax.xml.rpc.encoding.XMLType;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.log4j.Logger;import org.jdom.Document;import org.jdom.Element;import org.jdom.input.SAXBuilder;import org.jdom.output.Format;import org.jdom.output.XMLOutputter;import com.yuther.sms.business.uci.Cust;/** * 发送保存接口 * @author yuther * */public class Manager {		static Logger log = Logger.getLogger(Manager.class);		// WSDL	static String endpoint;	static	{		endpoint = "http://133.64.39.76:8089/webservice/Projects_qlsAS_ESB_BNet_initial_ProxyToEAI?WSDL";//		endpoint = "http://133.64.41.134:8289/webservice/Projects_qlsAS_ESB_BNet_initial_ProxyToEAI?WSDL";	}		public static Cust QueryCustByNbr(String localNetCode,String nbr)throws Exception{				// HEAD-----------------------------------		StringBuffer head = new StringBuffer();		head.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");		head.append("<GenericEvent>\n");		head.append("  <EventType>SYNC</EventType>\n");		head.append("  <Action />\n");		head.append("  <_EID>CustIndenify</_EID>\n");		head.append("  <SerialNo>BNET_1000</SerialNo>\n");		head.append("  <Sender>\n");		head.append("    <Application>NETB</Application>\n");		head.append("    <DataItems>\n");		head.append("      <DataItem>\n");		head.append("        <Keys>\n");		head.append("          <Key Name=\"LocalNet\" Value=\"_ESB_WS\" />\n");		head.append("          <Key Name=\"ServiceArea\" Value=\"_ESB_WS\" />\n");		head.append("          <Key Name=\"ProductID\" Value=\"0\" />\n");		head.append("        </Keys>\n");		head.append("      </DataItem>\n");		head.append("    </DataItems>\n");		head.append("  </Sender>\n");		head.append("</GenericEvent>\n");					// BODY------------------------------------------		StringBuffer body = new StringBuffer();		body.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");		body.append("<Request>\n");		body.append("	<IDENTIFY_TYPE>4</IDENTIFY_TYPE>\n");			/*		0:根据客户ID		1:根据客户名称(建议少用)+本地网标识+服务区标识		2:根据客户名称+证件编号+证件类型(证件类型可空)+本地网标识+服务区标识		3:证件编号+证件类型(证件类型可空)		4:根据本地网业务标识码+接入号码(本地网业务标识码取值见 《基础数据统一编码》)		   */				body.append("	<IDENTIFY_DETAIL>").append(localNetCode+"\n").append(nbr).append("</IDENTIFY_DETAIL>\n"); //客户识别使用的信息,如果需要多个信息,信息间使用‘换行符\n’隔开//		body.append("	<IDENTIFY_DETAIL>290\n87795288</IDENTIFY_DETAIL>\n"); //客户识别使用的信息,如果需要多个信息,信息间使用‘换行符\n’隔开		body.append("</Request>\n");						// 从字符串转换为DOM		SAXBuilder builder = new SAXBuilder();		Document outDocument = null;		Reader in = new StringReader(head.toString());		try		{			outDocument = builder.build(in);		}		catch (Exception e)		{			log.error("Head String转换DOM时,程序内部出错", e);			System.exit(-1);		}				in = new StringReader(body.toString());		try		{			outDocument = builder.build(in);		}		catch (Exception e)		{			log.error("BOdy String转换DOM时,程序内部出错", e);			System.exit(-1);		}				try 		{			// 以下都是套路			Service service = new Service();			Call call = (Call)service.createCall();			call.setTargetEndpointAddress(endpoint);						// WSDL里面描述的接口名称			call.setOperationName("callWebServ");						//  接口的参数			call.addParameter("in0", XMLType.XSD_STRING, ParameterMode.IN);			call.addParameter("in1", XMLType.XSD_STRING, ParameterMode.IN);			// 设置返回类型 			call.setReturnType(XMLType.XSD_STRING);						System.out.println("HEAD:\n" + head.toString());			System.out.println("BODY:\n" + body.toString());						//接口访问			String result = (String)call.invoke(new Object[]{head.toString(), body.toString()});					//System.out.println("result is "+result);			//			builder = new SAXBuilder();//			in = new StringReader(result);//			try//			{//				outDocument = builder.build(in);//			}//			catch (Exception e)//			{//				log.error("Result String转换DOM时,程序内部出错",  e);//				System.exit(-1);//			}////			XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());//			String inXML = xmlOut.outputString(outDocument);			//将返回字符串转为DOM			try			{				Document retDOM = covert(result);				// 跟节点<Response>				Element el_root = retDOM.getRootElement();				//<RET_CODE>				Element element_RET_CODE = el_root.getChild("RET_CODE");								//N:客户不存在(参与人存在);		P:客户不存在(参与人不存在);		O:对应唯一客户;		M:对应多个客户;		E:出错				if (!element_RET_CODE.getTextTrim().equals("O"))				{					throw new Exception("通过设备号查询所属客户,<RET_CODE>返回非O值.");				}												//<CustListVOList>				Element el_CustListVOList = el_root.getChild("CustListVOList");				//<CustListVO>				Element el_CustListVO = el_CustListVOList.getChild("CustListVO");								Cust cust = new Cust();								List list = el_CustListVO.getChildren();				for (int i = 0; i < list.size(); i++)				{					Element el = (Element)list.get(i);										//客户ID					if (el.getName().equals("custId"))					{						cust.setCustId(el.getTextTrim());					}					//本地网标识					if (el.getName().equals("localNetCode"))					{						cust.setLocalNetCode(el.getTextTrim());					}					//服务区标识					if (el.getName().equals("areaCode"))					{						cust.setAreaCode(el.getTextTrim());					}					//客户名称					if (el.getName().equals("custName"))					{						cust.setCustName(el.getTextTrim());					}					//客户类型(即参与人类型)					if (el.getName().equals("partyType"))					{						cust.setPartyType(el.getTextTrim());					}					//行业标识					if (el.getName().equals("custVOcaCode"))					{						cust.setCustVOcaCode(el.getTextTrim());					}					//VIP卡号					if (el.getName().equals("vipCode"))					{						cust.setVipCode(el.getTextTrim());					}					//客户的详细地址					if (el.getName().equals("custAddr"))					{						cust.setCustAddr(el.getTextTrim());					}					//地址类型					if (el.getName().equals("addrType"))					{						cust.setAddrType(el.getTextTrim());					}					//证件类型标识					if (el.getName().equals("certTypeId"))					{						cust.setCertTypeId(el.getTextTrim());					}					//证件编码					if (el.getName().equals("certCode"))					{						cust.setCertCode(el.getTextTrim());					}				}								return cust;											}			catch (Exception e)			{				log.error( "web service调用返回XML格式非法",  e);				throw new Exception("web service调用返回XML格式非法");			}							}		catch (Exception e) 		{			throw new Exception("web service调用异常");		}			}		/**	 * 转换XML字符串	 * @param XML	 * @return	 * @throws Exception	 */	private static Document covert(String XML) throws Exception	{		// 从字符串转换为DOM		SAXBuilder builder = new SAXBuilder();		Document outDocument = null;		Reader in = new StringReader(XML);		try		{			outDocument = builder.build(in);			return outDocument;		}		catch (Exception e)		{			log.error("String转换DOM时,String格式出错", e);			throw new Exception("String转换DOM时,String格式出错");		}	}		public static void main(String[] args){				try {						Cust cust = Manager.QueryCustByNbr("290","85307669");			System.out.println(cust.getCustName());					} catch (Exception e) {			e.printStackTrace();		}			}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -