8000 :new: #2631 【小程序】小程序交易组件-订单服务新增获取订单列表和生成支付参数的接口 · binarywang/WxJava@4de09fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 4de09fa

Browse files
authored
🆕 #2631 【小程序】小程序交易组件-订单服务新增获取订单列表和生成支付参数的接口
1 parent a6d4b6e commit 4de09fa

File tree

7 files changed

+204
-27
lines changed

7 files changed

+204
-27
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopOrderService.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderInfo;
44
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopOrderPayRequest;
5-
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAddOrderResponse;
6-
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
7-
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetOrderResponse;
5+
import cn.binarywang.wx.miniapp.bean.shop.response.*;
86
import me.chanjar.weixin.common.error.WxErrorException;
97

8+
import java.util.Date;
9+
1010
/**
1111
* 小程序交易组件-订单服务
1212
*
@@ -21,4 +21,46 @@ public interface WxMaShopOrderService {
2121

2222
WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid)
2323
throws WxErrorException;
24+
25+
26+
/**
27+
* <pre>
28+
*
29+
* 获取订单列表
30+
*
31+
* 请求方式:POST(HTTPS)
32+
* 请求地址:<a href="https://api.weixin.qq.com/shop/order/get_list">请求地址</a>
33+
*
34+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/order/get_order_list.html">文档地址</a>
35+
* </pre>
36+
*
37+
* @param page 第x页,大于等于1
38+
* @param pageSize 每页订单数,上限100
39+
* @param desc 是否时间倒叙
40+
* @param startCreateTime 起始创建时间
41+
* @param endCreateTime 最终创建时间
42+
* @return 订单列表信息
43+
* @throws WxErrorException .
44+
*/
45+
WxMaShopGetOrderListResponse getOrderList(Integer page, Integer pageSize, Boolean desc, Date startCreateTime, Date endCreateTime)
46+
throws WxErrorException;
47+
48+
/**
49+
* <pre>
50+
*
51+
* 生成支付参数
52+
*
53+
* 请求方式:POST(HTTPS)
54+
* 请求地址:<a href="https://api.weixin.qq.com/shop/order/getpaymentparams">请求地址</a>
55+
*
56+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/order/getpaymentparams.html">文档地址</a>
57+
* </pre>
58+
*
59+
* @param orderId 微信侧订单id
60+
* @param outOrderId 商家自定义订单ID
61+
* @param openid 用户openid
62+
* @return 支付参数
63+
* @throws WxErrorException .
64+
*/
65+
WxMaShopGetPaymentParamsResponse getPaymentParams(String orderId, String outOrderId, String openid) throws WxErrorException;
2466
}
Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
package cn.binarywang.wx.miniapp.api.impl;
22

3-
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_ADD;
4-
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_CHECK_SCENE;
5-
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_GET;
6-
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_PAY;
7-
83
import cn.binarywang.wx.miniapp.api.WxMaService;
94
import cn.binarywang.wx.miniapp.api.WxMaShopOrderService;
105
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderInfo;
116
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopOrderPayRequest;
12-
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAddOrderResponse;
13-
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
14-
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetOrderResponse;
7+
import cn.binarywang.wx.miniapp.bean.shop.response.*;
158
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
169
import com.google.gson.JsonObject;
1710
import lombok.RequiredArgsConstructor;
@@ -21,13 +14,22 @@
2114
import me.chanjar.weixin.common.error.WxErrorException;
2215
import me.chanjar.weixin.common.util.json.GsonHelper;
2316
import me.chanjar.weixin.common.util.json.GsonParser;
17+
import org.apache.commons.lang3.time.FastDateFormat;
18+
19+
import java.text.Format;
20+
import java.util.Date;
21+
22+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.*;
2423

2524
/**
2625
* @author boris
2726
*/
2827
@RequiredArgsConstructor
2928
@Slf4j
3029
public class WxMaShopOrderServiceImpl implements WxMaShopOrderService {
30+
31+
private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
32+
3133
private static final String ERR_CODE = "errcode";
3234
private static final String MATCH_KEY = "is_matched";
3335
private final WxMaService wxMaService;
@@ -45,34 +47,49 @@ public Boolean checkScene(Integer scene) throws WxErrorException {
4547

4648
@Override
4749
public WxMaShopAddOrderResponse addOrder(WxMaShopOrderInfo orderInfo) throws WxErrorException {
48-
String responseContent = this.wxMaService.post(ORDER_ADD, orderInfo);
49-
JsonObject jsonObject = GsonParser.parse(responseContent);
50-
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
51-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
52-
}
53-
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAddOrderResponse.class);
50+
return this.post(ORDER_ADD,orderInfo, WxMaShopAddOrderResponse.class);
5451
}
5552

5653
@Override
5754
public WxMaShopBaseResponse orderPay(WxMaShopOrderPayRequest request) throws WxErrorException {
58-
String responseContent = this.wxMaService.post(ORDER_PAY, request);
59-
JsonObject jsonObject = GsonParser.parse(responseContent);
60-
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
61-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
55+
return this.post(ORDER_PAY,request, WxMaShopBaseResponse.class);
56+
}
57+
58+
@Override
59+
public WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid) throws WxErrorException {
60+
return this.post(ORDER_GET, GsonHelper.buildJsonObject("order_id", orderId, "out_order_id", outOrderId,
61+
"openid", openid), WxMaShopGetOrderResponse.class);
62+
}
63+
64+
@Override
65+
public WxMaShopGetOrderListResponse getOrderList(Integer page, Integer pageSize, Boolean desc, Date startCreateTime, Date endCreateTime) throws WxErrorException {
66+
JsonObject object = new JsonObject();
67+
object.addProperty("page", page == null ? 1 : page);
68+
object.addProperty("page_size", pageSize == null ? 10 : pageSize);
69+
object.addProperty("desc", desc ? 1 : 2);
70+
if (startCreateTime != null) {
71+
object.addProperty("start_create_time", this.dateFormat.format(startCreateTime));
72+
}
73+
if (endCreateTime != null) {
74+
object.addProperty("end_create_time", this.dateFormat.format(endCreateTime));
6275
}
63-
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
76+
return this.post(ORDER_GET_LIST, object, WxMaShopGetOrderListResponse.class);
6477
}
6578

6679
@Override
67-
public WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid)
68-
throws WxErrorException {
69-
String responseContent = this.wx 10000 MaService.post(ORDER_GET,
80+
public WxMaShopGetPaymentParamsResponse getPaymentParams(String orderId, String outOrderId, String openid) throws WxErrorException {
81+
return this.post(ORDER_GET_PAYMENT_PARAMS,
7082
GsonHelper.buildJsonObject("order_id", orderId, "out_order_id", outOrderId,
71-
"openid", openid));
83+
"openid", openid), WxMaShopGetPaymentParamsResponse.class);
84+
}
85+
86+
87+
private <T> T post(String url, Object params, Class<T> classOfT) throws WxErrorException {
88+
String responseContent = this.wxMaService.post(url, params);
7289
JsonObject jsonObject = GsonParser.parse(responseContent);
7390
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
7491
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
7592
}
76-
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopGetOrderResponse.class);
93+
return WxMaGsonBuilder.create().fromJson(responseContent, classOfT);
7794
}
7895
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopOrderDetail.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
public class WxMaShopOrderDetail implements Serializable {
1515
private static final long serialVersionUID = 3325843289672341160L;
1616

17+
/**
18+
* 推广员、分享员信息
19+
*/
20+
@SerializedName("promotion_info")
21+
private WxMaShopPromotionInfo promotionInfo;
22+
1723
/**
1824
* 下单商品信息
1925
* <pre>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.binarywang.wx.miniapp.bean.shop;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* 推广员、分享员信息
10+
*
11+
* @author zhongjun
12+
* @date 2022/5/17
13+
**/
14+
@Data
15+
public class WxMaShopPromotionInfo implements Serializable {
16+
private static final long serialVersionUID = -812058443344709898L;
17+
/**
18+
* 推广员唯一ID
19+
*/
20+
@SerializedName("promoter_id")
21+
private String promoterId;
22+
23+
/**
24+
* 推广员视频号昵称
25+
*/
26+
@SerializedName("finder_nickname")
27+
private String finderNickname;
28+
/**
29+
* 推广员openid
30+
*/
31+
@SerializedName("promoter_openid")
32+
private String promoterOpenid;
33+
34+
/**
35+
* 分享员openid
36+
*/
37+
@SerializedName("sharer_openid")
38+
private String sharerOpenid;
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cn.binarywang.wx.miniapp.bean.shop.response;
2+
3+
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderResult;
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* @author leiin
12+
* @date 2021/3/23
13+
*/
14+
@Data
15+
@EqualsAndHashCode(callSuper = true)
16+
public class WxMaShopGetOrderListResponse extends WxMaShopBaseResponse implements Serializable {
17+
private static final long serialVersionUID = -81207907908726897L;
18+
19+
/**
20+
* 订单满足条件的总数
21+
*/
22+
@SerializedName("total_num")
23+
private Integer totalNum;
24+
25+
/**
26+
* 订单列表
27+
*/
28+
@SerializedName("order")
29+
private WxMaShopOrderResult order;
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cn.binarywang.wx.miniapp.bean.shop.response;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
9+
import java.io.Serializable;
10+
11+
/**
12+
* 生成支付参数响应
13+
*
14+
* @author zhongjun
15+
* @date 2022/5/17
16+
**/
17+
@Data
18+
@EqualsAndHashCode(callSuper = true)
19+
public class WxMaShopGetPaymentParamsResponse extends WxMaShopBaseResponse implements Serializable {
20+
private static final long serialVersionUID = -8796836131438585559L;
21+
22+
@SerializedName("payment_params")
23+
private PaymentParams paymentParams;
24+
25+
@Getter
26+
@Setter
27+
public static class PaymentParams {
28+
29+
private String timeStamp;
30+
31+
private String nonceStr;
32+
33+
@SerializedName("package")
34+
private String packageValue;
35+
36+
private String signType;
37+
38+
private String paySign;
39+
}
40+
41+
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ interface Order {
418418
String ORDER_ADD = "https://api.weixin.qq.com/shop/order/add";
419419
String ORDER_PAY = "https://api.weixin.qq.com/shop/order/pay";
420420
String ORDER_GET = "https://api.weixin.qq.com/shop/order/get";
421+
String ORDER_GET_LIST = "https://api.weixin.qq.com/shop/order/get_list";
422+
String ORDER_GET_PAYMENT_PARAMS = "https://api.weixin.qq.com/shop/order/getpaymentparams";
421423
}
422424

423425
interface Register {

0 commit comments

Comments
 (0)
0