Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
添加交易组件订单接口
Signed-off-by: WangLei <904443972@qq.com>
  • Loading branch information
wangleiin committed Mar 23, 2021
commit c5b68ec2f74efd31af341764ef00cde81c6a7e21
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
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 me.chanjar.weixin.common.error.WxErrorException;

/**
* 小程序交易组件-订单服务
*
* @author boris
*/
public interface WxMaShopOrderService {
Boolean checkScene(Integer scene) throws WxErrorException;

WxMaShopAddOrderResponse addOrder(WxMaShopOrderInfo orderInfo) throws WxErrorException;

WxMaShopBaseResponse orderPay(WxMaShopOrderPayRequest request) throws WxErrorException;

WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid)
throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
private final WxMaLiveMemberService liveMemberService = new WxMaLiveMemberServiceImpl(this);
private final WxOcrService ocrService = new WxMaOcrServiceImpl(this);
private final WxImgProcService imgProcService = new WxMaImgProcServiceImpl(this);
private final WxMaShopSpuService shopSpuService = new WxMaShopSpuServiceImpl(this);
private final WxMaShopOrderService shopOrderService = new WxMaShopOrderServiceImpl(this);
private Map<String, WxMaConfig> configMap;
private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
Expand Down Expand Up @@ -499,4 +501,13 @@ public WxImgProcService getImgProcService() {
return this.imgProcService;
}

@Override
public WxMaShopSpuService getShopSpuService() {
return this.shopSpuService;
}

@Override
public WxMaShopOrderService getShopOrderService() {
return this.shopOrderService;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,78 @@
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.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
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;

/**
* @author boris
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopOrderServiceImpl implements WxMaShopOrderService {
private final WxMaService service;
private static final String ERR_CODE = "errcode";
private static final String MATCH_KEY = "is_matched";
private final WxMaService wxMaService;

@Override
public Boolean checkScene(Integer scene) throws WxErrorException {
String responseContent = this.wxMaService
.post(ORDER_CHECK_SCENE, GsonHelper.buildJsonObject("scene", scene));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get(MATCH_KEY).getAsBoolean();
}

@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);
}

@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);
}

@Override
public WxMaShopGetOrderResponse getOrder(Integer orderId, String outOrderId, String openid)
throws WxErrorException {
String responseContent = this.wxMaService.post(ORDER_GET,
GsonHelper.buildJsonObject("order_id", orderId, "out_order_id", outOrderId,
"openid", openid));
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetSpuListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetSpuResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
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;

/**
* @author boris
Expand All @@ -31,11 +35,16 @@
@Slf4j
public class WxMaShopSpuServiceImpl implements WxMaShopSpuService {

private static final String ERR_CODE = "errcode";
private final WxMaService wxMaService;

@Override
public WxMaShopAddSpuResponse addSpu(WxMaShopSpuInfo spuInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_ADD_URL, spuInfo);
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, WxMaShopAddSpuResponse.class);
}

Expand All @@ -45,6 +54,10 @@ public WxMaShopBaseResponse deleteSpu(Integer productId, String outProductId)
String responseContent = this.wxMaService
.post(SPU_DEL_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
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);
}

Expand All @@ -54,26 +67,42 @@ public WxMaShopGetSpuResponse getSpu(Integer productId, String outProductId, Int
String responseContent = this.wxMaService
.post(SPU_GET_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId, "need_edit_spu", needEditSpu));
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, WxMaShopGetSpuResponse.class);
}

@Override
public WxMaShopGetSpuListResponse getSpuList(WxMaShopSpuPageRequest request)
throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_GET_LIST_URL, 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, WxMaShopGetSpuListResponse.class);
}

@Override
public WxMaShopAddSpuResponse updateSpu(WxMaShopSpuInfo spuInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_UPDATE_URL, spuInfo);
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, WxMaShopAddSpuResponse.class);
}

@Override
public WxMaShopAddSpuResponse updateSpuWithoutAudit(WxMaShopSpuWithoutAuditInfo spuInfo)
throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_UPDATE_WITHOUT_URL, spuInfo);
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, WxMaShopAddSpuResponse.class);
}

Expand All @@ -83,6 +112,10 @@ public WxMaShopBaseResponse listingSpu(Integer productId, String outProductId)
String responseContent = this.wxMaService
.post(SPU_LISTING_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
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);
}

Expand All @@ -92,6 +125,10 @@ public WxMaShopBaseResponse delistingSpu(Integer productId, String outProductId)
String responseContent = this.wxMaService
.post(SPU_DELISTING_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cn.binarywang.wx.miniapp.bean.shop;

import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Data;

/**
* @author leiin
* @date 2021/3/23
* @description:
*/
@Data
public class WxMaShopAddOrderResult implements Serializable {
/**
* 交易组件平台订单ID
*/
@SerializedName("order_id")
private Integer orderId;
/**
* 交易组件平台订单ID
*/
@SerializedName("out_order_id")
private String outOrderId;
/**
* 拉起收银台的ticket
*/
@SerializedName("ticket")
private String ticket;
/**
* ticket有效截止时间
*/
@SerializedName("ticket_expire_time")
private String ticketExpireTime;
/**
* 订单最终价格(单位:分)
*/
@SerializedName("final_price")
private Integer finalPrice;

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cn.binarywang.wx.miniapp.bean.shop;

import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Data;

/**
* @author leiin
* @date 2021/3/23
* @description:
*/
@Data
public class WxMaShopAddressInfo implements Serializable {
/**
* 收件人姓名
* <pre>
* 是否必填:是
* </pre>
*/
@SerializedName("receiver_name")
private String receiverName;
/**
* 详细收货地址信息
* <pre>
* 是否必填:是
* </pre>
*/
@SerializedName("detailed_address")
private String detailedAddress;
/**
* 收件人手机号码
* <pre>
* 是否必填:是
* </pre>
*/
@SerializedName("tel_number")
private String telNumber;
/**
* 国家
* <pre>
* 是否必填:否
* </pre>
*/
@SerializedName("country")
private String country;
/**
* 省份
* <pre>
* 是否必填:否
* </pre>
*/
@SerializedName("province")
private String province;
/**
* 城市
* <pre>
* 是否必填:否
* </pre>
*/
@SerializedName("city")
private String city;
/**
* 乡镇
* <pre>
* 是否必填:否
* </pre>
*/
@SerializedName("town")
private String town;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cn.binarywang.wx.miniapp.bean.shop;

import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
import lombok.Data;

/**
* @author leiin
* @date 2021/3/23
* @description:
*/
@Data
public class WxMaShopDeliveryDetail implements Serializable {

private static final long serialVersionUID = 9074573142867543744L;

/**
*
* <pre>
* 是否必填:是
* </pre>
*/
@SerializedName("delivery_type")
private Integer deliveryType;

// 以下字段仅作为返回数据展示填充

/**
* 是否发货完成
*/
@SerializedName("finish_all_delivery")
private Integer finishAllDelivery;

/**
* 快递信息
*/
@SerializedName("delivery_list")
private List<WxMaShopDeliveryItem> deliveryList;
}

Loading