From cfa92390f21714601c02e8f626940203c68e8b3b Mon Sep 17 00:00:00 2001 From: liming1019 Date: Wed, 10 Aug 2022 22:44:43 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2772=20=E3=80=90=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E3=80=91=E5=A2=9E=E5=8A=A0=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E7=AE=A1=E7=90=86=E4=B9=8B=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaService.java | 6 +++ .../wx/miniapp/api/WxMaShopPayService.java | 24 ++++++++++ .../miniapp/api/impl/BaseWxMaServiceImpl.java | 5 ++ .../api/impl/WxMaShopPayServiceImpl.java | 29 ++++++++++++ .../WxMaShopPayCreateOrderRequest.java | 47 +++++++++++++++++++ .../WxMaShopPayCreateOrderResponse.java | 40 ++++++++++++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 4 ++ .../api/impl/WxMaShopPayServiceImplTest.java | 40 ++++++++++++++++ 8 files changed, 195 insertions(+) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopPayService.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImpl.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopPayCreateOrderRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopPayCreateOrderResponse.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImplTest.java diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java index 72e8aad1e6..fb2ef3b9b7 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java @@ -515,4 +515,10 @@ public interface WxMaService extends WxService { * @return getWxMaShopCouponService */ WxMaShopCouponService getWxMaShopCouponService(); + + /** + * 小程序支付管理-订单支付 + * @return getWxMaShopPayService + */ + WxMaShopPayService getWxMaShopPayService(); } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopPayService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopPayService.java new file mode 100644 index 0000000000..b1c3da4356 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopPayService.java @@ -0,0 +1,24 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 小程序支付管理订单相关接口 + * + * @author liming1019 + */ +public interface WxMaShopPayService { + + /** + * 创建订单 + * 文档地址:文档地址 + * + * @param request 创建订单参数 + * @return 创建订单结果 + * @throws WxErrorException . + */ + WxMaShopPayCreateOrderResponse createOrder(WxMaShopPayCreateOrderRequest request) + throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java index b1d3db0d7b..4cff1bf16b 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java @@ -83,6 +83,7 @@ public abstract class BaseWxMaServiceImpl implements WxMaService, RequestH private final WxMaProductService productService = new WxMaProductServiceImpl(this); private final WxMaProductOrderService productOrderService = new WxMaProductOrderServiceImpl(this); private final WxMaShopCouponService wxMaShopCouponService = new WxMaShopCouponServiceImpl(this); + private final WxMaShopPayService wxMaShopPayService = new WxMaShopPayServiceImpl(this); private Map configMap; private int retrySleepMillis = 1000; private int maxRetryTimes = 5; @@ -612,4 +613,8 @@ public WxMaShopCouponService getWxMaShopCouponService() { return this.wxMaShopCouponService; } + @Override + public WxMaShopPayService getWxMaShopPayService() { + return this.wxMaShopPayService; + } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImpl.java new file mode 100644 index 0000000000..1a1c45f291 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImpl.java @@ -0,0 +1,29 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaShopPayService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Pay.CREATE_ORDER; + +/** + * 小程序支付管理订单相关接口 + * + * @author liming1019 + */ +@RequiredArgsConstructor +@Slf4j +public class WxMaShopPayServiceImpl implements WxMaShopPayService { + private final WxMaService wxMaService; + + @Override + public WxMaShopPayCreateOrderResponse createOrder(WxMaShopPayCreateOrderRequest request) throws WxErrorException { + String response = this.wxMaService.post(CREATE_ORDER, request); + return WxGsonBuilder.create().fromJson(response, WxMaShopPayCreateOrderResponse.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopPayCreateOrderRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopPayCreateOrderRequest.java new file mode 100644 index 0000000000..085a70eecf --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopPayCreateOrderRequest.java @@ -0,0 +1,47 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2022/8/10 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxMaShopPayCreateOrderRequest implements Serializable { + private static final long serialVersionUID = -5597409427574429095L; + + @SerializedName("openid") + private String openid; + @SerializedName("combine_trade_no") + private String combineTradeNo; + @SerializedName("expire_time") + private Long expireTime; + @SerializedName("sub_orders") + private List subOrders; + + @NoArgsConstructor + @AllArgsConstructor + @Data + @Builder + public static class SubOrdersDTO { + @SerializedName("mchid") + private String mchid; + @SerializedName("amount") + private Integer amount; + @SerializedName("trade_no") + private String tradeNo; + @SerializedName("description") + private String description; + } +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopPayCreateOrderResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopPayCreateOrderResponse.java new file mode 100644 index 0000000000..85cd3e3909 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopPayCreateOrderResponse.java @@ -0,0 +1,40 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2022/8/10 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxMaShopPayCreateOrderResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -375471325664721192L; + + @SerializedName("payment_params") + private PaymentParamsDTO paymentParams; + + @NoArgsConstructor + @Data + public static class PaymentParamsDTO { + @SerializedName("timeStamp") + private Integer timeStamp; + @SerializedName("nonceStr") + private String nonceStr; + @SerializedName("package") + private String packageX; + @SerializedName("paySign") + private String paySign; + @SerializedName("signType") + private String signType; + } +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index c7c02f8b2d..e6c8535b91 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -536,6 +536,10 @@ interface Coupon { String UPDATE_USER_COUPON = "https://api.weixin.qq.com/shop/coupon/update_user_coupon"; String UPDATE_USER_COUPON_STATUS = "https://api.weixin.qq.com/shop/coupon/update_usercoupon_status"; } + + interface Pay { + String CREATE_ORDER = "https://api.weixin.qq.com/shop/pay/createorder"; + } } /** diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImplTest.java new file mode 100644 index 0000000000..bf509b8b3a --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImplTest.java @@ -0,0 +1,40 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopPayServiceImplTest { + + @Inject + private WxMaService wxService; + + @Test + public void testCreateOrder() throws Exception { + WxMaShopPayCreateOrderRequest request = + WxMaShopPayCreateOrderRequest.builder() + .openid("") + .combineTradeNo("") + .expireTime(1234L) + .subOrders(Arrays.asList(WxMaShopPayCreateOrderRequest.SubOrdersDTO.builder() + .mchid("") + .amount(0) + .tradeNo("") + .description("") + .build() + )) + .build(); + WxMaShopPayCreateOrderResponse response = wxService.getWxMaShopPayService().createOrder(request); + assertThat(response).isNotNull(); + } +}