This commit is contained in:
van
2026-03-23 17:19:55 +08:00
parent 9bb7cfc7fb
commit 184a53005d
3 changed files with 52 additions and 1 deletions

View File

@@ -44,8 +44,9 @@ public class KdocsCallbackController extends BaseController {
log.error("金山文档授权失败: {}", msg);
return htmlPage(false, "授权失败: " + msg, null);
}
// 无 code多为平台校验回调可达性或用户直接打开本地址非授权失败
if (StringUtils.isBlank(code)) {
return htmlPage(false, "缺少授权码 code", null);
return callbackEndpointInfoPage();
}
log.info("金山文档授权回调 code 已收到 state={}", state);
KdocsTokenInfo tokenInfo = kdocsOAuthService.getAccessTokenByCode(code);
@@ -83,4 +84,20 @@ public class KdocsCallbackController extends BaseController {
html.append("</script></body></html>");
return new ResponseEntity<>(html.toString(), headers, HttpStatus.OK);
}
/**
* 无授权参数时的占位页HTTP 200避免被误判为「回调不可用」也不向 opener 误发失败消息。
*/
private ResponseEntity<String> callbackEndpointInfoPage() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_HTML);
String html = "<!DOCTYPE html><html lang='zh-CN'><head><meta charset='UTF-8'><meta name='robots' content='noindex'>"
+ "<title>金山文档授权回调</title></head>"
+ "<body style='font-family:sans-serif;text-align:center;padding:40px;color:#333'>"
+ "<h2>金山文档授权回调</h2>"
+ "<p>此地址用于 OAuth 授权完成后的跳转,请勿直接收藏或打开。</p>"
+ "<p>请在系统中点击「连接金山文档」或「授权」后,由金山文档页面自动跳转到此处。</p>"
+ "</body></html>";
return new ResponseEntity<>(html, headers, HttpStatus.OK);
}
}

View File

@@ -0,0 +1,30 @@
package com.ruoyi.web.controller.jarvis;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.net.URI;
/**
* 迁移金山文档后,开放平台若仍登记旧回调 /wps365-callback则 302 到新路径并保留 query含 code
*/
@Anonymous
@RestController
public class Wps365ToKdocsCallbackRedirectController {
@Anonymous
@GetMapping("/wps365-callback")
public ResponseEntity<Void> redirectToKdocs(HttpServletRequest request) {
String q = request.getQueryString();
String path = "/kdocs-callback" + (StringUtils.isNotBlank(q) ? "?" + q : "");
HttpHeaders headers = new HttpHeaders();
headers.setLocation(URI.create(path));
return new ResponseEntity<>(null, headers, HttpStatus.FOUND);
}
}