格式化飞书通知跳转链接方法错误
This commit is contained in:
@@ -12,6 +12,7 @@ public class TRTCUtils {
|
||||
|
||||
/**
|
||||
* 默认过期时间 30 s
|
||||
* 修改为 24 小时(官方建议)
|
||||
*/
|
||||
private static final Long expired = 60 * 60 * 24L;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Fun Li 2023/10/23 10:01
|
||||
@@ -62,6 +63,9 @@ public class EventCenterHttpRequest {
|
||||
@Value("#{'${sms.whiteList:,}'.split(',')}")
|
||||
private List<String> whiteList;
|
||||
|
||||
private static final String PC_PATH_KEY = "pcPath";
|
||||
private static final String MOBILE_PATH_KEY = "mobilePath";
|
||||
|
||||
/**
|
||||
* 创建单个事件
|
||||
* @param request {@link com.cool.store.request.event.CreateSingleEventRequest}
|
||||
@@ -86,8 +90,11 @@ public class EventCenterHttpRequest {
|
||||
public void sendFeiShuNotice(FeiShuNoticeMsgEnum msgEnum, List<String> receiverIds, Object... objects) throws ApiException {
|
||||
//1. 组织消息参数,SendMsgRequest 的 cardParams,需要填入的参数为模板中 ${} 中的参数
|
||||
HashMap<String, String> cardParams = new HashMap<>();
|
||||
String PCPath = getPath(msgEnum.getPCPath(), false, objects);
|
||||
String mobilePath = getPath(msgEnum.getMobilePath(), true, objects);
|
||||
String PCPath = msgEnum.getPCPath();
|
||||
String mobilePath = msgEnum.getMobilePath();
|
||||
Map<String, String> pathMap = generatePath(PCPath, mobilePath, objects);
|
||||
PCPath = pathMap.get(PC_PATH_KEY);
|
||||
mobilePath = pathMap.get(MOBILE_PATH_KEY);
|
||||
try {
|
||||
PCPath = URLEncoder.encode(PCPath, "UTF-8");
|
||||
mobilePath = URLEncoder.encode(mobilePath, "UTF-8");
|
||||
@@ -166,24 +173,32 @@ public class EventCenterHttpRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据消息路径模板返回格式化参数后的路径
|
||||
* @param pathPattern 路径模板
|
||||
* @param whetherSpliceParamsArray 是否裁剪参数,将数组用于格式化的参数从数组中裁剪
|
||||
* @param objects 参数数组
|
||||
* @return 格式化后的带参数路径
|
||||
* 格式化传入的跳转路径
|
||||
* 要求 PC 和 mobile 的路径参数数量相同、顺序相同(若无路径参数,则忽略)
|
||||
* @param pcPath PC 跳转路径
|
||||
* @param mobilePath mobile 跳转路径
|
||||
* @param objects 公共参数
|
||||
* @return Map: {pcPath: 格式化后的 PC 跳转链接, mobilePath: 格式化后的 mobile 跳转链接}
|
||||
*/
|
||||
private String getPath(String pathPattern, boolean whetherSpliceParamsArray, Object... objects) {
|
||||
//无需格式化
|
||||
if (!pathPattern.contains("{0}")) {
|
||||
return pathPattern;
|
||||
private Map<String, String> generatePath(String pcPath, String mobilePath, Object... objects) {
|
||||
int paramsCount = 0;
|
||||
HashMap<String, String> res = new HashMap<>();
|
||||
//初始化防空
|
||||
res.put(PC_PATH_KEY, pcPath);
|
||||
res.put(MOBILE_PATH_KEY, mobilePath);
|
||||
//格式化
|
||||
if (pcPath.contains("{0}")) {
|
||||
MessageFormat pcMessageFormat = new MessageFormat(pcPath);
|
||||
paramsCount = pcMessageFormat.getFormatsByArgumentIndex().length;
|
||||
res.put(PC_PATH_KEY, pcMessageFormat.format(objects));
|
||||
}
|
||||
MessageFormat messageFormat = new MessageFormat(pathPattern);
|
||||
int paramsCount = messageFormat.getFormatsByArgumentIndex().length;
|
||||
String wholePath = messageFormat.format(objects);
|
||||
if (whetherSpliceParamsArray) {
|
||||
System.arraycopy(objects, paramsCount, objects, 0, objects.length - paramsCount);
|
||||
if (mobilePath.contains("{0}")) {
|
||||
MessageFormat mobileMessageFormat = new MessageFormat(pcPath);
|
||||
paramsCount = Math.max(mobileMessageFormat.getFormatsByArgumentIndex().length, paramsCount);
|
||||
res.put(MOBILE_PATH_KEY, mobileMessageFormat.format(objects));
|
||||
}
|
||||
return wholePath;
|
||||
System.arraycopy(objects, paramsCount, objects, 0, objects.length - paramsCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -665,6 +665,8 @@ public class ExhibitionServiceImpl implements ExhibitionService {
|
||||
List<String> feishuUserIdListByUserIds = enterpriseUserDAO.getFeishuUserIdListByUserIds(Arrays.asList(investManager));
|
||||
eventCenterHttpRequest.sendFeiShuNotice(FeiShuNoticeMsgEnum.PARTNER_SIGNUP_EXHIBITION,
|
||||
feishuUserIdListByUserIds,
|
||||
mobileCheckDTO.getLineId(),
|
||||
mobileCheckDTO.getPartnerId(),
|
||||
mobileCheckDTO.getPartnerName(),
|
||||
mobileCheckDTO.getMobile(),
|
||||
DateUtils.format(hyExhibitionDO.getStartDate(),CoolDateUtils.DATE_FORMAT_DAY_2),
|
||||
|
||||
@@ -58,7 +58,7 @@ class EventRequestTest extends AbstractJUnit4SpringContextTests {
|
||||
//8. 会销协作通知
|
||||
eventCenterHttpRequest.sendFeiShuNotice(FeiShuNoticeMsgEnum.EXHIBITION_COLLABORATOR, Arrays.asList(userId), "68", "老大", "会销", "2023-12-31", "系东方大酒店");
|
||||
//9. 线索报名会销
|
||||
eventCenterHttpRequest.sendFeiShuNotice(FeiShuNoticeMsgEnum.PARTNER_SIGNUP_EXHIBITION, Arrays.asList(userId), "237298", "e2771d330ec54648841a38607f06b598", "线索客户", "1008611", "2023-10-24", "会销", "蜀山");
|
||||
eventCenterHttpRequest.sendFeiShuNotice(FeiShuNoticeMsgEnum.PARTNER_SIGNUP_EXHIBITION, Arrays.asList(userId), "237409", "3eb15ac62c1949ef9b17522386b532d7", "线索客户", "1008611", "2023-10-24", "会销", "蜀山");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user