mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #2059 【小程序】增加小程序交易组件部分接口
This commit is contained in:
@@ -377,4 +377,29 @@ public interface WxMaService extends WxService {
|
||||
*/
|
||||
WxImgProcService getImgProcService();
|
||||
|
||||
// /**
|
||||
// * 返回小程序交易组件-售后服务接口
|
||||
// * @return
|
||||
// */
|
||||
// WxMaShopAfterSaleService getShopAfterSaleService();
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 返回小程序交易组件-物流服务接口
|
||||
// * @return
|
||||
// */
|
||||
// WxMaShopDeliveryService getShopDeliveryService();
|
||||
|
||||
|
||||
/**
|
||||
* 返回小程序交易组件-订单服务接口
|
||||
* @return
|
||||
*/
|
||||
WxMaShopOrderService getShopOrderService();
|
||||
|
||||
/**
|
||||
* 返回小程序交易组件-spu商品服务接口
|
||||
* @return
|
||||
*/
|
||||
WxMaShopSpuService getShopSpuService();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
/**
|
||||
* 小程序交易组件-售后服务
|
||||
*
|
||||
* @author boris
|
||||
*/
|
||||
public interface WxMaShopAfterSaleService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
/**
|
||||
* 小程序交易组件-物流发货服务
|
||||
*
|
||||
* @author boris
|
||||
*/
|
||||
public interface WxMaShopDeliveryService {
|
||||
|
||||
}
|
||||
@@ -0,0 +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;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopSpuInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopSpuWithoutAuditInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopSpuPageRequest;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAddSpuResponse;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetSpuListResponse;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetSpuResponse;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
/**
|
||||
* 小程序交易组件-商品服务
|
||||
*
|
||||
* @author boris
|
||||
*/
|
||||
public interface WxMaShopSpuService {
|
||||
WxMaShopAddSpuResponse addSpu(WxMaShopSpuInfo spuInfo) throws WxErrorException;
|
||||
|
||||
WxMaShopBaseResponse deleteSpu(Integer productId, String outProductId) throws WxErrorException;
|
||||
|
||||
WxMaShopGetSpuResponse getSpu(Integer productId, String outProductId, Integer needEditSpu)
|
||||
throws WxErrorException;
|
||||
|
||||
WxMaShopGetSpuListResponse getSpuList(WxMaShopSpuPageRequest request)
|
||||
throws WxErrorException;
|
||||
|
||||
WxMaShopAddSpuResponse updateSpu(WxMaShopSpuInfo spuInfo) throws WxErrorException;
|
||||
|
||||
WxMaShopAddSpuResponse updateSpuWithoutAudit(WxMaShopSpuWithoutAuditInfo spuInfo)
|
||||
throws WxErrorException;
|
||||
|
||||
WxMaShopBaseResponse listingSpu(Integer productId, String outProductId)
|
||||
throws WxErrorException;
|
||||
|
||||
WxMaShopBaseResponse delistingSpu(Integer productId, String outProductId)
|
||||
throws WxErrorException;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -499,4 +501,13 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
return this.imgProcService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopSpuService getShopSpuService() {
|
||||
return this.shopSpuService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopOrderService getShopOrderService() {
|
||||
return this.shopOrderService;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaShopAfterSaleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author boris
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
|
||||
private final WxMaService service;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaShopDeliveryService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author boris
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class WxMaShopDeliveryServiceImpl implements WxMaShopDeliveryService {
|
||||
private final WxMaService service;
|
||||
|
||||
}
|
||||
@@ -0,0 +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 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_ADD_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_DELISTING_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_DEL_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_GET_LIST_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_GET_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_LISTING_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_UPDATE_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.SPU_UPDATE_WITHOUT_URL;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaShopSpuService;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopSpuInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopSpuWithoutAuditInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopSpuPageRequest;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAddSpuResponse;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
|
||||
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
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopBaseResponse deleteSpu(Integer productId, String outProductId)
|
||||
throws WxErrorException {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopGetSpuResponse getSpu(Integer productId, String outProductId, Integer needEditSpu)
|
||||
throws WxErrorException {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopBaseResponse listingSpu(Integer productId, String outProductId)
|
||||
throws WxErrorException {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopBaseResponse delistingSpu(Integer productId, String outProductId)
|
||||
throws WxErrorException {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user