From 38959f821a29ff63c3dd84394d346c4340b695ea Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 22 Mar 2020 14:37:32 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20#1455=20=E4=BF=AE=E5=A4=8D=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E6=94=AF=E4=BB=98=E5=88=86=E8=B4=A6=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E4=BA=BA=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B9=B6=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfitSharingQueryResult.java | 20 +++++-- .../impl/ProfitSharingServiceImpl.java | 1 + .../ProfitSharingQueryResultTest.java | 59 +++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResultTest.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResult.java index 49fdf7455..e52cde946 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResult.java @@ -4,12 +4,15 @@ import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import com.thoughtworks.xstream.annotations.XStreamAlias; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import org.w3c.dom.Document; +import java.util.List; + /** * @author Wang GuangXin 2019/10/22 15:51 * @version 1.0 @@ -49,7 +52,11 @@ public class ProfitSharingQueryResult extends BaseWxPayResult { * 分账接收方列表 */ @XStreamAlias("receivers") - private String receivers; + private String receiversJson; + /** + * 分账接收方列表json转换后的对象 + */ + private List receivers; /** * 分账金额 */ @@ -61,11 +68,14 @@ public class ProfitSharingQueryResult extends BaseWxPayResult { @XStreamAlias("description") private String description; - public ProfitSharingQueryResult.Receivers formatReceivers() { + public List formatReceivers() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); Gson gson = gsonBuilder.create(); - return gson.fromJson(receivers, Receivers.class); + final List receivers = gson.fromJson(receiversJson, new TypeToken>() { + }.getType()); + this.receivers = receivers; + return receivers; } @Override @@ -75,13 +85,13 @@ public class ProfitSharingQueryResult extends BaseWxPayResult { orderId = readXMLString(d, "orderId"); status = readXMLString(d, "status"); closeReason = readXMLString(d, "close_reason"); - receivers = readXMLString(d, "receivers"); + receiversJson = readXMLString(d, "receivers"); amount = readXMLInteger(d, "amount"); description = readXMLString(d, "description"); } @Data - public class Receivers { + public class Receiver { /** * 分账接收方类型 */ diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImpl.java index 09e305d19..105532099 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImpl.java @@ -81,6 +81,7 @@ public class ProfitSharingServiceImpl implements ProfitSharingService { String responseContent = this.payService.post(url, request.toXML(), true); ProfitSharingQueryResult result = BaseWxPayResult.fromXML(responseContent, ProfitSharingQueryResult.class); + result.formatReceivers(); result.checkResult(this.payService, request.getSignType(), true); return result; } diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResultTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResultTest.java new file mode 100644 index 000000000..386101fed --- /dev/null +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResultTest.java @@ -0,0 +1,59 @@ +package com.github.binarywang.wxpay.bean.profitsharing; + +import org.testng.annotations.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * 测试. + * + * @author Binary Wang + * @date 2020-03-22 + */ +@Test +public class ProfitSharingQueryResultTest { + + @Test + public void testFormatReceivers() { + ProfitSharingQueryResult result = new ProfitSharingQueryResult(); + result.setReceiversJson("[\n" + + "{\n" + + "\"type\": \"MERCHANT_ID\",\n" + + "\"account\":\"190001001\",\n" + + "\"amount\":100,\n" + + "\"description\": \"分到商户\",\n" + + "\"result\": \"SUCCESS\",\n" + + "\"finish_time\": \"20180608170132\"\n" + + "},\n" + + "{\n" + + "\"type\": \"PERSONAL_WECHATID\",\n" + + "\"account\":\"86693952\",\n" + + "\"amount\":888,\n" + + "\"description\": \"分到个人\",\n" + + "\"result\": \"SUCCESS\",\n" + + "\"finish_time\": \"20180608170132\"\n" + + "}\n" + + "]"); + + List receivers = result.formatReceivers(); + assertThat(receivers).isNotEmpty(); + + assertThat(receivers.get(0)).isNotNull(); + assertThat(receivers.get(0).getType()).isEqualTo("MERCHANT_ID"); + assertThat(receivers.get(0).getAccount()).isEqualTo("190001001"); + assertThat(receivers.get(0).getAmount()).isEqualTo(100); + assertThat(receivers.get(0).getDescription()).isEqualTo("分到商户"); + assertThat(receivers.get(0).getResult()).isEqualTo("SUCCESS"); + assertThat(receivers.get(0).getFinishTime()).isEqualTo("20180608170132"); + + assertThat(receivers.get(1)).isNotNull(); + assertThat(receivers.get(1).getType()).isEqualTo("PERSONAL_WECHATID"); + assertThat(receivers.get(1).getAccount()).isEqualTo("86693952"); + assertThat(receivers.get(1).getAmount()).isEqualTo(888); + assertThat(receivers.get(1).getDescription()).isEqualTo("分到个人"); + assertThat(receivers.get(1).getResult()).isEqualTo("SUCCESS"); + assertThat(receivers.get(1).getFinishTime()).isEqualTo("20180608170132"); + } +}