diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingMerchantRatioQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingMerchantRatioQueryRequest.java new file mode 100644 index 000000000..d8b1ff961 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingMerchantRatioQueryRequest.java @@ -0,0 +1,47 @@ +package com.github.binarywang.wxpay.bean.profitsharing; + +import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; +import com.github.binarywang.wxpay.constant.WxPayConstants; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * @author : cofedream + * @date : 2020-12-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@XStreamAlias("xml") +public class ProfitSharingMerchantRatioQueryRequest extends BaseWxPayRequest { + private static final long serialVersionUID = 2773455587673225334L; + + public ProfitSharingMerchantRatioQueryRequest(String subMchId) { + this.subMchId = subMchId; + } + + @Override + protected void checkConstraints() throws WxPayException { + // 目前仅支持HMAC-SHA256. + this.setSignType(WxPayConstants.SignType.HMAC_SHA256); + } + + @Override + public boolean ignoreAppid() { + return true; + } + + @Override + protected boolean ignoreSubAppId() { + return true; + } + + @Override + protected void storeMap(Map map) { + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingMerchantRatioQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingMerchantRatioQueryResult.java new file mode 100644 index 000000000..76e20de6d --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingMerchantRatioQueryResult.java @@ -0,0 +1,32 @@ +package com.github.binarywang.wxpay.bean.profitsharing; + +import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.w3c.dom.Document; + +/** + * @author : cofedream + * @date : 2020-12-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@XStreamAlias("xml") +public class ProfitSharingMerchantRatioQueryResult extends BaseWxPayResult { + /** + * 服务商模式下的子商户号.
+ * 2000
+ * 子商户允许服务商分账的最大比例,单位万分比,比如2000表示20% + */ + @XStreamAlias("max_ratio") + private Integer maxRatio; + + @Override + protected void loadXml(Document d) { + maxRatio = readXmlInteger(d, "max_ratio"); + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingOrderAmountQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingOrderAmountQueryRequest.java new file mode 100644 index 000000000..5718860f9 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingOrderAmountQueryRequest.java @@ -0,0 +1,59 @@ +package com.github.binarywang.wxpay.bean.profitsharing; + +import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; +import com.github.binarywang.wxpay.constant.WxPayConstants; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; +import me.chanjar.weixin.common.annotation.Required; + +import java.util.Map; + +/** + * @author : cofedream + * @date : 2020-12-29 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor +@XStreamAlias("xml") +public class ProfitSharingOrderAmountQueryRequest extends BaseWxPayRequest { + + private static final long serialVersionUID = 6009448187615691627L; + /** + *
+   * 字段名:微信订单号.
+   * 变量名:transaction_id
+   * 是否必填:是
+   * String(32)
+   * 示例值:4208450740201411110007820472
+   * 描述:微信支付订单号
+   * 
+ */ + @XStreamAlias("transaction_id") + @Required + private String transactionId; + + @Override + protected void checkConstraints() throws WxPayException { + // 目前仅支持HMAC-SHA256. + this.setSignType(WxPayConstants.SignType.HMAC_SHA256); + } + + @Override + public boolean ignoreAppid() { + return true; + } + + @Override + protected boolean ignoreSubAppId() { + return true; + } + + @Override + protected void storeMap(Map map) { + map.put("transaction_id", transactionId); + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingOrderAmountQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingOrderAmountQueryResult.java new file mode 100644 index 000000000..5d4093d96 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingOrderAmountQueryResult.java @@ -0,0 +1,37 @@ +package com.github.binarywang.wxpay.bean.profitsharing; + +import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.w3c.dom.Document; + +/** + * @author : cofedream + * @date : 2020-12-29 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@XStreamAlias("xml") +public class ProfitSharingOrderAmountQueryResult extends BaseWxPayResult { + private static final long serialVersionUID = 7355605400662796198L; + /** + * 微信订单号. + */ + @XStreamAlias("transaction_id") + private String transactionId; + /** + * 订单剩余待分金额. + */ + @XStreamAlias("unsplit_amount") + private Integer unSplitAmount; + + @Override + protected void loadXml(Document d) { + transactionId = readXmlString(d, "transaction_id"); + unSplitAmount = readXmlInteger(d, "unsplit_amount"); + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingService.java index 7f8d6ad33..df21cfdab 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingService.java @@ -96,6 +96,34 @@ public interface ProfitSharingService { */ ProfitSharingQueryResult profitSharingQuery(ProfitSharingQueryRequest request) throws WxPayException; + /** + *
+   * 服务商可通过调用此接口查询订单剩余待分金额。
+   * 接口频率:30QPS
+   * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_10&index=7
+   * 接口链接:https://api.mch.weixin.qq.com/pay/profitsharingorderamountquery
+   * 
+ * + * @param request . + * @return . + * @throws WxPayException . + */ + ProfitSharingOrderAmountQueryResult profitSharingOrderAmountQuery(ProfitSharingOrderAmountQueryRequest request) throws WxPayException; + + /** + *
+   * 服务商可以查询子商户设置的允许服务商分账的最大比例。
+   * 接口频率:30QPS
+   * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_11&index=8
+   * 接口链接:	https://api.mch.weixin.qq.com/pay/profitsharingmerchantratioquery
+   * 
+ * + * @param request . + * @return . + * @throws WxPayException . + */ + ProfitSharingMerchantRatioQueryResult profitSharingMerchantRatioQuery(ProfitSharingMerchantRatioQueryRequest request) throws WxPayException; + /** * TODO:这个接口用真实的数据返回【参数不正确】,我对比官方文档除了缺少sub_mch_id,和sub_appid之外其他相同,当我随便填了一个商户id的时候,提示【回退方没有开通分账回退功能】 *
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 3500ad41e..8d25a63d1 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
@@ -86,6 +86,28 @@ public class ProfitSharingServiceImpl implements ProfitSharingService {
     return result;
   }
 
+  @Override
+  public ProfitSharingOrderAmountQueryResult profitSharingOrderAmountQuery(ProfitSharingOrderAmountQueryRequest request) throws WxPayException {
+    request.checkAndSign(this.payService.getConfig());
+    String url = this.payService.getPayBaseUrl() + "/pay/profitsharingorderamountquery";
+
+    final String responseContent = payService.post(url, request.toXML(), true);
+    ProfitSharingOrderAmountQueryResult result = BaseWxPayResult.fromXML(responseContent, ProfitSharingOrderAmountQueryResult.class);
+    result.checkResult(payService, request.getSignType(), true);
+    return result;
+  }
+
+  @Override
+  public ProfitSharingMerchantRatioQueryResult profitSharingMerchantRatioQuery(ProfitSharingMerchantRatioQueryRequest request) throws WxPayException {
+    request.checkAndSign(this.payService.getConfig());
+    String url = this.payService.getPayBaseUrl() + "/pay/profitsharingmerchantratioquery";
+
+    final String responseContent = payService.post(url, request.toXML(), true);
+    ProfitSharingMerchantRatioQueryResult result = BaseWxPayResult.fromXML(responseContent, ProfitSharingMerchantRatioQueryResult.class);
+    result.checkResult(payService, request.getSignType(), true);
+    return result;
+  }
+
   @Override
   public ProfitSharingReturnResult profitSharingReturn(ProfitSharingReturnRequest returnRequest) throws WxPayException {
     returnRequest.checkAndSign(this.payService.getConfig());
diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImplTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImplTest.java
index 13f94d401..2638630cb 100644
--- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImplTest.java
+++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImplTest.java
@@ -100,6 +100,24 @@ public class ProfitSharingServiceImplTest {
     this.logger.info(result.toString());
   }
 
+  @Test
+  public void testProfitSharingMerchantRatioQuery() throws WxPayException {
+    final String subMchId = "subMchid";
+    final ProfitSharingMerchantRatioQueryRequest request = new ProfitSharingMerchantRatioQueryRequest(subMchId);
+    final ProfitSharingMerchantRatioQueryResult result = payService.getProfitSharingService().profitSharingMerchantRatioQuery(request);
+    logger.info(result.toString());
+  }
+
+  @Test
+    public void testProfitSharingOrderAmountQuery() throws WxPayException {
+    final String transactionId = "4200000916202012281633853127";
+    final ProfitSharingOrderAmountQueryRequest request = ProfitSharingOrderAmountQueryRequest.newBuilder()
+      .transactionId(transactionId)
+      .build();
+    final ProfitSharingOrderAmountQueryResult result = payService.getProfitSharingService().profitSharingOrderAmountQuery(request);
+    logger.info(result.toString());
+  }
+
   @Test
   public void testProfitSharingReturn() throws WxPayException {
     ProfitSharingReturnRequest request = ProfitSharingReturnRequest