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 = "" + " " + " " + " " + " Y" + " " + " " + " <?xml version=\"1.0\" encoding=\"utf-8\"?><document><et_headers type=\"h\"><et_header idx=\"1\"><zzasn>9311031471</zzasn><zzasn_type>BL</zzasn_type><imclr></imclr><lifnr>0000177301</lifnr><vendor_name>浙江小步出行有限公司</vendor_name><zzship_addr>测试</zzship_addr><zzship_name>11</zzship_name><zzship_phon>1111</zzship_phon><zzship_date>2025-04-01</zzship_date><zzwarehouse_id>0000017560</zzwarehouse_id><zzwarehouse>中小件-北京中心仓</zzwarehouse><zzreceive_addr>北京市大兴区经济开发区科创十街十五号(亦庄小米产业园)T1楼1层</zzreceive_addr><zzcarrier></zzcarrier><zzdriver_name></zzdriver_name><zzdriver_phon></zzdriver_phon><zzarrive_time>20250402</zzarrive_time><zzarrive_time1>00:00:00</zzarrive_time1><zzcarrier_no></zzcarrier_no><road_transport_no></road_transport_no><zztrans_model></zztrans_model><zzdriver_license></zzdriver_license><zzlicense_numb></zzlicense_numb><zzseal_no></zzseal_no><zzcanceled></zzcanceled><ship_email>11@163.com</ship_email><lifnr_dg></lifnr_dg><short_name></short_name><reserve_date></reserve_date><reserve_time></reserve_time><bukrs>1110</bukrs><asn_desc></asn_desc><price_stat></price_stat><final_contact></final_contact><final_phone></final_phone><final_addr></final_addr><final_company></final_company><status>S002</status><status_sn></status_sn><purchase_mode></purchase_mode><hub_lifnr></hub_lifnr><items type=\"h\"><item idx=\"1\"><zzasn>9311031471</zzasn><zzitem_id>0000000010</zzitem_id><zzpo_no>4500173648</zzpo_no><zzpo_item_id>0000000010</zzpo_item_id><zzreqnr></zzreqnr><zzreqln></zzreqln><zzproduct_id>950102000010</zzproduct_id><zzvproduct_id></zzvproduct_id><zzsku>BHR4008CN</zzsku><zzquantity>5.000</zzquantity><zzunit>ST</zzunit><brand></brand><place></place><brand_type></brand_type><is_identification></is_identification><zzopen_qty>5.000</zzopen_qty><changed_at>20250401071304</changed_at><created_at>20250401071304</created_at><app_models>11-AD</app_models><ext_doc_no>8897300</ext_doc_no><ext_doc_item>2884654</ext_doc_item><address_detail>北京市大兴区经济开发区科创十街十五号(亦庄小米产业园)T1楼1层</address_detail><batch_id></batch_id><batch_row></batch_row><xmsto_no></xmsto_no><xmsto_item_no></xmsto_item_no><modelnumber></modelnumber><shipment_id></shipment_id><shipmentid_num>0</shipmentid_num><maktx>米家智能侧吸油烟机</maktx><bednr></bednr><ware_type_from></ware_type_from><ware_type_to></ware_type_to><act_gr_qty>0.000</act_gr_qty><pn_matnr_l></pn_matnr_l><pn_matnr_name></pn_matnr_name></item></items><box_items type=\"h\"></box_items><box_sums type=\"h\"></box_sums><purchase_mode2></purchase_mode2><receiver>杨丹丹,周晨光</receiver><receive_phone>18811578183,13002157815</receive_phone><receive_addr>北京市大兴区经济开发区科创十街十五号(亦庄小米产业园)T1楼1层</receive_addr><receive_warehouse_id>0000017560</receive_warehouse_id><receive_warehouse_short>中小件-北京中心仓</receive_warehouse_short><product_type>GM</product_type><ekorg>2120</ekorg><ekotx></ekotx><stock_org_from></stock_org_from><stock_org_from_desc></stock_org_from_desc><stock_org_to>MI_IOT</stock_org_to><stock_org_to_desc>生态链库存组织(IOT)</stock_org_to_desc><migo_type></migo_type><zrproject>A1</zrproject><logistics_no></logistics_no><logistics_company></logistics_company><last4_phone_number></last4_phone_number><logistics_company_name></logistics_company_name><business_model></business_model></et_header></et_headers><ev_message></ev_message><ev_msgty>S</ev_msgty></document>" + " " + " " + ""; 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 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(""); int end = xml.indexOf("", start); if (start == -1 || end == -1) return null; return xml.substring(start + 9, end).trim(); } private String decodeXmlEntities(String xml) { return xml.replace("<", "<") .replace(">", ">") .replace("<", "<") .replace(">", ">") .replace("&", "&"); } private String extractCdata(String xml) { int cdataStart = xml.indexOf(""); int cdataEnd = xml.indexOf("", cdataStart); if (cdataStart == -1 || cdataEnd == -1) return null; return xml.substring(cdataStart + 11, cdataEnd).trim(); } }