1、修复小程序手机号登录问题

2、调整OA
This commit is contained in:
2026-09-18 19:48:16 +08:00
parent a2d9cfec02
commit 8d13978e84
4 changed files with 63 additions and 39 deletions
@@ -1,24 +1,45 @@
package org.springblade.thirdparty.oa.config;
import feign.Logger;
import feign.Request;
import org.springblade.thirdparty.oa.interceptor.OARequestInterceptor;
import org.springframework.cloud.openfeign.clientconfig.FeignClientConfigurer;
import org.springframework.context.annotation.Bean;
import java.util.concurrent.TimeUnit;
/**
* OA Feign 客户端配置
* OA Feign 客户端配置
* <p>
* 必须关闭父上下文继承,否则全局 {@code BladeFeignRequestInterceptor}
* 会把当前登录请求的 Host、Content-Length、Blade-Auth 等头再次写入,
* 导致 gwzh nginx 返回 400。
*
* @author bfhuange
* @since 2024/12/18
*/
public class OAFeignClientConfig {
@Bean
public FeignClientConfigurer feignClientConfigurer() {
return new FeignClientConfigurer() {
@Override
public boolean inheritParentConfiguration() {
return false;
}
};
}
@Bean
public OARequestInterceptor requestInterceptor(OAProperties oaProperties) {
return new OARequestInterceptor(oaProperties);
}
@Bean
public Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
@Bean
public Request.Options options() {
return new Request.Options(10, TimeUnit.SECONDS, 120, TimeUnit.SECONDS, true);
@@ -34,16 +34,21 @@ import org.springblade.thirdparty.oa.config.OAProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/**
* OA Feign 请求拦截器。
* <p>
* 对齐可用 curl:仅发送 Authorization + Content-Type,并清掉登录请求透传头,
* 避免 nginx 因 Host/Content-Length/Blade-Auth 等返回 400。
* 对齐可用 curl:仅发送 Authorization + Content-Type
* 配合 {@code FeignClientConfigurer#inheritParentConfiguration()=false}
* 避免全局 BladeFeignRequestInterceptor 透传登录请求头。
*
* @author Chill
*/
@@ -53,38 +58,16 @@ public class OARequestInterceptor implements RequestInterceptor {
private static final String BASIC_PREFIX = "Basic ";
private static final String BEARER_PREFIX = "Bearer ";
private static final Set<String> STRIP_HEADERS = Set.of(
HttpHeaders.HOST.toLowerCase(Locale.ROOT),
HttpHeaders.CONTENT_LENGTH.toLowerCase(Locale.ROOT),
HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ROOT),
HttpHeaders.ACCEPT.toLowerCase(Locale.ROOT),
HttpHeaders.CONNECTION.toLowerCase(Locale.ROOT),
HttpHeaders.TRANSFER_ENCODING.toLowerCase(Locale.ROOT),
HttpHeaders.COOKIE.toLowerCase(Locale.ROOT),
private static final Set<String> KEEP_HEADERS = Set.of(
HttpHeaders.AUTHORIZATION.toLowerCase(Locale.ROOT),
HttpHeaders.ACCEPT_ENCODING.toLowerCase(Locale.ROOT),
HttpHeaders.ORIGIN.toLowerCase(Locale.ROOT),
HttpHeaders.REFERER.toLowerCase(Locale.ROOT),
HttpHeaders.EXPECT.toLowerCase(Locale.ROOT),
"keep-alive",
"upgrade",
"te",
"trailer",
"forwarded",
"x-real-ip",
"x-request-id",
"blade-auth",
"blade-requested-with",
"tenant-id",
"auth"
HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ROOT)
);
private final OAProperties oaProperties;
@Override
public void apply(RequestTemplate template) {
stripForwardedHeaders(template);
// 与可用 curl 保持一致:Authorization + Content-Type
stripUnwantedHeaders(template);
template.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
String authorization = normalizeAuthorization(oaProperties.getAuthorization());
@@ -93,17 +76,37 @@ public class OARequestInterceptor implements RequestInterceptor {
} else {
log.warn("OA Feign 未配置 third-party.oa.authorizationgwzh 网关可能拒绝请求");
}
logRequest(template);
}
private void stripForwardedHeaders(RequestTemplate template) {
List<String> headerNames = new ArrayList<>(template.headers().keySet());
/**
* 打印 OA Feign 最终发出的请求头与 body,便于对照 curl。
*/
private void logRequest(RequestTemplate template) {
String bodyText = "";
byte[] body = template.body();
if (body != null && body.length > 0) {
Charset charset = template.requestCharset() == null ? StandardCharsets.UTF_8 : template.requestCharset();
bodyText = new String(body, charset);
}
log.info("OA Feign 请求 method={}, url={}{}{}, headers={}, body={}",
template.method(),
template.feignTarget() == null ? "" : template.feignTarget().url(),
template.path(),
template.queryLine() == null ? "" : template.queryLine(),
template.headers(),
bodyText);
}
/**
* 只保留 Authorization / Content-Type,其余全部移除。
*/
private void stripUnwantedHeaders(RequestTemplate template) {
Map<String, Collection<String>> headers = template.headers();
List<String> headerNames = new ArrayList<>(headers.keySet());
for (String headerName : headerNames) {
String lowerName = headerName.toLowerCase(Locale.ROOT);
if (STRIP_HEADERS.contains(lowerName)
|| lowerName.startsWith("x-forwarded-")
|| lowerName.startsWith("blade-")
|| lowerName.startsWith("x-b3-")
|| lowerName.startsWith("sw8")) {
if (!KEEP_HEADERS.contains(headerName.toLowerCase(Locale.ROOT))) {
template.removeHeader(headerName);
}
}