mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-28 20:43:42 +08:00 
			
		
		
		
	🆕 #2631 【小程序】小程序交易组件-订单服务新增获取订单列表和生成支付参数的接口
This commit is contained in:
		| @ -2,11 +2,11 @@ package cn.binarywang.wx.miniapp.api; | ||||
|  | ||||
| import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderInfo; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopOrderPayRequest; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAddOrderResponse; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetOrderResponse; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.*; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * 小程序交易组件-订单服务 | ||||
|  * | ||||
| @ -21,4 +21,46 @@ public interface WxMaShopOrderService { | ||||
|  | ||||
|   WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid) | ||||
|     throws WxErrorException; | ||||
|  | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * | ||||
|    * 获取订单列表 | ||||
|    * | ||||
|    * 请求方式:POST(HTTPS) | ||||
|    * 请求地址:<a href="https://api.weixin.qq.com/shop/order/get_list">请求地址</a> | ||||
|    * | ||||
|    * 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/order/get_order_list.html">文档地址</a> | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param page  第x页,大于等于1 | ||||
|    * @param pageSize  每页订单数,上限100 | ||||
|    * @param desc  是否时间倒叙 | ||||
|    * @param startCreateTime  起始创建时间 | ||||
|    * @param endCreateTime  最终创建时间 | ||||
|    * @return 订单列表信息 | ||||
|    * @throws WxErrorException . | ||||
|    */ | ||||
|   WxMaShopGetOrderListResponse getOrderList(Integer page, Integer pageSize, Boolean desc, Date startCreateTime, Date endCreateTime) | ||||
|     throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * | ||||
|    * 生成支付参数 | ||||
|    * | ||||
|    * 请求方式:POST(HTTPS) | ||||
|    * 请求地址:<a href="https://api.weixin.qq.com/shop/order/getpaymentparams">请求地址</a> | ||||
|    * | ||||
|    * 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/order/getpaymentparams.html">文档地址</a> | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param orderId 微信侧订单id | ||||
|    * @param outOrderId 商家自定义订单ID | ||||
|    * @param openid  用户openid | ||||
|    * @return 支付参数 | ||||
|    * @throws WxErrorException . | ||||
|    */ | ||||
|   WxMaShopGetPaymentParamsResponse getPaymentParams(String orderId, String outOrderId, String openid) throws WxErrorException; | ||||
| } | ||||
|  | ||||
| @ -1,17 +1,10 @@ | ||||
| package cn.binarywang.wx.miniapp.api.impl; | ||||
|  | ||||
| import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_ADD; | ||||
| import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_CHECK_SCENE; | ||||
| import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_GET; | ||||
| import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.ORDER_PAY; | ||||
|  | ||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaShopOrderService; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderInfo; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopOrderPayRequest; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAddOrderResponse; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetOrderResponse; | ||||
| import cn.binarywang.wx.miniapp.bean.shop.response.*; | ||||
| import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; | ||||
| import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| @ -21,6 +14,12 @@ import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.json.GsonHelper; | ||||
| import me.chanjar.weixin.common.util.json.GsonParser; | ||||
| import org.apache.commons.lang3.time.FastDateFormat; | ||||
|  | ||||
| import java.text.Format; | ||||
| import java.util.Date; | ||||
|  | ||||
| import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.*; | ||||
|  | ||||
| /** | ||||
|  * @author boris | ||||
| @ -28,6 +27,9 @@ import me.chanjar.weixin.common.util.json.GsonParser; | ||||
| @RequiredArgsConstructor | ||||
| @Slf4j | ||||
| public class WxMaShopOrderServiceImpl implements WxMaShopOrderService { | ||||
|  | ||||
|   private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); | ||||
|  | ||||
|   private static final String ERR_CODE = "errcode"; | ||||
|   private static final String MATCH_KEY = "is_matched"; | ||||
|   private final WxMaService wxMaService; | ||||
| @ -45,34 +47,49 @@ public class WxMaShopOrderServiceImpl implements WxMaShopOrderService { | ||||
|  | ||||
|   @Override | ||||
|   public WxMaShopAddOrderResponse addOrder(WxMaShopOrderInfo orderInfo) throws WxErrorException { | ||||
|     String responseContent = this.wxMaService.post(ORDER_ADD, orderInfo); | ||||
|     JsonObject jsonObject = GsonParser.parse(responseContent); | ||||
|     if (jsonObject.get(ERR_CODE).getAsInt() != 0) { | ||||
|       throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); | ||||
|     } | ||||
|     return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAddOrderResponse.class); | ||||
|     return this.post(ORDER_ADD,orderInfo, WxMaShopAddOrderResponse.class); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WxMaShopBaseResponse orderPay(WxMaShopOrderPayRequest request) throws WxErrorException { | ||||
|     String responseContent = this.wxMaService.post(ORDER_PAY, request); | ||||
|     JsonObject jsonObject = GsonParser.parse(responseContent); | ||||
|     if (jsonObject.get(ERR_CODE).getAsInt() != 0) { | ||||
|       throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); | ||||
|     } | ||||
|     return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); | ||||
|     return this.post(ORDER_PAY,request, WxMaShopBaseResponse.class); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid) | ||||
|     throws WxErrorException { | ||||
|     String responseContent = this.wxMaService.post(ORDER_GET, | ||||
|   public WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid) throws WxErrorException { | ||||
|     return this.post(ORDER_GET, GsonHelper.buildJsonObject("order_id", orderId, "out_order_id", outOrderId, | ||||
|       "openid", openid), WxMaShopGetOrderResponse.class); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WxMaShopGetOrderListResponse getOrderList(Integer page, Integer pageSize, Boolean desc, Date startCreateTime, Date endCreateTime) throws WxErrorException { | ||||
|     JsonObject object = new JsonObject(); | ||||
|     object.addProperty("page", page == null ? 1 : page); | ||||
|     object.addProperty("page_size", pageSize == null ? 10 : pageSize); | ||||
|     object.addProperty("desc", desc ? 1 : 2); | ||||
|     if (startCreateTime != null) { | ||||
|       object.addProperty("start_create_time", this.dateFormat.format(startCreateTime)); | ||||
|     } | ||||
|     if (endCreateTime != null) { | ||||
|       object.addProperty("end_create_time", this.dateFormat.format(endCreateTime)); | ||||
|     } | ||||
|     return this.post(ORDER_GET_LIST, object, WxMaShopGetOrderListResponse.class); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WxMaShopGetPaymentParamsResponse getPaymentParams(String orderId, String outOrderId, String openid) throws WxErrorException { | ||||
|     return this.post(ORDER_GET_PAYMENT_PARAMS, | ||||
|       GsonHelper.buildJsonObject("order_id", orderId, "out_order_id", outOrderId, | ||||
|         "openid", openid)); | ||||
|         "openid", openid), WxMaShopGetPaymentParamsResponse.class); | ||||
|   } | ||||
|  | ||||
|  | ||||
|   private <T> T post(String url, Object params, Class<T> classOfT) throws WxErrorException { | ||||
|     String responseContent = this.wxMaService.post(url, params); | ||||
|     JsonObject jsonObject = GsonParser.parse(responseContent); | ||||
|     if (jsonObject.get(ERR_CODE).getAsInt() != 0) { | ||||
|       throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); | ||||
|     } | ||||
|     return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopGetOrderResponse.class); | ||||
|     return WxMaGsonBuilder.create().fromJson(responseContent, classOfT); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -14,6 +14,12 @@ import java.util.List; | ||||
| public class WxMaShopOrderDetail implements Serializable { | ||||
|   private static final long serialVersionUID = 3325843289672341160L; | ||||
|  | ||||
|   /** | ||||
|    * 推广员、分享员信息 | ||||
|    */ | ||||
|   @SerializedName("promotion_info") | ||||
|   private WxMaShopPromotionInfo promotionInfo; | ||||
|  | ||||
|   /** | ||||
|    * 下单商品信息 | ||||
|    * <pre> | ||||
|  | ||||
| @ -0,0 +1,39 @@ | ||||
| package cn.binarywang.wx.miniapp.bean.shop; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| /** | ||||
|  * 推广员、分享员信息 | ||||
|  * | ||||
|  * @author zhongjun | ||||
|  * @date 2022/5/17 | ||||
|  **/ | ||||
| @Data | ||||
| public class WxMaShopPromotionInfo implements Serializable { | ||||
|   private static final long serialVersionUID = -812058443344709898L; | ||||
|   /** | ||||
|    * 推广员唯一ID | ||||
|    */ | ||||
|   @SerializedName("promoter_id") | ||||
|   private String promoterId; | ||||
|  | ||||
|   /** | ||||
|    * 推广员视频号昵称 | ||||
|    */ | ||||
|   @SerializedName("finder_nickname") | ||||
|   private String finderNickname; | ||||
|   /** | ||||
|    * 推广员openid | ||||
|    */ | ||||
|   @SerializedName("promoter_openid") | ||||
|   private String promoterOpenid; | ||||
|  | ||||
|   /** | ||||
|    * 分享员openid | ||||
|    */ | ||||
|   @SerializedName("sharer_openid") | ||||
|   private String sharerOpenid; | ||||
| } | ||||
| @ -0,0 +1,30 @@ | ||||
| package cn.binarywang.wx.miniapp.bean.shop.response; | ||||
|  | ||||
| import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderResult; | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| /** | ||||
|  * @author leiin | ||||
|  * @date 2021/3/23 | ||||
|  */ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class WxMaShopGetOrderListResponse extends WxMaShopBaseResponse implements Serializable { | ||||
|   private static final long serialVersionUID = -81207907908726897L; | ||||
|  | ||||
|   /** | ||||
|    * 订单满足条件的总数 | ||||
|    */ | ||||
|   @SerializedName("total_num") | ||||
|   private Integer totalNum; | ||||
|  | ||||
|   /** | ||||
|    * 订单列表 | ||||
|    */ | ||||
|   @SerializedName("order") | ||||
|   private WxMaShopOrderResult order; | ||||
| } | ||||
| @ -0,0 +1,41 @@ | ||||
| package cn.binarywang.wx.miniapp.bean.shop.response; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.Getter; | ||||
| import lombok.Setter; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| /** | ||||
|  * 生成支付参数响应 | ||||
|  * | ||||
|  * @author zhongjun | ||||
|  * @date 2022/5/17 | ||||
|  **/ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class WxMaShopGetPaymentParamsResponse extends WxMaShopBaseResponse implements Serializable { | ||||
|   private static final long serialVersionUID = -8796836131438585559L; | ||||
|  | ||||
|   @SerializedName("payment_params") | ||||
|   private PaymentParams paymentParams; | ||||
|  | ||||
|   @Getter | ||||
|   @Setter | ||||
|   public static class PaymentParams { | ||||
|  | ||||
|     private String timeStamp; | ||||
|  | ||||
|     private String nonceStr; | ||||
|  | ||||
|     @SerializedName("package") | ||||
|     private String packageValue; | ||||
|  | ||||
|     private String signType; | ||||
|  | ||||
|     private String paySign; | ||||
|   } | ||||
|  | ||||
| } | ||||
| @ -418,6 +418,8 @@ public class WxMaApiUrlConstants { | ||||
|       String ORDER_ADD = "https://api.weixin.qq.com/shop/order/add"; | ||||
|       String ORDER_PAY = "https://api.weixin.qq.com/shop/order/pay"; | ||||
|       String ORDER_GET = "https://api.weixin.qq.com/shop/order/get"; | ||||
|       String ORDER_GET_LIST = "https://api.weixin.qq.com/shop/order/get_list"; | ||||
|       String ORDER_GET_PAYMENT_PARAMS = "https://api.weixin.qq.com/shop/order/getpaymentparams"; | ||||
|     } | ||||
|  | ||||
|     interface Register { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 zhongjun
					zhongjun