-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab26565
commit cfa9239
Showing
8 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopPayService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...c/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopPayCreateOrderRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
...main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopPayCreateOrderResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...a-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |