feat: 优化钉钉CorpId配置,添加格式提示说明
This commit is contained in:
parent
c001103192
commit
ccdc77d8eb
@ -211,38 +211,38 @@ public class DingTalkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建钉钉应用内跳转链接
|
* 构建钉钉跳转链接
|
||||||
* 格式: dingtalk://dingtalkclient/action/openapp?corpid=xxx&container_type=work_platform&app_id=0_xxx&redirect_type=jump&redirect_url=xxx
|
* 如果配置了正确的corpId(以ding开头),使用应用内跳转;否则使用简单外链方式
|
||||||
* @param config 钉钉配置
|
* @param config 钉钉配置
|
||||||
* @param targetUrl 目标跳转地址
|
* @param targetUrl 目标跳转地址
|
||||||
* @return 钉钉应用内跳转链接
|
* @return 钉钉跳转链接
|
||||||
*/
|
*/
|
||||||
private String buildDingTalkAppLink(DingTalkConfig config, String targetUrl) {
|
private String buildDingTalkAppLink(DingTalkConfig config, String targetUrl) {
|
||||||
try {
|
try {
|
||||||
String corpId = config.getCorpId();
|
String corpId = config.getCorpId();
|
||||||
String agentId = config.getAgentId();
|
String agentId = config.getAgentId();
|
||||||
|
|
||||||
// 如果没有配置corpId或agentId,回退到旧的跳转方式
|
// 检查corpId是否是有效的钉钉企业ID格式(以ding开头)
|
||||||
if (corpId == null || corpId.trim().isEmpty() || agentId == null || agentId.trim().isEmpty()) {
|
boolean validCorpId = corpId != null && corpId.trim().startsWith("ding");
|
||||||
log.warn("钉钉corpId或agentId未配置,使用普通跳转链接");
|
boolean validAgentId = agentId != null && !agentId.trim().isEmpty();
|
||||||
return "dingtalk://dingtalkclient/page/link?url=" +
|
|
||||||
URLEncoder.encode(targetUrl, StandardCharsets.UTF_8.toString());
|
if (validCorpId && validAgentId) {
|
||||||
|
// 使用应用内跳转
|
||||||
|
String appId = "0_" + agentId.trim();
|
||||||
|
String encodedUrl = URLEncoder.encode(targetUrl, StandardCharsets.UTF_8.toString());
|
||||||
|
String dingTalkLink = String.format(
|
||||||
|
"dingtalk://dingtalkclient/action/openapp?corpid=%s&container_type=work_platform&app_id=%s&redirect_type=jump&redirect_url=%s",
|
||||||
|
corpId.trim(), appId, encodedUrl
|
||||||
|
);
|
||||||
|
log.debug("使用钉钉应用内跳转: {}", dingTalkLink);
|
||||||
|
return dingTalkLink;
|
||||||
|
} else {
|
||||||
|
// corpId格式不正确,使用简单外链方式
|
||||||
|
log.info("corpId格式不正确或未配置,使用简单外链跳转。当前corpId: {}", corpId);
|
||||||
|
return targetUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建钉钉应用内跳转链接
|
|
||||||
// app_id 格式为 0_agentId
|
|
||||||
String appId = "0_" + agentId;
|
|
||||||
String encodedUrl = URLEncoder.encode(targetUrl, StandardCharsets.UTF_8.toString());
|
|
||||||
|
|
||||||
String dingTalkLink = String.format(
|
|
||||||
"dingtalk://dingtalkclient/action/openapp?corpid=%s&container_type=work_platform&app_id=%s&redirect_type=jump&redirect_url=%s",
|
|
||||||
corpId, appId, encodedUrl
|
|
||||||
);
|
|
||||||
|
|
||||||
log.debug("构建钉钉应用内跳转链接: {}", dingTalkLink);
|
|
||||||
return dingTalkLink;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("构建钉钉应用内跳转链接失败", e);
|
log.error("构建钉钉跳转链接失败", e);
|
||||||
return targetUrl;
|
return targetUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -751,7 +751,11 @@
|
|||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
<a-form-item label="企业ID (CorpId)">
|
<a-form-item label="企业ID (CorpId)">
|
||||||
<a-input v-model:value="dingTalkConfig.corpId" placeholder="钉钉企业ID" />
|
<a-input v-model:value="dingTalkConfig.corpId" placeholder="以ding开头,如:dingxxxxxxxxxxxxxxxx" />
|
||||||
|
<div style="margin-top: 4px; font-size: 12px; color: #888;">
|
||||||
|
<Icon name="info" size="sm" color="#888" style="margin-right: 4px;" />
|
||||||
|
在钉钉开放平台 → 应用开发 → 企业内部开发 → 应用信息中查看,格式以 "ding" 开头
|
||||||
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-divider orientation="left">机器人配置(可选)</a-divider>
|
<a-divider orientation="left">机器人配置(可选)</a-divider>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user