聯通vac和sp對接填坑備忘
坑很多,平時我也不寫webservice,聯通配合的哥們說來說去就是:“按規範”,這簡直就是最高訓示:“按既定方針辦”。沒辦法隻能自己苦逼的多試試。
建議聯通參考參考微信公衆平台上面的,有個文檔,有個服務端填寫,也搞個論壇能提問。
閑話少說,規範一共2點,一個webservice,一個ftp :
- ftp這個真心不好了解,啥發起方vac,接受方sp,檔案頭格式檔案體格式,繞的暈頭轉向的,其實就是他們有一個ftp伺服器,咱們定期去考檔案回來按照檔案頭檔案體解析,這一塊可以先不管,以後再填坑
- webservice這一塊封包demo如下
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:m0="http://req.sync.soap.bossagent.vac.unicom.com" xmlns:m1="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:orderRelationUpdateNotify xmlns:m="http://soap.bossagent.vac.unicom.com/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<orderRelationUpdateNotifyRequest xsi:type="m0:OrderRelationUpdateNotifyRequest">
<recordSequenceId>201310281653151945</recordSequenceId>
<userIdType>1</userIdType>
<userId>18628071120</userId>
<serviceType>80</serviceType>
<spId>90120</spId>
<productId>9081086801</productId>
<updateType>1</updateType>
<updateTime>20150326153832</updateTime>
<updateDesc/>
<linkId/>
<content/>
<effectiveDate/>
<expireDate>20370101000000</expireDate>
<time_stamp>1028165315</time_stamp>
<encodeStr>1862807112090810868011028165315</encodeStr>
</orderRelationUpdateNotifyRequest>
</m:orderRelationUpdateNotify>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
字段名稱并不和文檔一模一樣,我是先拿到文檔的,按照文檔寫了對象,對不起,測試的時候找不到字段滴,主要就是Id和ID差別,其他倒還好
搭建maven + cxf + spring項目
建立一個maven項目,
pom.xml添加需要的jar
<cxf.version>2.7.13</cxf.version>
---
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>dingzl test</display-name>
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 設定Spring容器加載配置檔案路徑 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
<jaxws:endpoint id="orderRelationUpdateNotify" implementor="com.unicom.vac.bossagent.soap.OrderRelationUpdateNotifyImpl" address="/OrderRelationUpdateNotify"/>
</beans>
建java接口檔案
這時候需要能看懂demo的xml封包,我就是走了很多彎路
<m:orderRelationUpdateNotify xmlns:m="http://soap.bossagent.vac.unicom.com" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<orderRelationUpdateNotifyRequest xsi:type="m0:OrderRelationUpdateNotifyRequest">
這裡檔案夾按照soap.bossagent.vac.unicom.com來建,com/unicom/vac/bossagent/soap下面建java檔案,
路徑 :../src/main/java/com/unicom/vac/bossagent/soap/IOrderRelationUpdateNotify.java
package com.unicom.vac.bossagent.soap;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(targetNamespace = "http://soap.bossagent.vac.unicom.com")
public interface IOrderRelationUpdateNotify {
@WebMethod(operationName="orderRelationUpdateNotify")
public Rsp orderRelationUpdateNotify(@WebParam(name="orderRelationUpdateNotifyRequest") OrderRelationUpdateNotifyRequest req);
}
targetNamespace 這個困惑我好久.沒有這個的時候,封包http://soap.bossagent.vac.unicom.com 帶上斜杠”/”的時候是能找到.
但是沒有斜杠的時候一直報 Unexpected wrapper element {http://soap.bossagent.vac.unicom.com}orderRelationUpdateNotify found. Expected {http://soap.bossagent.vac.unicom.com/}orderRelationUpdateNotify.
後來加上targetNamespace 就好了
實作類
路徑 :../src/main/java/com/unicom/vac/bossagent/soap/OrderRelationUpdateNotifyImpl.java
package com.unicom.vac.bossagent.soap;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@WebService
public class OrderRelationUpdateNotifyImpl implements IOrderRelationUpdateNotify {
private static final Logger logger = LogManager.getLogger(OrderRelationUpdateNotifyImpl.class);
@WebMethod(operationName="orderRelationUpdateNotify")
public Rsp orderRelationUpdateNotify(@WebParam(name="orderRelationUpdateNotifyRequest") OrderRelationUpdateNotifyRequest req) {
logger.info(req.toString());
Rsp rsp = new Rsp();
rsp.setRecordSequenceID(req.getRecordSequenceId());
rsp.setResultCode();
return rsp;
}
}
入參對象
package com.unicom.vac.bossagent.soap;
public class OrderRelationUpdateNotifyRequest {
private String recordSequenceId;// string 18 流水号,
private Integer userIdType;// integer 4 使用者ID類型 1: MSISDN 2: PsedoCode
private String userId;// string 36 使用者手機号碼或僞碼 UserIdType填1 為手機号碼; UserIdType填2 為僞碼
private String serviceType;// String 2 業務類型,見附錄
private String spId;// string 21 SP辨別
private String productId;// string 21 産品辨別(此為SP在PRM側申請的SP_Productid)
private Integer updateType;// integer 4 更新操作的類型包括: 1:訂購 2:退定 3:點播 4:定購關系變更(一般是修改有效期)(保留,暫不用) 5:改号
private String updateTime;// string 14 更新時間
private String updateDesc;// string 100 更新操作的較長的描述 聯通在信、彩信等定購、點播接入号,和CheckPrice請求中AccessNo字段一緻; 對crm側訂購、退訂由vac根據産品填寫;對其他業務填空
private String linkId;// string 20 事務關聯ID,用于點播業務的臨時定購關系關聯,由平台産生。格式如下: MMDDHHMMSS+10位随機序列号; 為空表示無效。 使用者點播時使用。
private String content;// string 140 内容,當UpdateType=5時,本字段填原使用者手機号碼或僞碼,具體填寫方式由UserIdType字段決定
private String effectiveDate;// string 14 訂購關系生效時間, 格式:yyyyMMddhhmmss
private String expireDate;// string 14 訂購關系失效時間, 格式:yyyyMMddhhmmss
private String time_stamp;// string 10 時間戳由VAC生成,格式是: MMDDHHMMSS,月日時分秒。
private String encodeStr;// string
.....get/set略。。。
這裡和文檔略有差別,要注意
傳回值對象
package com.unicom.vac.bossagent.soap;
/**
* 傳回值
* @author dingzl10
*
*/
public class Rsp {
private String recordSequenceID;
private Integer resultCode;
public String getRecordSequenceID() {
return recordSequenceID;
}
public void setRecordSequenceID(String recordSequenceID) {
this.recordSequenceID = recordSequenceID;
}
public Integer getResultCode() {
return resultCode;
}
public void setResultCode(Integer resultCode) {
this.resultCode = resultCode;
}
@Override
public String toString() {
return "Rsp [recordSequenceID=" + recordSequenceID + ", resultCode=" + resultCode + "]";
}
}
部署&測試
部署的時候呢,對方是不接受域名的,一定要ip和端口,這個要注意
測試
代碼測試很容易就通過了
public static void main(String[] args) {
JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean();
svr.setServiceClass(IOrderRelationUpdateNotify.class);
svr.setAddress("http://localhost:8080/sp/OrderRelationUpdateNotify");
IOrderRelationUpdateNotify hw = (IOrderRelationUpdateNotify) svr.create();
OrderRelationUpdateNotifyRequest r = new OrderRelationUpdateNotifyRequest();
r.setRecordSequenceId("111111111");
System.out.println(hw.orderRelationUpdateNotify(r).toString());
}
然并卵,估計他們也不會用代碼來調
我還是用工具,直接考封包來的實在一點
要用post,get是調不到滴
傳回值
<soap:Envelope>
<soap:Body>
<ns2:orderRelationUpdateNotifyResponse>
<return>
<recordSequenceID>201310281653151111945</recordSequenceID>
<resultCode>0</resultCode>
</return>
</ns2:orderRelationUpdateNotifyResponse>
</soap:Body>
</soap:Envelope>