|
|
@@ -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 对象
|
|
|
*
|