Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingIsTradeManagedResponse;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* @author xzh
* created on 2023/5/17 16:49
*/
public interface WxMaOrderShippingService {
/**
* 查询小程序是否已开通发货信息管理服务
*
* @param appId 待查询小程序的 appid,非服务商调用时仅能查询本账号
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
WxMaOrderShippingIsTradeManagedResponse isTradeManaged(String appId)
throws WxErrorException;

/**
* 发货信息录入接口
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
WxMaOrderShippingInfoBaseResponse upload(WxMaOrderShippingInfoUploadRequest request)
throws WxErrorException;


/**
* 发货信息合单录入接口
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
WxMaOrderShippingInfoBaseResponse upload(WxMaOrderCombinedShippingInfoUploadRequest request)
throws WxErrorException;

/**
* 查询订单发货状态
* 你可以通过交易单号或商户号+商户单号来查询该支付单的发货状态。
*
* @param request 请求
* @return WxMaOrderShippingInfoGetResponse
* @throws WxErrorException e
*/
WxMaOrderShippingInfoGetResponse get(WxMaOrderShippingInfoGetRequest request)
throws WxErrorException;

/**
* 查询订单列表
* 你可以通过支付时间、支付者openid或订单状态来查询订单列表。
*
* @param request 请求
* @return WxMaOrderShippingInfoGetListResponse
* @throws WxErrorException e
*/
WxMaOrderShippingInfoGetListResponse getList(WxMaOrderShippingInfoGetListRequest request)
throws WxErrorException;

/**
* 确认收货提醒接口
* 如你已经从你的快递物流服务方获知到用户已经签收相关商品,可以通过该接口提醒用户及时确认收货,以提高资金结算效率,每个订单仅可调用一次。
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
WxMaOrderShippingInfoBaseResponse notifyConfirmReceive(WxMaOrderShippingInfoNotifyConfirmRequest request)
throws WxErrorException;

/**
* 消息跳转路径设置接口
* 如你已经在小程序内接入平台提供的确认收货组件,可以通过该接口设置发货消息及确认收货消息的跳转动作,用户点击发货消息时会直接进入你的小程序订单列表页面或详情页面进行确认收货,进一步优化用户体验。
*
* @param path 商户自定义跳转路径
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
WxMaOrderShippingInfoBaseResponse setMsgJumpPath(String path)
throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,36 +496,49 @@ public interface WxMaService extends WxService {

/**
* 分享人接口
*
* @return WxMaShopSharerService
*/
WxMaShopSharerService getShopSharerService();

/**
* 标准交易组件接口
*
* @return WxMaProductService
*/
WxMaProductService getProductService();

/**
* 小商店-标准交易组件-订单服务
*
* @return getProductOrderService
*/
WxMaProductOrderService getProductOrderService();

/**
* 小商店-标准交易组件-优惠券
*
* @return getWxMaShopCouponService
*/
WxMaShopCouponService getWxMaShopCouponService();

/**
* 小程序支付管理-订单支付
*
* @return getWxMaShopPayService
*/
WxMaShopPayService getWxMaShopPayService();

/**
* 小程序发货信息管理服务
*
* @return getWxMaOrderShippingService
*/
WxMaOrderShippingService getWxMaOrderShippingService();

/**
* 小程序openApi管理
*
* @return getWxMaOpenApiService
*/
WxMaOpenApiService getWxMaOpenApiService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
private final WxMaProductOrderService productOrderService = new WxMaProductOrderServiceImpl(this);
private final WxMaShopCouponService wxMaShopCouponService = new WxMaShopCouponServiceImpl(this);
private final WxMaShopPayService wxMaShopPayService = new WxMaShopPayServiceImpl(this);

private final WxMaOrderShippingService wxMaOrderShippingService = new WxMaOrderShippingServiceImpl(this);

private final WxMaOpenApiService wxMaOpenApiService = new WxMaOpenApiServiceImpl(this);

private Map<String, WxMaConfig> configMap;
private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
Expand Down Expand Up @@ -602,24 +606,34 @@ public WxMaReimburseInvoiceService getReimburseInvoiceService() {
}

@Override
public WxMaDeviceSubscribeService getDeviceSubscribeService(){ return this.deviceSubscribeService; }
public WxMaDeviceSubscribeService getDeviceSubscribeService() {
return this.deviceSubscribeService;
}

@Override
public WxMaMarketingService getMarketingService() {return this.marketingService; }
public WxMaMarketingService getMarketingService() {
return this.marketingService;
}

@Override
public WxMaImmediateDeliveryService getWxMaImmediateDeliveryService() {
return this.immediateDeliveryService;
}

@Override
public WxMaSafetyRiskControlService getSafetyRiskControlService(){ return this.safetyRiskControlService; }
public WxMaSafetyRiskControlService getSafetyRiskControlService() {
return this.safetyRiskControlService;
}

@Override
public WxMaShopSharerService getShopSharerService() {return this.shopSharerService; }
public WxMaShopSharerService getShopSharerService() {
return this.shopSharerService;
}

@Override
public WxMaProductService getProductService() { return this.productService; }
public WxMaProductService getProductService() {
return this.productService;
}

@Override
public WxMaProductOrderService getProductOrderService() {
Expand All @@ -636,6 +650,16 @@ public WxMaShopPayService getWxMaShopPayService() {
return this.wxMaShopPayService;
}

/**
* 小程序发货信息管理服务
*
* @return getWxMaOrderShippingService
*/
@Override
public WxMaOrderShippingService getWxMaOrderShippingService() {
return this.wxMaOrderShippingService;
}

@Override
public WxMaOpenApiService getWxMaOpenApiService() {
return this.wxMaOpenApiService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package cn.binarywang.wx.miniapp.api.impl;

import cn.binarywang.wx.miniapp.api.WxMaOrderShippingService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaOrderShippingIsTradeManagedRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingIsTradeManagedResponse;
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.api.WxConsts;
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;

import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.OrderShipping.*;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.OTHER.GET_CATEGORY;


/**
* @author xzh
* created on 2023/5/17 17:44
*/
@Slf4j
@RequiredArgsConstructor
public class WxMaOrderShippingServiceImpl implements WxMaOrderShippingService {

private final WxMaService wxMaService;

/**
* 查询小程序是否已开通发货信息管理服务
*
* @param appId 待查询小程序的 appid,非服务商调用时仅能查询本账号
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingIsTradeManagedResponse isTradeManaged(String appId) throws WxErrorException {
WxMaOrderShippingIsTradeManagedRequest request = WxMaOrderShippingIsTradeManagedRequest.builder().appId(appId).build();
return request(IS_TRADE_MANAGED, request, WxMaOrderShippingIsTradeManagedResponse.class);
}

/**
* 发货信息录入接口
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse upload(WxMaOrderShippingInfoUploadRequest request) throws WxErrorException {
return request(UPLOAD_SHIPPING_INFO, request, WxMaOrderShippingInfoBaseResponse.class);
}

/**
* 发货信息合单录入接口
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse upload(WxMaOrderCombinedShippingInfoUploadRequest request) throws WxErrorException {
return request(UPLOAD_COMBINED_SHIPPING_INFO, request, WxMaOrderShippingInfoBaseResponse.class);
}

/**
* 查询订单发货状态
* 你可以通过交易单号或商户号+商户单号来查询该支付单的发货状态。
*
* @param request 请求
* @return WxMaOrderShippingInfoGetResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoGetResponse get(WxMaOrderShippingInfoGetRequest request) throws WxErrorException {
return request(GET_SHIPPING_INFO, request, WxMaOrderShippingInfoGetResponse.class);
}

/**
* 查询订单列表
* 你可以通过支付时间、支付者openid或订单状态来查询订单列表。
*
* @param request 请求
* @return WxMaOrderShippingInfoGetListResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoGetListResponse getList(WxMaOrderShippingInfoGetListRequest request) throws WxErrorException {
return request(GET_SHIPPING_INFO_LIST, request, WxMaOrderShippingInfoGetListResponse.class);
}

/**
* 确认收货提醒接口
* 如你已经从你的快递物流服务方获知到用户已经签收相关商品,可以通过该接口提醒用户及时确认收货,以提高资金结算效率,每个订单仅可调用一次。
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse notifyConfirmReceive(WxMaOrderShippingInfoNotifyConfirmRequest request) throws WxErrorException {
return request(NOTIFY_CONFIRM_RECEIVE, request, WxMaOrderShippingInfoBaseResponse.class);
}

/**
* 消息跳转路径设置接口
* 如你已经在小程序内接入平台提供的确认收货组件,可以通过该接口设置发货消息及确认收货消息的跳转动作,用户点击发货消息时会直接进入你的小程序订单列表页面或详情页面进行确认收货,进一步优化用户体验。
*
* @param path 商户自定义跳转路径
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse setMsgJumpPath(String path) throws WxErrorException {
JsonObject jsonObject = GsonHelper.buildJsonObject("path", path);
return request(SET_MSG_JUMP_PATH, jsonObject, WxMaOrderShippingInfoBaseResponse.class);
}

private <T> T request(String url, Object request, Class<T> resultT) throws WxErrorException {
String responseContent = this.wxMaService.post(url, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, resultT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 xzh
* created on 2023/5/17 17:01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaOrderShippingIsTradeManagedRequest implements Serializable {

private static final long serialVersionUID = -5735132900385013330L;
/**
* 必填
* 待查询小程序的 appid,非服务商调用时仅能查询本账号
*/
@SerializedName("appid")
private String appId;

}
Loading