mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-03 20:27:46 +08:00
🆕 #2772 【小程序】增加小程序支付管理之创建订单接口
This commit is contained in:
parent
ab26565377
commit
cfa92390f2
@ -515,4 +515,10 @@ public interface WxMaService extends WxService {
|
||||
* @return getWxMaShopCouponService
|
||||
*/
|
||||
WxMaShopCouponService getWxMaShopCouponService();
|
||||
|
||||
/**
|
||||
* 小程序支付管理-订单支付
|
||||
* @return getWxMaShopPayService
|
||||
*/
|
||||
WxMaShopPayService getWxMaShopPayService();
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/wxafunds/API/order/create_order.html">文档地址</a>
|
||||
*
|
||||
* @param request 创建订单参数
|
||||
* @return 创建订单结果
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaShopPayCreateOrderResponse createOrder(WxMaShopPayCreateOrderRequest request)
|
||||
throws WxErrorException;
|
||||
}
|
@ -83,6 +83,7 @@ public abstract class BaseWxMaServiceImpl<H, P> 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<String, WxMaConfig> configMap;
|
||||
private int retrySleepMillis = 1000;
|
||||
private int maxRetryTimes = 5;
|
||||
@ -612,4 +613,8 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
return this.wxMaShopCouponService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopPayService getWxMaShopPayService() {
|
||||
return this.wxMaShopPayService;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<SubOrdersDTO> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -536,6 +536,10 @@ public class WxMaApiUrlConstants {
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user