fix (farm): 集成测试: 微服务API,微信端接口
- 微信端,获取多个服务token,用于切换服务
This commit is contained in:
@@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
|||||||
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
||||||
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
|
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
|
||||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||||
|
import cn.iocoder.yudao.module.system.util.TokenExtractorUtil;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
@@ -154,7 +155,8 @@ public class AuthController {
|
|||||||
@Operation(summary = "获取租户的令牌列表")
|
@Operation(summary = "获取租户的令牌列表")
|
||||||
public CommonResult<List<TenantTokenRespVO>> getTenantTokenList(@RequestHeader("authorization") String authorization,
|
public CommonResult<List<TenantTokenRespVO>> getTenantTokenList(@RequestHeader("authorization") String authorization,
|
||||||
@RequestBody @Valid TenantTokenReqVO reqVO) {
|
@RequestBody @Valid TenantTokenReqVO reqVO) {
|
||||||
List<TenantTokenRespVO> res = authService.getTenantTokenList(reqVO.getPhoneNumber(), authorization);
|
String token = TokenExtractorUtil.extractToken(authorization);
|
||||||
|
List<TenantTokenRespVO> res = authService.getTenantTokenList(reqVO.getPhoneNumber(), token);
|
||||||
return success(res);
|
return success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: binda
|
||||||
|
* @date: 2025/9/16 20:31
|
||||||
|
*/
|
||||||
|
public class TokenExtractorUtil {
|
||||||
|
/**
|
||||||
|
* 从Bearer令牌字符串中截取令牌部分
|
||||||
|
* @param bearerToken 完整的Bearer令牌字符串,格式为 "Bearer {token}"
|
||||||
|
* @return 截取后的令牌字符串,如果格式不正确则返回null
|
||||||
|
*/
|
||||||
|
public static String extractToken(String bearerToken) {
|
||||||
|
if (bearerToken == null || bearerToken.trim().isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用空格分割字符串
|
||||||
|
String[] parts = bearerToken.split(" ");
|
||||||
|
|
||||||
|
// 检查格式是否正确(至少有两部分,第一部分是"Bearer")
|
||||||
|
if (parts.length < 2 || !"Bearer".equals(parts[0])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回令牌部分(可能是第二部分或后面所有部分的组合)
|
||||||
|
// 处理令牌中可能包含空格的情况
|
||||||
|
if (parts.length == 2) {
|
||||||
|
return parts[1];
|
||||||
|
} else {
|
||||||
|
// 如果令牌本身包含空格,重新组合第二部分及之后的部分
|
||||||
|
StringBuilder tokenBuilder = new StringBuilder();
|
||||||
|
for (int i = 1; i < parts.length; i++) {
|
||||||
|
if (i > 1) {
|
||||||
|
tokenBuilder.append(" ");
|
||||||
|
}
|
||||||
|
tokenBuilder.append(parts[i]);
|
||||||
|
}
|
||||||
|
return tokenBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user