http post xml 表单提交(application/x-www-form-urlencoded)

http post xml 表单提交(application/x-www-form-urlencoded)
原报文
<rminfo>
    <serialid>1</serialid>
    <outserialid>SP1712011545899767809_171201152853818</outserialid>
    <merserialid>1209681201712011377612234</merserialid>
    <paycode>3</paycode>
    <reinfo></reinfo>
    <channelname>**</channelname>
    <productid>1152</productid>
    <productname>QQ钱包JSAPI支付</productname>
    <payfinishedtime>2017-12-01 15:30:58</payfinishedtime>
    <extdata>
         <![CDATA[cardtype=1&cardtypedesc=储蓄卡]]>
</extdata>
    <extxml>
        <openid>
            <![CDATA[51FCF7AB8495CC6AF1D83CF37DAEAF5D]]>
</openid>
        <useraccount>
            <![CDATA[YLiVd8NnAGa+CAk3HoJu7M4GEnula+WfQSqPUpCkD+2e6+k55wK/Qw==]]>
</useraccount>
        <bankinfo>
            <shortname>CITIC</shortname>
            <bankname>中信银行</bankname>
            <cardtype>储蓄卡</cardtype>
        </bankinfo>
    </extxml>
    <projectorder>SP1712011524306335970445899767809</projectorder>
    <projectcode>70</projectcode>
    <financecode>081001144123040103187210044139115002056164073004</financecode>
    <paymentcount>0</paymentcount>
    <unionorder>SP1712011524306335970445899767809</unionorder>
    <operationtype>1</operationtype>
    <reduceamount></reduceamount>
    <awardamount></awardamount>
    <realamount>22.00</realamount>
    <companycode>1</companycode>
    <reqcompany>1</reqcompany>
    <ver>0</ver>
    <fromplat>11</fromplat>
</rminfo>
能解决报文中包含等号的问题
@ResponseBody
public String commonPayCallBack( @RequestBody String req){
    BaseResponse response = new BaseResponse();
    try{
        String reqStr = URLDecoder.decode(req,"UTF-8");
        CommonPayCallbackForm request = XmlSerializerHelper.deserialize(reqStr,CommonPayCallbackForm.class);
    }catch(..){..}
}
CommonPayCallbackForm.java
@XSteamAlias("rminfo") //报文头结点
public class CommonPayCallbackFrom extends BaseRequest{
    private static final long serialVersionUID = 1L;
    @XStreamAlias("serialid") //报文原始值
    private String SerialId;  //转化后的值
    @XStreamAlias("outserialid")
    private String outSerialId;
    .....
}
XmlSerializerHelper.java
import com.thoughtworks.xstream.XStream;
public class XmlSerializerHelper implements Serialzer{
    private XStream xstream;
    public static <T> T deserialize(String text,Class<T> clazz){
        XmlSerializerHelper xmlSerializerHelper = new XmlSerializerHelper();
        return xmlSerializerHelper.deserialize(text,class,StringUtils.EMPTY);
    }
    @SuppressWarning("unchecked")
    @Override
    public <T> T deserialize(String text,Class<T> class,String dateFormat){
        xstream.processAnnotations(clazz);
        return (T) xstream.fromXML(text);
    }
}

猜你喜欢

转载自blog.csdn.net/zy52002520/article/details/78706973
今日推荐