1
This commit is contained in:
@@ -185,4 +185,20 @@ xss:
|
|||||||
excludes: /system/notice
|
excludes: /system/notice
|
||||||
# 匹配链接
|
# 匹配链接
|
||||||
urlPatterns: /system/*,/monitor/*,/tool/*
|
urlPatterns: /system/*,/monitor/*,/tool/*
|
||||||
|
# 腾讯文档开放平台配置
|
||||||
|
tencent:
|
||||||
|
doc:
|
||||||
|
# 应用ID(需要在腾讯文档开放平台申请)
|
||||||
|
app-id: 90aa0b70e7704c2abd2a42695d5144a4
|
||||||
|
# 应用密钥(需要在腾讯文档开放平台申请)
|
||||||
|
app-secret: G8ZdSWcoViIawygo7JSolE86PL32UO0O
|
||||||
|
# 授权回调地址(需要在腾讯文档开放平台配置,必须使用HTTPS)
|
||||||
|
redirect-uri: https://jarvis.van333.cn/jarvis/tendoc/oauth/callback
|
||||||
|
# API基础地址
|
||||||
|
api-base-url: https://docs.qq.com/open/v1
|
||||||
|
# OAuth授权地址
|
||||||
|
oauth-url: https://docs.qq.com/oauth/v2/authorize
|
||||||
|
# 获取Token地址
|
||||||
|
token-url: https://docs.qq.com/oauth/v2/token
|
||||||
|
# 刷新Token地址
|
||||||
|
refresh-token-url: https://docs.qq.com/oauth/v2/token
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package com.ruoyi.jarvis.config;
|
package com.ruoyi.jarvis.config;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 腾讯文档开放平台配置
|
* 腾讯文档开放平台配置
|
||||||
@@ -9,9 +14,12 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author system
|
* @author system
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@Component
|
||||||
@ConfigurationProperties(prefix = "tencent.doc")
|
@ConfigurationProperties(prefix = "tencent.doc")
|
||||||
public class TencentDocConfig {
|
public class TencentDocConfig {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(TencentDocConfig.class);
|
||||||
|
|
||||||
/** 应用ID */
|
/** 应用ID */
|
||||||
private String appId;
|
private String appId;
|
||||||
|
|
||||||
@@ -33,6 +41,27 @@ public class TencentDocConfig {
|
|||||||
/** 刷新Token地址 */
|
/** 刷新Token地址 */
|
||||||
private String refreshTokenUrl = "https://docs.qq.com/oauth/v2/token";
|
private String refreshTokenUrl = "https://docs.qq.com/oauth/v2/token";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置初始化后验证
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
log.info("腾讯文档配置加载 - appId: {}, redirectUri: {}, apiBaseUrl: {}",
|
||||||
|
appId != null && appId.length() > 10 ? appId.substring(0, 10) + "..." : (appId != null ? appId : "null"),
|
||||||
|
redirectUri != null ? redirectUri : "null",
|
||||||
|
apiBaseUrl);
|
||||||
|
|
||||||
|
if (appId == null || appId.trim().isEmpty()) {
|
||||||
|
log.warn("腾讯文档应用ID未配置!请检查application-dev.yml中的tencent.doc.app-id");
|
||||||
|
}
|
||||||
|
if (appSecret == null || appSecret.trim().isEmpty()) {
|
||||||
|
log.warn("腾讯文档应用密钥未配置!请检查application-dev.yml中的tencent.doc.app-secret");
|
||||||
|
}
|
||||||
|
if (redirectUri == null || redirectUri.trim().isEmpty()) {
|
||||||
|
log.warn("腾讯文档回调地址未配置!请检查application-dev.yml中的tencent.doc.redirect-uri");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getAppId() {
|
public String getAppId() {
|
||||||
return appId;
|
return appId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,19 +29,42 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthUrl() {
|
public String getAuthUrl() {
|
||||||
|
if (tencentDocConfig == null) {
|
||||||
|
throw new RuntimeException("腾讯文档配置未加载,请检查TencentDocConfig是否正确注入");
|
||||||
|
}
|
||||||
|
|
||||||
String appId = tencentDocConfig.getAppId();
|
String appId = tencentDocConfig.getAppId();
|
||||||
String redirectUri = tencentDocConfig.getRedirectUri();
|
String redirectUri = tencentDocConfig.getRedirectUri();
|
||||||
String oauthUrl = tencentDocConfig.getOauthUrl();
|
String oauthUrl = tencentDocConfig.getOauthUrl();
|
||||||
|
|
||||||
|
log.debug("获取授权URL - appId: {}, redirectUri: {}, oauthUrl: {}", appId, redirectUri, oauthUrl);
|
||||||
|
|
||||||
|
// 验证配置参数
|
||||||
|
if (appId == null || appId.trim().isEmpty()) {
|
||||||
|
throw new RuntimeException("腾讯文档应用ID未配置,请检查application-dev.yml中的tencent.doc.app-id配置");
|
||||||
|
}
|
||||||
|
if (redirectUri == null || redirectUri.trim().isEmpty()) {
|
||||||
|
throw new RuntimeException("腾讯文档回调地址未配置,请检查application-dev.yml中的tencent.doc.redirect-uri配置");
|
||||||
|
}
|
||||||
|
if (oauthUrl == null || oauthUrl.trim().isEmpty()) {
|
||||||
|
oauthUrl = "https://docs.qq.com/oauth/v2/authorize"; // 使用默认值
|
||||||
|
log.warn("OAuth URL未配置,使用默认值: {}", oauthUrl);
|
||||||
|
}
|
||||||
|
|
||||||
// 构建授权URL(根据腾讯文档官方文档:https://docs.qq.com/open/document/app/oauth2/authorize.html)
|
// 构建授权URL(根据腾讯文档官方文档:https://docs.qq.com/open/document/app/oauth2/authorize.html)
|
||||||
StringBuilder authUrl = new StringBuilder();
|
StringBuilder authUrl = new StringBuilder();
|
||||||
authUrl.append(oauthUrl);
|
authUrl.append(oauthUrl);
|
||||||
authUrl.append("?client_id=").append(appId);
|
authUrl.append("?client_id=").append(appId);
|
||||||
try {
|
try {
|
||||||
authUrl.append("&redirect_uri=").append(java.net.URLEncoder.encode(redirectUri, "UTF-8"));
|
// 确保redirectUri不为null后再编码
|
||||||
|
String encodedRedirectUri = java.net.URLEncoder.encode(redirectUri, "UTF-8");
|
||||||
|
authUrl.append("&redirect_uri=").append(encodedRedirectUri);
|
||||||
} catch (java.io.UnsupportedEncodingException e) {
|
} catch (java.io.UnsupportedEncodingException e) {
|
||||||
log.error("URL编码失败", e);
|
log.error("URL编码失败", e);
|
||||||
authUrl.append("&redirect_uri=").append(redirectUri);
|
authUrl.append("&redirect_uri=").append(redirectUri);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("构建授权URL失败", e);
|
||||||
|
throw new RuntimeException("构建授权URL失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
authUrl.append("&response_type=code");
|
authUrl.append("&response_type=code");
|
||||||
authUrl.append("&scope=all"); // 根据官方文档,scope固定为all
|
authUrl.append("&scope=all"); // 根据官方文档,scope固定为all
|
||||||
@@ -50,7 +73,9 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
|||||||
String state = java.util.UUID.randomUUID().toString();
|
String state = java.util.UUID.randomUUID().toString();
|
||||||
authUrl.append("&state=").append(state);
|
authUrl.append("&state=").append(state);
|
||||||
|
|
||||||
return authUrl.toString();
|
String result = authUrl.toString();
|
||||||
|
log.info("生成授权URL: {}", result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user