This commit is contained in:
Leo
2026-01-15 20:37:49 +08:00
parent 8802e68106
commit 7f7bec8d29
2 changed files with 183 additions and 5 deletions

View File

@@ -59,7 +59,11 @@ public class WPS365OAuthServiceImpl implements IWPS365OAuthService {
// 构建授权URL
StringBuilder authUrl = new StringBuilder();
authUrl.append(oauthUrl);
// WPS365可能使用 app_id 而不是 client_id先尝试 client_id标准OAuth2参数
// 如果失败,可能需要改为 app_id
authUrl.append("?client_id=").append(appId);
log.debug("授权URL参数 - client_id: {}", appId);
// 重要redirect_uri必须与WPS365开放平台配置的回调地址完全一致
// 包括协议(https)、域名、路径,不能有多余的斜杠
@@ -69,6 +73,11 @@ public class WPS365OAuthServiceImpl implements IWPS365OAuthService {
finalRedirectUri = finalRedirectUri.substring(0, finalRedirectUri.length() - 1);
}
// 验证redirect_uri不为空
if (finalRedirectUri == null || finalRedirectUri.isEmpty()) {
throw new RuntimeException("redirect_uri不能为空请检查application.yml中的wps365.redirect-uri配置");
}
try {
String encodedRedirectUri = java.net.URLEncoder.encode(finalRedirectUri, "UTF-8");
authUrl.append("&redirect_uri=").append(encodedRedirectUri);
@@ -77,21 +86,37 @@ public class WPS365OAuthServiceImpl implements IWPS365OAuthService {
log.error("URL编码失败", e);
authUrl.append("&redirect_uri=").append(finalRedirectUri);
}
authUrl.append("&response_type=code");
// WPS365的scope根据官方文档设置
// 注意scope参数可能需要根据实际申请的权限调整
authUrl.append("&scope=file.read,ksheet.read,user.info");
// 添加state参数
// response_type参数必需
authUrl.append("&response_type=code");
log.debug("授权URL参数 - response_type: code");
// scope参数必需根据WPS365文档
String scope = "file.read,ksheet.read,user.info";
authUrl.append("&scope=").append(scope);
log.debug("授权URL参数 - scope: {}", scope);
// state参数推荐用于防止CSRF攻击
if (state == null || state.trim().isEmpty()) {
state = UUID.randomUUID().toString();
}
authUrl.append("&state=").append(state);
log.debug("授权URL参数 - state: {}", state);
String result = authUrl.toString();
log.info("生成授权URL: {}", result);
log.warn("⚠️ 请确保WPS365开放平台配置的回调地址与以下地址完全一致包括协议、域名、路径:");
log.warn("⚠️ 回调地址: {}", finalRedirectUri);
log.info("📋 授权请求参数清单:");
log.info(" - client_id: {}", appId);
log.info(" - redirect_uri: {}", finalRedirectUri);
log.info(" - response_type: code");
log.info(" - scope: {}", scope);
log.info(" - state: {}", state);
log.info("如果仍然报错,请检查:");
log.info(" 1. WPS365平台配置的回调地址是否与上述redirect_uri完全一致");
log.info(" 2. 参数名是否正确WPS365可能使用app_id而不是client_id");
log.info(" 3. scope权限是否已在WPS365平台申请");
return result;
}