微信发货接口对接,逻辑编写
This commit is contained in:
parent
29e195492b
commit
a2eb7be948
@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@ -16,6 +17,13 @@ public class DateTimeUtils {
|
||||
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
|
||||
}
|
||||
|
||||
// 将java.util.Date对象格式化为RFC 3339格式
|
||||
public static String formatDateTimeRFC3339(Date date) {
|
||||
ZonedDateTime zonedDateTime = date.toInstant().atZone(java.time.ZoneId.systemDefault());
|
||||
return zonedDateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
}
|
||||
|
||||
|
||||
public static Date parseDate(String dateString, String pattern) {
|
||||
SimpleDateFormat format = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
|
||||
@ -267,6 +267,20 @@ public class PhoneNumberUtils {
|
||||
return pattern.matcher(code).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对手机号进行脱敏处理
|
||||
*
|
||||
* @param phoneNumber 原始手机号
|
||||
* @return 脱敏后的手机号
|
||||
*/
|
||||
public static String maskPhoneNumber(String phoneNumber) {
|
||||
if (phoneNumber == null || phoneNumber.length() != 11) {
|
||||
return phoneNumber; // 如果手机号为空或长度不是11位,直接返回原始值
|
||||
}
|
||||
return phoneNumber.substring(0, 3) + "****" + phoneNumber.substring(7);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(isValidNumber("13111111111"));
|
||||
}
|
||||
|
||||
@ -11,9 +11,11 @@ package com.suisung.mall.shop.wechat.service.impl;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.suisung.mall.common.constant.CommonConstant;
|
||||
import com.suisung.mall.common.pojo.dto.WxOrderBaseInfoDTO;
|
||||
import com.suisung.mall.common.utils.DateTimeUtils;
|
||||
import com.suisung.mall.common.utils.RestTemplateHttpUtil;
|
||||
import com.suisung.mall.common.utils.phone.PhoneNumberUtils;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderBaseService;
|
||||
import com.suisung.mall.shop.wechat.service.WxOrderShippingService;
|
||||
import com.suisung.mall.shop.wechat.utils.WxUtil;
|
||||
@ -25,7 +27,7 @@ import org.springframework.data.util.Pair;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -74,13 +76,26 @@ public class WxOrderShippingServiceImpl implements WxOrderShippingService {
|
||||
return Pair.of(false, ORDER_RECORD_ERROR);
|
||||
}
|
||||
|
||||
|
||||
//shop_order_logistics shop_store_sf_order
|
||||
JSONObject shippingItem = new JSONObject();
|
||||
shippingItem.set("item_desc", orderBaseInfo.getSubject()); // 必填项
|
||||
|
||||
|
||||
// 发物流快递的必填字段
|
||||
shippingItem.set("tracking_no", expressNo);
|
||||
shippingItem.set("express_company", trackingNo);
|
||||
shippingItem.set("contact.receiver_contact", CommonConstant.IDD_ZH_CN + "-" + PhoneNumberUtils.maskPhoneNumber("13128998786"));
|
||||
|
||||
JSONArray shippingList = new JSONArray().put(shippingItem);
|
||||
|
||||
JSONObject paramsJSON = new JSONObject()
|
||||
.set("order_key.order_number_type", 2)
|
||||
.set("order_key.transaction_id", orderBaseInfo.getTransaction_id())
|
||||
.set("delivery_mode", 1)
|
||||
.set("logistics_type", logisticsType)
|
||||
.set("shipping_list", new JSONArray())
|
||||
.set("upload_time", DateTimeUtils.formatDateTime(LocalDateTime.now(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"))
|
||||
.set("shipping_list", shippingList)
|
||||
.set("upload_time", DateTimeUtils.formatDateTimeRFC3339(new Date()))
|
||||
.set("payer.openid", orderBaseInfo.getOpenid());
|
||||
|
||||
JSONObject respObj = RestTemplateHttpUtil.sendPost(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user