diff --git a/backend/mci-channel-wecom/src/main/java/com/sino/mci/channel/wecom/WeComBotSender.java b/backend/mci-channel-wecom/src/main/java/com/sino/mci/channel/wecom/WeComBotSender.java index c94a23c..744c880 100644 --- a/backend/mci-channel-wecom/src/main/java/com/sino/mci/channel/wecom/WeComBotSender.java +++ b/backend/mci-channel-wecom/src/main/java/com/sino/mci/channel/wecom/WeComBotSender.java @@ -85,7 +85,11 @@ public class WeComBotSender { private String resolveWebhookUrl(Map extra, String key) { String customUrl = getString(extra, "webhook_url"); if (customUrl != null && !customUrl.isBlank()) { - return String.format(customUrl, key); + if (customUrl.contains("%s")) { + return customUrl.replace("%s", key); + } + log.warn("[WeComBot] custom webhook_url missing %s placeholder; appending key param"); + return customUrl.contains("?") ? customUrl + "&key=" + key : customUrl + "?key=" + key; } return String.format(DEFAULT_WEBHOOK_URL, key); } diff --git a/backend/mci-server/src/main/java/com/sino/mci/send/service/SendService.java b/backend/mci-server/src/main/java/com/sino/mci/send/service/SendService.java index aaf95f0..04adf47 100644 --- a/backend/mci-server/src/main/java/com/sino/mci/send/service/SendService.java +++ b/backend/mci-server/src/main/java/com/sino/mci/send/service/SendService.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.sino.mci.channel.adapter.registry.ChannelAdapterRegistry; import com.sino.mci.channel.common.dto.SendMessageRequest; import com.sino.mci.channel.common.dto.SendMessageResult; +import com.sino.mci.channel.common.model.AccountType; import com.sino.mci.channel.common.model.ChannelType; import com.sino.mci.channel.common.spi.ChannelAdapter; import com.sino.mci.channel.entity.ChannelAccount; @@ -79,6 +80,8 @@ public class SendService { private static final int SEND_STATUS_SUCCESS = 2; private static final int SEND_STATUS_FAILED = 3; + private static final int CONVERSATION_TYPE_SINGLE = 1; + private static final int CONVERSATION_TYPE_GROUP = 2; private static final int CONVERSATION_SCENE_INTERNAL = 1; private static final int CONVERSATION_SCENE_EXTERNAL = 2; private static final Set ACCOUNT_TYPES_BOT = Set.of(6); @@ -350,14 +353,22 @@ public class SendService { throw new BusinessException("会话不存在: " + conversationId); } - ChannelType channelType = resolveChannelTypeForScene(conversation.getConversationScene()); - Set accountTypes = resolveAccountTypesForScene(conversation.getConversationScene()); + ChannelType channelType; + Set accountTypes; + // 单聊未回填场景时保持旧行为,按 channelStrategy 默认 WECOM 路由;群聊必须按场景路由 + if (conversation.getConversationType() != null && conversation.getConversationType() == CONVERSATION_TYPE_SINGLE) { + channelType = parseChannelType(extractChannelType(channelStrategy)); + accountTypes = null; + } else { + channelType = resolveChannelTypeForScene(conversation.getConversationScene()); + accountTypes = resolveAccountTypesForScene(conversation.getConversationScene()); + } Long accountId = selectSendAccount(tenantCode, conversationId, channelType, accountTypes, channelStrategy); if (accountId == null) { accountId = conversation.getOwnerAccountId(); ChannelAccount ownerAccount = accountMapper.selectById(accountId); - if (ownerAccount == null || !accountTypes.contains(ownerAccount.getAccountType())) { + if (ownerAccount == null || (accountTypes != null && !accountTypes.contains(ownerAccount.getAccountType()))) { accountId = null; } } @@ -970,6 +981,10 @@ public class SendService { if (StringUtils.hasText(account.getAccountId())) { extra.put("account_id", account.getAccountId()); } + if (account.getAccountType() != null && account.getAccountType() == AccountType.WECOM_BOT.getCode() + && StringUtils.hasText(account.getExtInfo())) { + extra.put("webhook_url", account.getExtInfo()); + } } extra.put("record_id", record.getId()); extra.put("tenant_code", record.getTenantCode());