diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java index 373497f3..150cac38 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.bean.pay.result; import com.google.common.collect.Lists; import com.thoughtworks.xstream.annotations.XStreamAlias; +import io.restassured.path.xml.XmlPath; import java.util.List; @@ -17,6 +18,7 @@ import java.util.List; *
代金券类型 - * coupon_type_$n - * 否 - * String - * CASH - *
代金券ID - * coupon_id_$n - * 否 - * String(20) - * 10000 - * 代金券ID, $n为下标,从0开始编号 - *- */ - private String couponId; - - /** - *
单个代金券支付金额 - * coupon_fee_$n - * 否 - * Int - * 100 - * 单个代金券支付金额, $n为下标,从0开始编号 - *- */ - private Integer couponFee; - - public Coupon(String couponType, String couponId, Integer couponFee) { - this.couponType = couponType; - this.couponId = couponId; - this.couponFee = couponFee; - } - - public String getCouponType() { - return this.couponType; - } - - public void setCouponType(String couponType) { - this.couponType = couponType; - } - - public String getCouponId() { - return this.couponId; - } - - public void setCouponId(String couponId) { - this.couponId = couponId; - } - - public Integer getCouponFee() { - return this.couponFee; - } - - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - } - /** *
微信支付订单号
* transaction_id
@@ -259,7 +192,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
*/
@XStreamAlias("transaction_id")
private String transactionId;
-
/**
* 商户订单号
* out_trade_no
@@ -271,7 +203,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
*/
@XStreamAlias("out_trade_no")
private String outTradeNo;
-
/**
* 附加数据
* attach
@@ -283,7 +214,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
*/
@XStreamAlias("attach")
private String attach;
-
/**
* 支付完成时间
* time_end
@@ -295,7 +225,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
*/
@XStreamAlias("time_end")
private String timeEnd;
-
/**
* 交易状态描述
* trade_state_desc
@@ -460,10 +389,86 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
this.tradeStateDesc = tradeStateDesc;
}
- public void composeCoupons(String xmlString){
- if(this.couponCount != null && this.couponCount > 0 ){
+ /**
+ * 通过xml组装coupons属性内容
+ */
+ public void composeCoupons() {
+ if (this.couponCount != null && this.couponCount > 0) {
this.coupons = Lists.newArrayList();
- //TODO 暂时待实现
+ XmlPath xmlPath = new XmlPath(this.getXmlString());
+ for (int i = 0; i < this.couponCount; i++){
+ this.coupons.add(new Coupon(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class),
+ this.getXmlValueIfExists(xmlPath, "xml.coupon_id_" + i, String.class),
+ this.getXmlValueIfExists(xmlPath, "xml.coupon_fee_" + i, Integer.class)));
+ }
+ }
+ }
+
+ public static class Coupon {
+ /**
+ * 代金券类型
+ * coupon_type_$n
+ * 否
+ * String
+ * CASH
+ *
代金券ID + * coupon_id_$n + * 否 + * String(20) + * 10000 + * 代金券ID, $n为下标,从0开始编号 + *+ */ + private String couponId; + + /** + *
单个代金券支付金额 + * coupon_fee_$n + * 否 + * Int + * 100 + * 单个代金券支付金额, $n为下标,从0开始编号 + *+ */ + private Integer couponFee; + + public Coupon(String couponType, String couponId, Integer couponFee) { + this.couponType = couponType; + this.couponId = couponId; + this.couponFee = couponFee; + } + + public String getCouponType() { + return this.couponType; + } + + public void setCouponType(String couponType) { + this.couponType = couponType; } + + public String getCouponId() { + return this.couponId; + } + + public void setCouponId(String couponId) { + this.couponId = couponId; + } + + public Integer getCouponFee() { + return this.couponFee; + } + + public void setCouponFee(Integer couponFee) { + this.couponFee = couponFee; + } + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java new file mode 100644 index 00000000..1582ea17 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java @@ -0,0 +1,65 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + *
+ * Created by Binary Wang on 2017-01-04. + * @author binarywang(Binary Wang) + *+ */ +public class WxPayOrderQueryResultTest { + @Test + public void testComposeCoupons() throws Exception { + /** + * xml样例字符串来自于官方文档,并稍加改造加入了coupon相关的数据便于测试 + */ + String xmlString = "