| | |
| | | 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.service.SoapApiService; |
| | | import com.gs.xiaomi.util.SoapXmlBuilder; |
| | | import okhttp3.*; |
| | | import com.gs.xiaomi.service.XM104Service; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.xml.bind.JAXBContext; |
| | | import javax.xml.bind.JAXBException; |
| | | import javax.xml.bind.Unmarshaller; |
| | | import java.io.IOException; |
| | | import java.io.StringReader; |
| | | |
| | | @SpringBootTest |
| | | class XiaomiApplicationTests { |
| | | |
| | | @Autowired |
| | | private SoapApiService service; |
| | | private XM104Service xm104Service; |
| | | |
| | | @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); |
| | | xm104Service.getDb(); |
| | | } |
| | | |
| | | @Test |
| | | void testService() 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); |
| | | |
| | | BizDocumentResult bizDocumentResult = service.callAndParse(DataAcquisitionConfiguration.XM104_URL, req); |
| | | |
| | | System.out.println(JSON.toJSONString(bizDocumentResult)); |
| | | } |
| | | |
| | | @Test |
| | | void sta() throws IOException, JAXBException { |
| | | OkHttpClient client = new OkHttpClient().newBuilder() |
| | | .build(); |
| | | MediaType mediaType = MediaType.parse("application/xml"); |
| | | RequestBody body = RequestBody.create(mediaType, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\r\n <soapenv:Header/>\r\n <soapenv:Body>\r\n <urn:ZFM_WS_API>\r\n <IV_CODE>VDATA.XM104</IV_CODE>\r\n <IV_EVENT></IV_EVENT>\r\n <IV_FLAG></IV_FLAG>\r\n <IV_INFO><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<document>\r\n <BIZ_DATE>2025-04-01</BIZ_DATE>\r\n <I_LIFNR>177301</I_LIFNR>\r\n</document>]]></IV_INFO>\r\n <IV_PASS>D25932DF5772D0A2DF9620A2A0AB121A</IV_PASS>\r\n <IV_USER>V177301</IV_USER>\r\n </urn:ZFM_WS_API>\r\n </soapenv:Body>\r\n</soapenv:Envelope>"); |
| | | Request request = new Request.Builder() |
| | | .url("https://mipoq.p.mi.com/XISOAPAdapter/MessageServlet?p=ic/9e8a118fb0b7379aa11c2a5c2860982a&senderParty=&senderService=ZJ_XIAOBU_QAS&receiverParty=&receiverService=&interface=SI_ZFM_WS_API_OUT&interfaceNamespace=http://xiaomi.com/srm/b2b") |
| | | .method("POST", body) |
| | | // .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)") |
| | | .addHeader("Content-Type", "application/xml") |
| | | .addHeader("Authorization", "Basic UkZDWkpYSUFPQlU6cHBCOVIhSGU=") |
| | | .addHeader("Accept", "*/*") |
| | | // .addHeader("Host", "mipoq.p.mi.com") |
| | | .addHeader("Connection", "keep-alive") |
| | | // .addHeader("Cookie", "saplb_*=(J2EE4281420)4281450; MYSAPSSO2=AjExMDAgABJwb3J0YWw6UkZDWkpYSUFPQlWIAAdkZWZhdWx0AQALUkZDWkpYSUFPQlUCAAMwMDADAANQT1EEAAwyMDI1MDQwOTAwMTcFAAQAAAAICgALUkZDWkpYSUFPQlX%2FAQUwggEBBgkqhkiG9w0BBwKggfMwgfACAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHATGB0DCBzQIBATAiMB0xDDAKBgNVBAMTA1BPUTENMAsGA1UECxMESjJFRQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMjUwNDA5MDAxNzU2WjAjBgkqhkiG9w0BCQQxFgQUvvJ1HSnOLckboGYaMR9Wiaem6z4wCQYHKoZIzjgEAwQvMC0CFQDKLPrpUC19VM2gcslWaHAnh7dfxQIUNs2dTxwGcKdNU%2FdAQPs4f08yaw4%3D; JSESSIONID=_6bPldDq9mFJPXEd11bc-GvrWMAVlgFqVEEA_SAPF-GrpRbcuqxMK_gShBYGdmdp; JSESSIONMARKID=nUs7PQMlYui9UqFCm4Z-ZRqUiI8YQ_hLJPJWpUQQA") |
| | | .build(); |
| | | Response response = client.newCall(request).execute(); |
| | | |
| | | if (response.isSuccessful() && response.body() != null) { |
| | | String bodyStr = response.body().string(); |
| | | |
| | | 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(decodedXml)); |
| | | System.out.println(JSON.toJSONString(innerXml)); |
| | | } else { |
| | | throw new RuntimeException("SOAP request failed: " + response.code() + " - " + response.message()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @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><?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></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("<", "<") |
| | | .replace(">", ">") |
| | | .replace("<", "<") |
| | | .replace(">", ">") |
| | | .replace("&", "&"); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | } |