增加TOPGP签收后返回接口
This commit is contained in:
parent
24ce46c525
commit
7cd3135e54
|
|
@ -13,6 +13,7 @@ import io.swagger.annotations.ApiImplicitParams;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
|
@ -35,14 +36,15 @@ public class ExpSubsPushApiController extends BaseController {
|
|||
@Autowired
|
||||
IExpSubsPushApiService expSubsPushApiService;
|
||||
|
||||
//推送
|
||||
//快递100推送
|
||||
@CrossOrigin
|
||||
@PostMapping("anon/subscribeCallBackUrl")
|
||||
@PostMapping("anon/subscribeCallBackUrl/{salt}")
|
||||
@ApiOperation("快递信息订阅推送接受")
|
||||
public SubscribeResp SubscribeCallBackUrl(HttpServletRequest request) {
|
||||
return expSubsPushApiService.ExpressSubscribeCallBackUrl(request);
|
||||
public SubscribeResp SubscribeCallBackUrl(@PathVariable("salt") String salt, HttpServletRequest request) {
|
||||
return expSubsPushApiService.ExpressSubscribeCallBackUrl(request,salt);
|
||||
}
|
||||
|
||||
|
||||
//订阅
|
||||
@CrossOrigin
|
||||
@PostMapping("anon/subscribe")
|
||||
|
|
@ -58,12 +60,29 @@ public class ExpSubsPushApiController extends BaseController {
|
|||
@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "requestJson", value = "请求json",required = true, paramType = "body", dataType = "String", dataTypeClass = String.class)
|
||||
})
|
||||
|
||||
@PostMapping("api/express/topgpSubscribe")
|
||||
public String topgpSubscribe(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
return expSubsPushApiService.ExpressSubscribeFromTopgp(request);
|
||||
}
|
||||
|
||||
//接受topgp转签收单完成后的消息推送
|
||||
@Log(title = "TOPGP出货已转签收", businessType = BusinessType.OTHER)
|
||||
@CrossOrigin
|
||||
@ApiOperation(value="接受TOPGP已转签收消息推送",notes = "request body格式: {\"requestId\":\"topgpSign1628584040740\"," +
|
||||
"\"signedInfoList\":[{\"deliveryNo\":\"S301-2108020001\",\"signNo\":\"S501-2108020001\"},{\"deliveryNo\":\"S301-2108020002\",\"signNo\":\"S501-2108020002\"}]," +
|
||||
"\"expressNo\":\"300444235610\",\"company\":\"annengwuliu\",\"phone\":\"13800138000\",\"status\":\"0\"}"
|
||||
)
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "requestJson", value = "请求json",required = true, paramType = "body", dataType = "String", dataTypeClass = String.class)
|
||||
})
|
||||
@PostMapping("api/express/topgpSigned")
|
||||
public String topgpSigned(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
// return expSubsPushApiService.ExpressSubscribeFromTopgp(request);
|
||||
return expSubsPushApiService.TopgpDeliverySigned(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public interface IExpSubsPushApiService {
|
|||
* 成功结果返回例子: {"result":true,"returnCode":"200","message":"提交成功"}
|
||||
*
|
||||
*/
|
||||
public SubscribeResp ExpressSubscribeCallBackUrl(HttpServletRequest request);
|
||||
public SubscribeResp ExpressSubscribeCallBackUrl(HttpServletRequest request,String salt);
|
||||
|
||||
/**
|
||||
* 获取Topgp推送的快递信息,向快递100推送订阅请求
|
||||
|
|
@ -33,4 +33,11 @@ public interface IExpSubsPushApiService {
|
|||
* @return
|
||||
*/
|
||||
public String ExpressSubscribeFromTopgp(HttpServletRequest request) throws IOException;
|
||||
|
||||
/**
|
||||
* Topgp将出货单转为签收单后的信息推送处理
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public String TopgpDeliverySigned(HttpServletRequest request) throws IOException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.bps.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.kuaidi100.sdk.api.Subscribe;
|
||||
import com.kuaidi100.sdk.contant.ApiInfoConstant;
|
||||
|
|
@ -40,14 +41,7 @@ import java.util.Map;
|
|||
|
||||
@Service
|
||||
public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
||||
/*String key = PropertiesReader.get("key");
|
||||
String customer = PropertiesReader.get("customer");
|
||||
String secret = PropertiesReader.get("secret");
|
||||
String siid = PropertiesReader.get("siid");
|
||||
String userid = PropertiesReader.get("userid");
|
||||
String tid = PropertiesReader.get("tid");
|
||||
String secret_key = PropertiesReader.get("secret_key");
|
||||
String secret_secret = PropertiesReader.get("secret_secret"); */
|
||||
/*String key = PropertiesReader.get("key");*/
|
||||
private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
|
||||
@Value("${express.key}")
|
||||
private String key;
|
||||
|
|
@ -77,22 +71,26 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
if(StringUtils.isEmpty(expSubscribe.getRequestFrom())){
|
||||
expSubscribe.setRequestFrom("local");
|
||||
}
|
||||
|
||||
//如果订阅来源是topgp,则取TOPGP的时间戳,否则自己生成时间戳
|
||||
if( StringUtils.isEmpty(expSubscribe.getRequestId())) {
|
||||
//expSubscribe.setRequestId("local"+System.currentTimeMillis()); //获取时间戳,生成本地请求的requestId
|
||||
expSubscribe.setRequestId("local"+ LocalDateTime.now());
|
||||
}
|
||||
//如果订阅来源是topgp,则取TOPGP的订阅时间,否则自己生成订阅时间
|
||||
if(StringUtils.isEmpty(expSubscribe.getSubscribeTime())){
|
||||
expSubscribe.setSubscribeTime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
String salt="bpsemi"; //定义salt字符串
|
||||
//如果订阅来源是topgp,则取TOPGP传来的salt值topgp,否则使用bpsemi
|
||||
if(StringUtils.isEmpty(expSubscribe.getSalt())) {
|
||||
expSubscribe.setSalt("bpsemi");//定义salt字符串
|
||||
}
|
||||
|
||||
//组合订阅参数
|
||||
SubscribeParameters subscribeParameters = new SubscribeParameters();
|
||||
SubscribeResp subscribeResp = new SubscribeResp();
|
||||
subscribeParameters.setCallbackurl("http://report.bpsemi.cn:8081/it_war/anon/subscribeCallBackUrl");
|
||||
subscribeParameters.setCallbackurl("http://report.bpsemi.cn:8081/it_war/anon/subscribeCallBackUrl/"+expSubscribe.getSalt().trim());
|
||||
subscribeParameters.setPhone(expSubscribe.getPhone());
|
||||
subscribeParameters.setSalt(salt);
|
||||
subscribeParameters.setSalt(expSubscribe.getSalt());
|
||||
SubscribeParam subscribeParam = new SubscribeParam();
|
||||
subscribeParam.setParameters(subscribeParameters);
|
||||
subscribeParam.setCompany(expSubscribe.getCompany());
|
||||
|
|
@ -118,14 +116,13 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
return subscribeResp;
|
||||
}
|
||||
|
||||
|
||||
//订阅记录写入数据库
|
||||
ExpSubscribe newExpSubscribe = new ExpSubscribe();
|
||||
newExpSubscribe.setSid(expSubscribe.getSid()); //将时间戳设为Sid 210810 yangbo
|
||||
newExpSubscribe.setCompany(expSubscribe.getCompany());
|
||||
newExpSubscribe.setNumber(expSubscribe.getNumber());
|
||||
newExpSubscribe.setPhone(expSubscribe.getPhone());
|
||||
newExpSubscribe.setSalt(salt);
|
||||
newExpSubscribe.setSalt(expSubscribe.getSalt());
|
||||
newExpSubscribe.setSubscribeTime(expSubscribe.getSubscribeTime());
|
||||
newExpSubscribe.setResult((subscribeResp.isResult())?"true":"false");
|
||||
newExpSubscribe.setReturnCode(subscribeResp.getReturnCode());
|
||||
|
|
@ -167,7 +164,7 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
@Override
|
||||
public String ExpressSubscribeFromTopgp(HttpServletRequest request) throws IOException {
|
||||
//定义Return变量
|
||||
String retrunStr;
|
||||
String returnStr;
|
||||
|
||||
//获取httpServletRequest传过来的Json字符串,并进行解析
|
||||
JSONObject contentJson= JSONObject.parseObject(ServletUtils.getRequestContent(request));
|
||||
|
|
@ -210,10 +207,8 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
map.put("responseCode",subscribeResp.getReturnCode()); //返回码
|
||||
map.put("result",subscribeResp.isResult()); //订阅结果
|
||||
|
||||
|
||||
//返回Json字符串给TOPGP
|
||||
retrunStr= JSONObject.toJSONString(map);
|
||||
|
||||
returnStr= JSONObject.toJSONString(map);
|
||||
|
||||
//记录本次TOPGP订阅请求的Log
|
||||
ExpTopgpLog expTopgpLog=new ExpTopgpLog();
|
||||
|
|
@ -224,22 +219,57 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
expTopgpLog.setRequestStr(contentJson.toString());
|
||||
expTopgpLog.setRequestTime(subscribeTime);
|
||||
expTopgpLog.setResponseCode(subscribeResp.getReturnCode());
|
||||
expTopgpLog.setResponseStr(retrunStr);
|
||||
expTopgpLog.setResponseStr(returnStr);
|
||||
//插入TOPGPLOG数据库
|
||||
expTopgpLogService.insertExpTopgpLog(expTopgpLog);
|
||||
//返回TOPGP json字符串
|
||||
return returnStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Topgp将出货单转为签收单后的信息推送处理
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String TopgpDeliverySigned(HttpServletRequest request) throws IOException {
|
||||
//获取httpServletRequest传过来的Json字符串,并进行解析
|
||||
String returnStr;
|
||||
JSONObject contentJson= JSONObject.parseObject(ServletUtils.getRequestContent(request));
|
||||
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("requestId",contentJson.getString("requestId"));
|
||||
map.put("responseCode","200");
|
||||
map.put("expressNum",contentJson.getString("expressNum"));
|
||||
returnStr= JSONObject.toJSONString(map);
|
||||
|
||||
//写入TOPGP记录档
|
||||
String deliveryNum="";
|
||||
JSONArray jsonArray = JSONArray.parseArray(contentJson.getString("signedList"));
|
||||
for(Object object :jsonArray){
|
||||
JSONObject jsonObject= JSONObject.parseObject(object.toString());
|
||||
deliveryNum += jsonObject.getString("deliveryNum");
|
||||
if(jsonArray.indexOf(object)<jsonArray.size()-1){
|
||||
deliveryNum+=",";
|
||||
}
|
||||
}
|
||||
ExpTopgpLog expTopgpLog=new ExpTopgpLog();
|
||||
expTopgpLog.setRequestId(contentJson.getString("requestId"));
|
||||
expTopgpLog.setRequestType("topgpSigned");
|
||||
expTopgpLog.setExpressNumber(contentJson.getString("expressNum"));
|
||||
expTopgpLog.setRequestStr(contentJson.toString());
|
||||
expTopgpLog.setDeliveryNumber(deliveryNum);
|
||||
expTopgpLog.setRequestTime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
|
||||
expTopgpLog.setResponseCode("200");
|
||||
expTopgpLog.setResponseStr(returnStr);
|
||||
expTopgpLogService.insertExpTopgpLog(expTopgpLog);
|
||||
|
||||
//返回TOPGP json字符串
|
||||
return retrunStr;
|
||||
//返回处理结果给Topgp
|
||||
return returnStr;
|
||||
|
||||
}
|
||||
|
||||
public JSONObject SendRequestToTopgp( String url,String tip,Map<String,Object> map) {
|
||||
String param = TopgpXmlUtils.GetTopgpRequestXml(tip, map);
|
||||
String returnXml = HttpUtils.sendXmlPost(url, param);
|
||||
return TopgpXmlUtils.GetStatusFromTopgpResponse(returnXml);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理快递100订阅的快递推送信息,并返回响应结果
|
||||
*
|
||||
|
|
@ -247,7 +277,7 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public SubscribeResp ExpressSubscribeCallBackUrl(HttpServletRequest request) {
|
||||
public SubscribeResp ExpressSubscribeCallBackUrl(HttpServletRequest request,String salt) {
|
||||
//如果推送信息中没有包含
|
||||
if(StringUtils.isEmpty(request.getParameter("param"))
|
||||
|| StringUtils.isEmpty(request.getParameter("sign"))) {
|
||||
|
|
@ -260,9 +290,7 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
|
||||
String param= request.getParameter("param");
|
||||
String sign = request.getParameter("sign");
|
||||
//log.debug("快递100订阅推送回调结果|{}|{}",param,sign);
|
||||
//订阅时传的salt
|
||||
String salt = "bpsemi";
|
||||
|
||||
String ourSign = SignUtils.sign(param + salt);
|
||||
SubscribeResp subscribeResp = new SubscribeResp();
|
||||
subscribeResp.setResult(Boolean.TRUE);
|
||||
|
|
@ -277,56 +305,19 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
|
||||
SubscribePushParamResp subscribePushParamResp=JSONObject.parseObject(param,SubscribePushParamResp.class);
|
||||
SubscribePushResult subscribePushResult = subscribePushParamResp.getLastResult();
|
||||
//快递单号
|
||||
String nu = subscribePushResult.getNu();
|
||||
|
||||
//监控状态 (polling:监控中,shutdown:结束,abort:中止,updateall:重新推送。其中当快递单为已签收时status=shutdown)
|
||||
String status= subscribePushParamResp.getStatus();
|
||||
if(status.equals("abort")){
|
||||
if(subscribePushParamResp.getStatus().equals("abort")){
|
||||
//todo
|
||||
//当message为“3天查询无记录”或“60天无变化时”status= abort ,对于status=abort的状态的处理逻辑
|
||||
//将Abort信息存档。然后预警
|
||||
|
||||
}
|
||||
//如果是快递100推送的快递单状态为签收(state=3),并且为TOPGP订阅
|
||||
//快递单当前状态 (0在途,1揽收,2疑难,3签收,4退签,5派件,6退回,7转单,10待清关,11清关中,12已清关,13清关异常,14收件人拒签)
|
||||
String state = subscribePushResult.getState();
|
||||
|
||||
//处理签收逻辑
|
||||
//如果是快递100推送的快递单状态为签收(state=3),并且TOPGP未反馈该快递单已被签收
|
||||
if(state.equals("3")) {
|
||||
//如果该快递信息没有推送给TOPGP且TOPGP已反馈生成签收单成功记录,则推送给TOPGP
|
||||
ExpTopgpLog expTopgpLog=new ExpTopgpLog();
|
||||
expTopgpLog.setExpressNumber(subscribePushResult.getNu());
|
||||
expTopgpLog.setRequestType("toTopgp");
|
||||
expTopgpLog.setResponseCode("200");
|
||||
List<ExpTopgpLog> expTopgpLogList= expTopgpLogService.selectExpTopgpLogList(expTopgpLog);
|
||||
if(null==expTopgpLogList || expTopgpLogList.size()<1){
|
||||
Map<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("expressNum", subscribePushResult.getNu());
|
||||
requestMap.put("expressCom", subscribePushResult.getCom());
|
||||
requestMap.put("expressState", subscribePushResult.getState());
|
||||
|
||||
//一个快递单号,对应多个出货单请求?
|
||||
|
||||
|
||||
//调用topgp Webservice接口
|
||||
//topgp返回的?
|
||||
JSONObject jsonObject= SendRequestToTopgp(webserviceUrl, "express_testRequest",requestMap);
|
||||
log.info(jsonObject.toJSONString());
|
||||
if(jsonObject.getString("returnCode").equals("200")){
|
||||
//一个快递单号对应多个出货单号怎么处理?如果有多个出货单号,部分已签收,部分未签收又怎么处理? 如果推送到ERP时,ERP已经人工生成签收单了,又该怎么处理?
|
||||
|
||||
|
||||
if(subscribePushResult.getState().equals("3") && salt.equals("topgp")) {
|
||||
pushExpressInfoToTopgp(subscribePushResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//将快递流转状态存入数据库
|
||||
expSubsPushRespService.insertExpSubsPushResp(ToExpSubsPushResp(subscribePushParamResp)); //无论数据库中存在快递单号+快递公司编码,都更新数据库 210809 yangbo 修正
|
||||
|
||||
|
|
@ -346,11 +337,40 @@ public class ExpSubsPushApiServiceImpl implements IExpSubsPushApiService {
|
|||
//如果数据库中没有快递单号+快递公司编码,则更插入新记录
|
||||
expSubsPushRespService.insertExpSubsPushResp(ToExpSubsPushResp(subscribePushParamResp));
|
||||
}*/
|
||||
|
||||
|
||||
return subscribeResp;
|
||||
}
|
||||
|
||||
//根据快递100推送的快递信息,推送给TOPGP,并将TOPGP返回信息记录到exp_topgp_log表
|
||||
private void pushExpressInfoToTopgp(SubscribePushResult subscribePushResult){
|
||||
Map<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("requestId","toTopgp"+LocalDateTime.now()); //生成推送requestId
|
||||
requestMap.put("expressNum", subscribePushResult.getNu());
|
||||
requestMap.put("expressCom", subscribePushResult.getCom());
|
||||
requestMap.put("expressState", subscribePushResult.getState());
|
||||
|
||||
//将签收信息推送给TOPGP,让TOPGP处理签收
|
||||
String returnXml = HttpUtils.sendXmlPost(webserviceUrl, TopgpXmlUtils.GetTopgpRequestXml("express_testRequest", requestMap));
|
||||
JSONObject jsonObject = TopgpXmlUtils.TopgpResponseXmlToJson(returnXml);
|
||||
log.info(jsonObject.toJSONString());
|
||||
|
||||
//记录本次TOPGP订阅请求的Log
|
||||
ExpTopgpLog expTopgpLog=new ExpTopgpLog();
|
||||
expTopgpLog.setRequestId(requestMap.get("requestId").toString());
|
||||
expTopgpLog.setRequestType("toTopgp");
|
||||
expTopgpLog.setExpressNumber(requestMap.get("expressNum").toString());
|
||||
expTopgpLog.setRequestStr(JSONObject.toJSONString(requestMap));
|
||||
expTopgpLog.setRequestTime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
|
||||
JSONObject object = jsonObject.getJSONObject("execution");
|
||||
expTopgpLog.setResponseCode(object.getString("code"));
|
||||
expTopgpLog.setResponseStr(returnXml);
|
||||
//插入TOPGPLOG数据库
|
||||
expTopgpLogService.insertExpTopgpLog(expTopgpLog);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将快递100推送的信息转换为ExpSubsPushResp
|
||||
* @param subscribePushParamResp
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@
|
|||
sortName: "requesttime", //不要用驼峰式变量requestTime,mybatis会转换成request_time
|
||||
sortOrder: "desc",
|
||||
modalName: "ERP订阅推送日志",
|
||||
escape: true,
|
||||
columns: [{
|
||||
checkbox: true
|
||||
},
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class XmlWebserviceController {
|
|||
String param = TopgpXmlUtils.GetTopgpRequestXml("express_testRequest", map);
|
||||
String url = "http://192.168.2.81:85/web/ws/r/aws_ttsrv2_toptest";
|
||||
String returnXml = HttpUtils.sendXmlPost(url,param);
|
||||
return TopgpXmlUtils.GetStatusFromTopgpResponse(returnXml).toString();
|
||||
return TopgpXmlUtils.TopgpResponseXmlToJson(returnXml).toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import org.json.XML;
|
||||
|
|
@ -44,7 +45,7 @@ public class TopgpXmlUtils {
|
|||
" </RequestContent>\n" +
|
||||
" </Request>\n" +
|
||||
" </tip:request>\n" +
|
||||
" </tip:express_testRequest>\n" +
|
||||
" </tip:"+tip+">\n" +
|
||||
" </soapenv:Body>\n" +
|
||||
"</soapenv:Envelope>");
|
||||
log.info("=======生成xml结束======");
|
||||
|
|
@ -52,19 +53,102 @@ public class TopgpXmlUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 将TOPGP返回的XML转化为Json,并提出返回Status
|
||||
* @param TopgpResponseXml 调用TOPGP的Webservice的方法名 如:express_testRequest
|
||||
* 将TOPGP返回的XML转化为Json
|
||||
* @param topgpResponseXml
|
||||
* @return Status JsonObject
|
||||
*/
|
||||
public static JSONObject GetStatusFromTopgpResponse(String TopgpResponseXml) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(XML.toJSONObject(TopgpResponseXml).toString());
|
||||
JSONObject envelope = jsonObject.getJSONObject("SOAP-ENV:Envelope");
|
||||
JSONObject body = envelope.getJSONObject("SOAP-ENV:Body");
|
||||
JSONObject express_testResponse = body.getJSONObject("fjs1:express_testResponse");
|
||||
JSONObject fjs1Response = express_testResponse.getJSONObject("fjs1:response");
|
||||
JSONObject response = fjs1Response.getJSONObject("Response");
|
||||
JSONObject execution = response.getJSONObject("Execution");
|
||||
return execution.getJSONObject("Status");
|
||||
public static JSONObject TopgpResponseXmlToJson(String topgpResponseXml) {
|
||||
//String xmlString= TopgpResponseTestXml(); //开发测试用xml
|
||||
String xmlString =XML.toJSONObject(topgpResponseXml).toString();
|
||||
JSONObject xmlJson = JSONObject.parseObject(xmlString);
|
||||
JSONObject response = xmlJson.getJSONObject("SOAP-ENV:Envelope")
|
||||
.getJSONObject("SOAP-ENV:Body").getJSONObject("fjs1:express_testResponse")
|
||||
.getJSONObject("fjs1:response").getJSONObject("Response");
|
||||
|
||||
JSONObject returnJsonObject=new JSONObject();
|
||||
|
||||
if(StringUtils.isNotEmpty(response.getString("ResponseContent"))){
|
||||
JSONObject responseContent = response.getJSONObject("ResponseContent");
|
||||
if(StringUtils.isNotEmpty(responseContent.getString("Parameter"))){
|
||||
JSONObject parameter=responseContent.getJSONObject("Parameter");
|
||||
if(StringUtils.isNotEmpty(parameter.getString("Record"))){
|
||||
JSONObject record= parameter.getJSONObject("Record");
|
||||
if(StringUtils.isNotEmpty(record.getString("Field"))){
|
||||
returnJsonObject.put("Parameter",parameter.getJSONObject("Record").getJSONObject("Field")); //回传参数资料
|
||||
}
|
||||
}
|
||||
}else {
|
||||
returnJsonObject.put("Parameter",""); //回传参数资料
|
||||
}
|
||||
if(StringUtils.isNotEmpty(responseContent.getString("Document"))){
|
||||
JSONObject document= responseContent.getJSONObject("Document");
|
||||
if(StringUtils.isNotEmpty(document)){
|
||||
returnJsonObject.put("document",document.getJSONObject("RecordSet")); //回传单据的单头单身资料
|
||||
}
|
||||
}else {
|
||||
returnJsonObject.put("document","");
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotEmpty(response.getJSONObject("Execution"))){
|
||||
if(response.getJSONObject("Execution").containsKey("Status")){
|
||||
returnJsonObject.put("execution",response.getJSONObject("Execution").getJSONObject("Status")); //服务执行结果
|
||||
}else {
|
||||
returnJsonObject.put("execution","");
|
||||
}
|
||||
}
|
||||
return returnJsonObject;
|
||||
}
|
||||
|
||||
//TOPGP返回XML的标准格式,开发时可使用该XML进行测试。
|
||||
private static String TopgpResponseTestXml(){
|
||||
return "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
|
||||
" <SOAP-ENV:Body>\n" +
|
||||
" <fjs1:express_testResponse xmlns:fjs1=\"http://www.dsc.com.tw/tiptop/TIPTOPServiceGateWay\">\n" +
|
||||
" <fjs1:response>\n" +
|
||||
"<Response>\n" +
|
||||
" <Execution>\t<!-- 服务执行结果 -->\n" +
|
||||
" <Status code=\"0\" sqlcode=\"0\" description=\"\"/>\n" +
|
||||
" </Execution> \n" +
|
||||
" <ResponseContent>\n" +
|
||||
" <Parameter>\t<!-- 参数资料回传 -->\n" +
|
||||
" <Record>\n" +
|
||||
" <Field name=\"my_parameter\" value=\"my_value\"/>\n" +
|
||||
" </Record>\n" +
|
||||
" </Parameter> \n" +
|
||||
" <Document>\t<!—单据资料回传(单头单身) -->\n" +
|
||||
" <RecordSet id=\"1\">\n" +
|
||||
" <Master name=\"my_name\"> \n" +
|
||||
" <Record>\n" +
|
||||
" <Field name=\"my_column\" value=\"my_value\"/>\n" +
|
||||
" </Record>\n" +
|
||||
" </Master>\n" +
|
||||
" <Detail name=\"my_name\">\n" +
|
||||
" <Record>\n" +
|
||||
" <Field name=\"my_column\" value=\"my_value\"/>\n" +
|
||||
" <Field name=\"my_column1\" value=\"my_value1\"/>\n" +
|
||||
" </Record>\n" +
|
||||
" </Detail>\n" +
|
||||
" </RecordSet> \n" +
|
||||
" <RecordSet id=\"2\">\n" +
|
||||
" <Master name=”my_name”> \n" +
|
||||
" <Record>\n" +
|
||||
" <Field name=\"my_column\" value=\"my_value\"/>\n" +
|
||||
" </Record>\n" +
|
||||
" </Master>\n" +
|
||||
" <Detail name=”my_name”>\n" +
|
||||
" <Record>\n" +
|
||||
" <Field name=\"my_column\" value=\"my_value\"/>\n" +
|
||||
" <Field name=\"my_column1\" value=\"my_value1\"/>\n" +
|
||||
" </Record>\n" +
|
||||
" </Detail>\n" +
|
||||
" </RecordSet>\n" +
|
||||
" </Document>\n" +
|
||||
" </ResponseContent>\n" +
|
||||
"</Response>\n" +
|
||||
"</fjs1:response>\n" +
|
||||
" </fjs1:express_testResponse>\n" +
|
||||
" </SOAP-ENV:Body>\n" +
|
||||
"</SOAP-ENV:Envelope>";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue