soap Xml格式拼接和解析代码总结

 soap格式拼接和解析

import cn.hutool.json.XML;

public class SoapUtils {
    /**
     * 拼接发送的xml
     *
     * @param key
     * @param params
     * @param serviceType
     */
    public static String soapCreate(String key,String params,String serviceType){
        String soap="<soapenv:Envelope "+"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "+
                "xmlns:web=\"http://webservice.bjzcyy.cn/\">"+"<soapenv:Header/>"+"<soapenv:Body>"+"<web:ERPInterface>"
                +"<Key>"+key+"</Key>"+"<Params>"+params+"</Params>"+"<serviceType>"+serviceType+"</serviceType>"
                +"</web:ERPInterface>"+"</soapenv:Body>"+"</soapenv:Envelope>";
        return soap;
    }

    /**
     * 解析soap得到flag
     * @param soapResponse
     */
    public static String getFlagBySoap(String soapResponse){
        cn.hutool.json.JSONObject xmlJSONObj = XML.toJSONObject(soapResponse);

        String s=xmlJSONObj.getJSONObject("soap:Envelope").getJSONObject("soap:Body").getJSONObject("ns2:ERPInterfaceResponse")
                .getJSONObject("return").get("flag").toString();
        return s;
    }
}

猜你喜欢

转载自blog.csdn.net/damoneric_guo/article/details/115463720