feat:【MALL 商城】增加微信物流的对接(和社区同学,一起测试中。。。)
This commit is contained in:
@@ -65,4 +65,20 @@ public interface SocialClientApi {
|
||||
*/
|
||||
void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 上传订单发货到微信小程序
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
void uploadWxaOrderShippingInfo(Integer userType, SocialWxaOrderUploadShippingInfoReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 通知订单收货到微信小程序
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
void notifyWxaOrderConfirmReceive(Integer userType, SocialWxaOrderNotifyConfirmReceiveReqDTO reqDTO);
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.system.api.social.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 小程序订单上传购物详情
|
||||
*
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/shopping-order/normal-shopping-detail/uploadShoppingInfo.html">上传购物详情</a>
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class SocialWxaOrderNotifyConfirmReceiveReqDTO {
|
||||
|
||||
/**
|
||||
* 原支付交易对应的微信订单号
|
||||
*/
|
||||
@NotEmpty(message = "原支付交易对应的微信订单号不能为空")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* 快递签收时间
|
||||
*/
|
||||
@NotNull(message = "快递签收时间不能为空")
|
||||
private LocalDateTime receivedTime;
|
||||
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.system.api.social.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 小程序订单上传购物详情
|
||||
*
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/shopping-order/normal-shopping-detail/uploadShoppingInfo.html">上传购物详情</a>
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class SocialWxaOrderUploadShippingInfoReqDTO {
|
||||
|
||||
/**
|
||||
* 物流模式 - 实体物流配送采用快递公司进行实体物流配送形式
|
||||
*/
|
||||
public static final Integer LOGISTICS_TYPE_EXPRESS = 1;
|
||||
/**
|
||||
* 物流模式 - 虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式
|
||||
*/
|
||||
public static final Integer LOGISTICS_TYPE_VIRTUAL = 3;
|
||||
/**
|
||||
* 物流模式 - 用户自提
|
||||
*/
|
||||
public static final Integer LOGISTICS_TYPE_PICK_UP = 4;
|
||||
|
||||
/**
|
||||
* 支付者,支付者信息(openid)
|
||||
*/
|
||||
@NotEmpty(message = "支付者,支付者信息(openid)不能为空")
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* 原支付交易对应的微信订单号
|
||||
*/
|
||||
@NotEmpty(message = "原支付交易对应的微信订单号不能为空")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* 物流模式
|
||||
*/
|
||||
@NotNull(message = "物流模式不能为空")
|
||||
private Integer logisticsType;
|
||||
/**
|
||||
* 物流发货单号
|
||||
*/
|
||||
private String logisticsNo;
|
||||
/**
|
||||
* 物流公司编号
|
||||
*
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html#%E8%8E%B7%E5%8F%96%E8%BF%90%E5%8A%9Bid%E5%88%97%E8%A1%A8get-delivery-list">物流查询插件简介</a>
|
||||
*/
|
||||
private String expressCompany;
|
||||
/**
|
||||
* 商品信息
|
||||
*/
|
||||
@NotEmpty(message = "商品信息不能为空")
|
||||
private String itemDesc;
|
||||
/**
|
||||
* 收件人手机号
|
||||
*/
|
||||
@NotEmpty(message = "收件人手机号")
|
||||
private String receiverContact;
|
||||
|
||||
}
|
@@ -124,10 +124,11 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败");
|
||||
ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR = new ErrorCode(1_002_018_202, "获得小程序订阅消息模版失败");
|
||||
ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR = new ErrorCode(1_002_018_203, "发送小程序订阅消息失败");
|
||||
ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_UPLOAD_SHIPPING_INFO_ERROR = new ErrorCode(1_002_018_204, "上传微信小程序发货信息失败");
|
||||
ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_NOTIFY_CONFIRM_RECEIVE_ERROR = new ErrorCode(1_002_018_205, "上传微信小程序订单收货信息失败");
|
||||
ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_210, "社交客户端不存在");
|
||||
ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_211, "社交客户端已存在配置");
|
||||
|
||||
|
||||
// ========== OAuth2 客户端 1-002-020-000 =========
|
||||
ErrorCode OAUTH2_CLIENT_NOT_EXISTS = new ErrorCode(1_002_020_000, "OAuth2 客户端不存在");
|
||||
ErrorCode OAUTH2_CLIENT_EXISTS = new ErrorCode(1_002_020_001, "OAuth2 客户端编号已存在");
|
||||
|
@@ -94,4 +94,14 @@ public class SocialClientApiImpl implements SocialClientApi {
|
||||
socialClientService.sendSubscribeMessage(reqDTO, template.getPriTmplId(), socialUser.getOpenid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadWxaOrderShippingInfo(Integer userType, SocialWxaOrderUploadShippingInfoReqDTO reqDTO) {
|
||||
socialClientService.uploadWxaOrderShippingInfo(userType, reqDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyWxaOrderConfirmReceive(Integer userType, SocialWxaOrderNotifyConfirmReceiveReqDTO reqDTO) {
|
||||
socialClientService.notifyWxaOrderConfirmReceive(userType, reqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.system.service.social;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaOrderNotifyConfirmReceiveReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaOrderUploadShippingInfoReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
|
||||
@@ -92,6 +94,22 @@ public interface SocialClientService {
|
||||
*/
|
||||
void sendSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO, String templateId, String openId);
|
||||
|
||||
/**
|
||||
* 上传订单发货到微信小程序
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
void uploadWxaOrderShippingInfo(Integer userType, SocialWxaOrderUploadShippingInfoReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 通知订单收货到微信小程序
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
void notifyWxaOrderConfirmReceive(Integer userType, SocialWxaOrderNotifyConfirmReceiveReqDTO reqDTO);
|
||||
|
||||
// =================== 客户端管理 ===================
|
||||
|
||||
/**
|
||||
|
@@ -5,11 +5,15 @@ import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
|
||||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoBaseResponse;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
|
||||
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
@@ -19,6 +23,8 @@ import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaOrderNotifyConfirmReceiveReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaOrderUploadShippingInfoReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
|
||||
@@ -54,14 +60,17 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.hutool.core.date.DatePattern.UTC_MS_WITH_XXX_OFFSET_PATTERN;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
/**
|
||||
* 社交应用 Service 实现类
|
||||
@@ -327,6 +336,64 @@ public class SocialClientServiceImpl implements SocialClientService {
|
||||
return subscribeMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadWxaOrderShippingInfo(Integer userType, SocialWxaOrderUploadShippingInfoReqDTO reqDTO) {
|
||||
WxMaService service = getWxMaService(userType);
|
||||
List<ShippingListBean> shippingList;
|
||||
if (Objects.equals(reqDTO.getLogisticsType(), SocialWxaOrderUploadShippingInfoReqDTO.LOGISTICS_TYPE_EXPRESS)) {
|
||||
shippingList = singletonList(ShippingListBean.builder()
|
||||
.trackingNo(reqDTO.getLogisticsNo())
|
||||
.expressCompany(reqDTO.getExpressCompany())
|
||||
.itemDesc(reqDTO.getItemDesc())
|
||||
.contact(ContactBean.builder().receiverContact(DesensitizedUtil.mobilePhone(reqDTO.getReceiverContact())).build())
|
||||
.build());
|
||||
} else {
|
||||
shippingList = singletonList(ShippingListBean.builder().itemDesc(reqDTO.getItemDesc()).build());
|
||||
}
|
||||
WxMaOrderShippingInfoUploadRequest request = WxMaOrderShippingInfoUploadRequest.builder()
|
||||
.orderKey(OrderKeyBean.builder()
|
||||
.orderNumberType(2) // 使用原支付交易对应的微信订单号,即渠道单号
|
||||
.transactionId(reqDTO.getTransactionId())
|
||||
.build())
|
||||
.logisticsType(reqDTO.getLogisticsType()) // 配送方式
|
||||
.deliveryMode(1) // 统一发货
|
||||
.shippingList(shippingList)
|
||||
.payer(PayerBean.builder().openid(reqDTO.getOpenid()).build())
|
||||
.uploadTime(LocalDateTimeUtil.format(LocalDateTime.now(), UTC_MS_WITH_XXX_OFFSET_PATTERN))
|
||||
.build();
|
||||
try {
|
||||
WxMaOrderShippingInfoBaseResponse response = service.getWxMaOrderShippingService().upload(request);
|
||||
if (response.getErrCode() != 0) {
|
||||
log.error("[uploadWxaOrderShippingInfo][上传微信小程序发货信息失败:request({}) response({})]", request, response);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_UPLOAD_SHIPPING_INFO_ERROR, response.getErrMsg());
|
||||
}
|
||||
log.info("[uploadWxaOrderShippingInfo][上传微信小程序发货信息成功:request({}) response({})]", request, response);
|
||||
} catch (WxErrorException ex) {
|
||||
log.error("[uploadWxaOrderShippingInfo][上传微信小程序发货信息失败:request({})]", request, ex);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_UPLOAD_SHIPPING_INFO_ERROR, ex.getError().getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyWxaOrderConfirmReceive(Integer userType, SocialWxaOrderNotifyConfirmReceiveReqDTO reqDTO) {
|
||||
WxMaService service = getWxMaService(userType);
|
||||
WxMaOrderShippingInfoNotifyConfirmRequest request = WxMaOrderShippingInfoNotifyConfirmRequest.builder()
|
||||
.transactionId(reqDTO.getTransactionId())
|
||||
.receivedTime(LocalDateTimeUtil.toEpochMilli(reqDTO.getReceivedTime()))
|
||||
.build();
|
||||
try {
|
||||
WxMaOrderShippingInfoBaseResponse response = service.getWxMaOrderShippingService().notifyConfirmReceive(request);
|
||||
if (response.getErrCode() != 0) {
|
||||
log.error("[notifyWxaOrderConfirmReceive][确认收货提醒到微信小程序失败:request({}) response({})]", request, response);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_NOTIFY_CONFIRM_RECEIVE_ERROR, response.getErrMsg());
|
||||
}
|
||||
log.info("[notifyWxaOrderConfirmReceive][确认收货提醒到微信小程序成功:request({}) response({})]", request, response);
|
||||
} catch (WxErrorException ex) {
|
||||
log.error("[notifyWxaOrderConfirmReceive][确认收货提醒到微信小程序失败:request({})]", request, ex);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_NOTIFY_CONFIRM_RECEIVE_ERROR, ex.getError().getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 clientId + clientSecret 对应的 WxMpService 对象
|
||||
*
|
||||
|
Reference in New Issue
Block a user