啊鑫
2025-04-09 53a8212e781d469369b5418c125c5d3735a77a92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.gs.xiaomi;
 
import com.alibaba.fastjson.JSON;
import com.gs.xiaomi.config.DataAcquisitionConfiguration;
import com.gs.xiaomi.dto.BizDocument;
import com.gs.xiaomi.dto.BizDocumentResult;
import com.gs.xiaomi.dto.ZfmWsApiRequest;
import com.gs.xiaomi.util.SoapXmlBuilder;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
 
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
 
@SpringBootTest
class XiaomiApplicationTests {
 
    @Test
    void contextLoads() throws Exception {
        ZfmWsApiRequest req = new ZfmWsApiRequest();
        req.setIvCode(DataAcquisitionConfiguration.IV_CODEXM104);
        req.setIvEvent("");
        req.setIvFlag("");
        BizDocument doc = new BizDocument();
        doc.setBizDate("2025-04-01");
        doc.setLifnr(DataAcquisitionConfiguration.LIFNR);
        req.setIvInfo(doc);
        req.setIvPass(DataAcquisitionConfiguration.getIvPass(DataAcquisitionConfiguration.IV_CODEXM104));
        req.setIvUser(DataAcquisitionConfiguration.IV_USER);
        String soapXml = SoapXmlBuilder.build(req);
        System.out.println(soapXml);
    }
 
    @Test
    void contextLoads2() throws Exception {
        String bodyStr = "<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>" +
                "  <SOAP:Header/>" +
                "  <SOAP:Body xmlns:urn='urn:sap-com:document:sap:rfc:functions'>" +
                "    <n0:ZFM_WS_APIResponse xmlns:n0='urn:sap-com:document:sap:rfc:functions' xmlns:prx='urn:sap.com:proxy:FRD:/1SAI/TAS82FD47019F21003C052D:752'>" +
                "      <EV_CODE>Y</EV_CODE>" +
                "      <EV_EVENT/>" +
                "      <EV_FLAG/>" +
                "      <EV_RESULT>&#60;?xml version=\"1.0\" encoding=\"utf-8\"?&#62;&#60;document&#62;&#60;et_headers type=\"h\"&#62;&#60;et_header idx=\"1\"&#62;&#60;zzasn&#62;9311031471&#60;/zzasn&#62;&#60;zzasn_type&#62;BL&#60;/zzasn_type&#62;&#60;imclr&#62;&#60;/imclr&#62;&#60;lifnr&#62;0000177301&#60;/lifnr&#62;&#60;vendor_name&#62;浙江小步出行有限公司&#60;/vendor_name&#62;&#60;zzship_addr&#62;测试&#60;/zzship_addr&#62;&#60;zzship_name&#62;11&#60;/zzship_name&#62;&#60;zzship_phon&#62;1111&#60;/zzship_phon&#62;&#60;zzship_date&#62;2025-04-01&#60;/zzship_date&#62;&#60;zzwarehouse_id&#62;0000017560&#60;/zzwarehouse_id&#62;&#60;zzwarehouse&#62;中小件-北京中心仓&#60;/zzwarehouse&#62;&#60;zzreceive_addr&#62;北京市大兴区经济开发区科创十街十五号(亦庄小米产业园)T1楼1层&#60;/zzreceive_addr&#62;&#60;zzcarrier&#62;&#60;/zzcarrier&#62;&#60;zzdriver_name&#62;&#60;/zzdriver_name&#62;&#60;zzdriver_phon&#62;&#60;/zzdriver_phon&#62;&#60;zzarrive_time&#62;20250402&#60;/zzarrive_time&#62;&#60;zzarrive_time1&#62;00:00:00&#60;/zzarrive_time1&#62;&#60;zzcarrier_no&#62;&#60;/zzcarrier_no&#62;&#60;road_transport_no&#62;&#60;/road_transport_no&#62;&#60;zztrans_model&#62;&#60;/zztrans_model&#62;&#60;zzdriver_license&#62;&#60;/zzdriver_license&#62;&#60;zzlicense_numb&#62;&#60;/zzlicense_numb&#62;&#60;zzseal_no&#62;&#60;/zzseal_no&#62;&#60;zzcanceled&#62;&#60;/zzcanceled&#62;&#60;ship_email&#62;11@163.com&#60;/ship_email&#62;&#60;lifnr_dg&#62;&#60;/lifnr_dg&#62;&#60;short_name&#62;&#60;/short_name&#62;&#60;reserve_date&#62;&#60;/reserve_date&#62;&#60;reserve_time&#62;&#60;/reserve_time&#62;&#60;bukrs&#62;1110&#60;/bukrs&#62;&#60;asn_desc&#62;&#60;/asn_desc&#62;&#60;price_stat&#62;&#60;/price_stat&#62;&#60;final_contact&#62;&#60;/final_contact&#62;&#60;final_phone&#62;&#60;/final_phone&#62;&#60;final_addr&#62;&#60;/final_addr&#62;&#60;final_company&#62;&#60;/final_company&#62;&#60;status&#62;S002&#60;/status&#62;&#60;status_sn&#62;&#60;/status_sn&#62;&#60;purchase_mode&#62;&#60;/purchase_mode&#62;&#60;hub_lifnr&#62;&#60;/hub_lifnr&#62;&#60;items type=\"h\"&#62;&#60;item idx=\"1\"&#62;&#60;zzasn&#62;9311031471&#60;/zzasn&#62;&#60;zzitem_id&#62;0000000010&#60;/zzitem_id&#62;&#60;zzpo_no&#62;4500173648&#60;/zzpo_no&#62;&#60;zzpo_item_id&#62;0000000010&#60;/zzpo_item_id&#62;&#60;zzreqnr&#62;&#60;/zzreqnr&#62;&#60;zzreqln&#62;&#60;/zzreqln&#62;&#60;zzproduct_id&#62;950102000010&#60;/zzproduct_id&#62;&#60;zzvproduct_id&#62;&#60;/zzvproduct_id&#62;&#60;zzsku&#62;BHR4008CN&#60;/zzsku&#62;&#60;zzquantity&#62;5.000&#60;/zzquantity&#62;&#60;zzunit&#62;ST&#60;/zzunit&#62;&#60;brand&#62;&#60;/brand&#62;&#60;place&#62;&#60;/place&#62;&#60;brand_type&#62;&#60;/brand_type&#62;&#60;is_identification&#62;&#60;/is_identification&#62;&#60;zzopen_qty&#62;5.000&#60;/zzopen_qty&#62;&#60;changed_at&#62;20250401071304&#60;/changed_at&#62;&#60;created_at&#62;20250401071304&#60;/created_at&#62;&#60;app_models&#62;11-AD&#60;/app_models&#62;&#60;ext_doc_no&#62;8897300&#60;/ext_doc_no&#62;&#60;ext_doc_item&#62;2884654&#60;/ext_doc_item&#62;&#60;address_detail&#62;北京市大兴区经济开发区科创十街十五号(亦庄小米产业园)T1楼1层&#60;/address_detail&#62;&#60;batch_id&#62;&#60;/batch_id&#62;&#60;batch_row&#62;&#60;/batch_row&#62;&#60;xmsto_no&#62;&#60;/xmsto_no&#62;&#60;xmsto_item_no&#62;&#60;/xmsto_item_no&#62;&#60;modelnumber&#62;&#60;/modelnumber&#62;&#60;shipment_id&#62;&#60;/shipment_id&#62;&#60;shipmentid_num&#62;0&#60;/shipmentid_num&#62;&#60;maktx&#62;米家智能侧吸油烟机&#60;/maktx&#62;&#60;bednr&#62;&#60;/bednr&#62;&#60;ware_type_from&#62;&#60;/ware_type_from&#62;&#60;ware_type_to&#62;&#60;/ware_type_to&#62;&#60;act_gr_qty&#62;0.000&#60;/act_gr_qty&#62;&#60;pn_matnr_l&#62;&#60;/pn_matnr_l&#62;&#60;pn_matnr_name&#62;&#60;/pn_matnr_name&#62;&#60;/item&#62;&#60;/items&#62;&#60;box_items type=\"h\"&#62;&#60;/box_items&#62;&#60;box_sums type=\"h\"&#62;&#60;/box_sums&#62;&#60;purchase_mode2&#62;&#60;/purchase_mode2&#62;&#60;receiver&#62;杨丹丹,周晨光&#60;/receiver&#62;&#60;receive_phone&#62;18811578183,13002157815&#60;/receive_phone&#62;&#60;receive_addr&#62;北京市大兴区经济开发区科创十街十五号(亦庄小米产业园)T1楼1层&#60;/receive_addr&#62;&#60;receive_warehouse_id&#62;0000017560&#60;/receive_warehouse_id&#62;&#60;receive_warehouse_short&#62;中小件-北京中心仓&#60;/receive_warehouse_short&#62;&#60;product_type&#62;GM&#60;/product_type&#62;&#60;ekorg&#62;2120&#60;/ekorg&#62;&#60;ekotx&#62;&#60;/ekotx&#62;&#60;stock_org_from&#62;&#60;/stock_org_from&#62;&#60;stock_org_from_desc&#62;&#60;/stock_org_from_desc&#62;&#60;stock_org_to&#62;MI_IOT&#60;/stock_org_to&#62;&#60;stock_org_to_desc&#62;生态链库存组织(IOT)&#60;/stock_org_to_desc&#62;&#60;migo_type&#62;&#60;/migo_type&#62;&#60;zrproject&#62;A1&#60;/zrproject&#62;&#60;logistics_no&#62;&#60;/logistics_no&#62;&#60;logistics_company&#62;&#60;/logistics_company&#62;&#60;last4_phone_number&#62;&#60;/last4_phone_number&#62;&#60;logistics_company_name&#62;&#60;/logistics_company_name&#62;&#60;business_model&#62;&#60;/business_model&#62;&#60;/et_header&#62;&#60;/et_headers&#62;&#60;ev_message&#62;&#60;/ev_message&#62;&#60;ev_msgty&#62;S&#60;/ev_msgty&#62;&#60;/document&#62;</EV_RESULT>" +
                "    </n0:ZFM_WS_APIResponse>" +
                "  </SOAP:Body>" +
                "</SOAP:Envelope>";
 
        String evCode = extractEvCode(bodyStr);
        if (!"Y".equalsIgnoreCase(evCode)) {
            throw new RuntimeException("SOAP business failed, EV_CODE: " + evCode);
        }
 
        String decodedXml = decodeXmlEntities(bodyStr);
 
        String innerXml = extractCdata(decodedXml);
        if (innerXml == null) throw new RuntimeException("No CDATA <document> found in response");
 
 
        JAXBContext context = JAXBContext.newInstance(BizDocumentResult.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        BizDocumentResult unmarshal = (BizDocumentResult) unmarshaller.unmarshal(new StringReader(innerXml));
        System.out.println(JSON.toJSONString(unmarshal));
    }
 
    private String extractEvCode(String xml) {
        int start = xml.indexOf("<EV_CODE>");
        int end = xml.indexOf("</EV_CODE>", start);
        if (start == -1 || end == -1) return null;
        return xml.substring(start + 9, end).trim();
    }
 
    private String decodeXmlEntities(String xml) {
        return xml.replace("&#60;", "<")
                .replace("&#62;", ">")
                .replace("&lt;", "<")
                .replace("&gt;", ">")
                .replace("&amp;", "&");
    }
 
    private String extractCdata(String xml) {
        int cdataStart = xml.indexOf("<EV_RESULT>");
        int cdataEnd = xml.indexOf("</EV_RESULT>", cdataStart);
        if (cdataStart == -1 || cdataEnd == -1) return null;
        return xml.substring(cdataStart + 11, cdataEnd).trim();
    }
 
}