构建了1个xstreambean 用于把 支付宝单笔交易查询接口返回的XML信息 解析成 这个java对象,方便使用。
返回数据可能是:
<alipay>
<is_success>T</is_success>
<request>
<param name="_input_charset">utf-8</param>
<param name="service">single_trade_query</param>
<param name="partner">20889010000000</param>
<param name="out_trade_no">7_20130223150319_26</param>
</request>
<response>
<trade>
<body>北京-7_20130223150319_26</body>
<buyer_email>xx@126.com</buyer_email>
<buyer_id>208812311290894</buyer_id>
<coupon_used_fee>0.00</coupon_used_fee>
<discount>0.00</discount>
<flag_trade_locked>0</flag_trade_locked>
<gmt_create>2013-02-17 15:04:58</gmt_create>
<gmt_last_modified_time>
2013-02-17 15:05:09
</gmt_last_modified_time>
<gmt_payment>2013-02-17 15:05:09</gmt_payment>
<is_total_fee_adjust>F</is_total_fee_adjust>
<operator_role>B</operator_role>
<out_trade_no>7_20130223150319_26</out_trade_no>
<payment_type>1</payment_type>
<price>0.01</price>
<quantity>1</quantity>
<seller_email>zhifubao008@china.cn</seller_email>
<seller_id>2088901059369309</seller_id>
<subject>北京-7_20130223150319_26</subject>
<to_buyer_fee>0.00</to_buyer_fee>
<to_seller_fee>0.01</to_seller_fee>
<total_fee>0.01</total_fee>
<trade_no>2013022356736989</trade_no>
<trade_status>TRADE_SUCCESS</trade_status>
<use_coupon>F</use_coupon>
</trade>
</response>
<sign>6c472babf7bd98ascb97fee1666a3303</sign>
<sign_type>MD5</sign_type>
</alipay>
也可能是:
<alipay>
<is_success>F</is_success>
<error>xxxx</error>
</alipay>
package
com.alipay.xml.parse;
import
java.util.List;
import
com.thoughtworks.xstream.annotations.XStreamAlias;
import
com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import
com.thoughtworks.xstream.annotations.XStreamImplicit;
/**
* @author Songjian
@H_
403_104@
*
* Feb 23,2013
*/
@XStreamAlias
(
"alipay"
)
public
class
Alipay {
@XStreamAlias
(
"is_success"
)
private
String isSuccess;
@XStreamAlias
(
"error"
)
private
String error;
@XStreamAlias
(
"request"
)
private
Request request;
@XStreamAlias
(
"response"
)
private
Response response;
public
static
class
Request{
@XStreamImplicit
(itemFieldName=
"param"
)
private
List<Param> param;
public
List<Param> getParam() {
return
param;
}
public
void
setParam(List<Param> param) {
this
.param = param;
}
}
@XStreamAlias
(
"param"
)
public
static
class
Param{
@XStreamAsAttribute
private
String name;
public
String getName() {
return
name;
}
public
void
setName(String name) {
this
.name = name;
}
}
public
static
class
Response{
@XStreamAlias
(
"trade"
)
private
Rrade rrade;
public
Rrade getRrade() {
return
rrade;
}
public
void
setRrade(Rrade rrade) {
this
.rrade = rrade;
}
}
public
static
class
Rrade{
@XStreamAlias
(
"body"
)
private
String body;
@XStreamAlias
(
"buyer_email"
)
private
String buyer_email;
@XStreamAlias
(
"buyer_id"
)
private
String buyer_id;
@XStreamAlias
(
"coupon_used_fee"
)
private
String coupon_used_fee;
@XStreamAlias
(
"discount"
)
private
String discount;
@XStreamAlias
(
"flag_trade_locked"
)
private
String flag_trade_locked;
@XStreamAlias
(
"gmt_create"
)
private
String gmt_create;
@XStreamAlias
(
"gmt_last_modified_time"
)
private
String gmt_last_modified_time;
@XStreamAlias
(
"gmt_payment"
)
private
String gmt_payment;
@XStreamAlias
(
"is_total_fee_adjust"
)
private
String is_total_fee_adjust;
@XStreamAlias
(
"operator_role"
)
private
String operator_role;
@XStreamAlias
(
"out_trade_no"
)
private
String out_trade_no;
@XStreamAlias
(
"payment_type"
)
private
String payment_type;
@XStreamAlias
(
"price"
)
private
String price;
@XStreamAlias
(
"quantity"
)
private
String quantity;
@XStreamAlias
(
"seller_email"
)
private
String seller_email;
@XStreamAlias
(
"seller_id"
)
private
String seller_id;
@XStreamAlias
(
"subject"
)
private
String subject;
@XStreamAlias
(
"to_buyer_fee"
)
private
String to_buyer_fee;
@XStreamAlias
(
"to_seller_fee"
)
private
String to_seller_fee;
@XStreamAlias
(
"total_fee"
)
private
String total_fee;
@XStreamAlias
(
"trade_no"
)
private
String trade_no;
@XStreamAlias
(
"trade_status"
)
private
String trade_status;
@XStreamAlias
(
"use_coupon"
)
private
String use_coupon;
public
String getBody() {
return
body;
}
public
void
setBody(String body) {
this
.body = body;
}
public
String getBuyer_email() {
return
buyer_email;
}
public
void
setBuyer_email(String buyer_email) {
this
.buyer_email = buyer_email;
}
public
String getBuyer_id() {
return
buyer_id;
}
public
void
setBuyer_id(String buyer_id) {
this
.buyer_id = buyer_id;
}
public
String getCoupon_used_fee() {
return
coupon_used_fee;
}
public
void
setCoupon_used_fee(String coupon_used_fee) {
this
.coupon_used_fee = coupon_used_fee;
}
public
String getDiscount() {
return
discount;
}
public
void
setDiscount(String discount) {
this
.discount = discount;
}
public
String getFlag_trade_locked() {
return
flag_trade_locked;
}
public
void
setFlag_trade_locked(String flag_trade_locked) {
this
.flag_trade_locked = flag_trade_locked;
}
public
String getGmt_create() {
return
gmt_create;
}
public
void
setGmt_create(String gmt_create) {
this
.gmt_create = gmt_create;
}
public
String getGmt_last_modified_time() {
return
gmt_last_modified_time;
}
public
void
setGmt_last_modified_time(String gmt_last_modified_time) {
this
.gmt_last_modified_time = gmt_last_modified_time;
}
public
String getGmt_payment() {
return
gmt_payment;
}
public
void
setGmt_payment(String gmt_payment) {
this
.gmt_payment = gmt_payment;
}
public
String getIs_total_fee_adjust() {
return
is_total_fee_adjust;
}
public
void
setIs_total_fee_adjust(String is_total_fee_adjust) {
@H_604_1
502@
this
.is_total_fee_adjust = is_total_fee_adjust;