v1.15 修改创建令牌问题
This commit is contained in:
+9
-13
@@ -1,19 +1,15 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Example sysUserDetails template template
|
||||
### Example sysUserDetails template
|
||||
|
||||
# IntelliJ project files
|
||||
.idea
|
||||
.idea/
|
||||
*.iml
|
||||
out
|
||||
gen
|
||||
target
|
||||
out/
|
||||
gen/
|
||||
target/
|
||||
*.log
|
||||
logs
|
||||
.history
|
||||
lib
|
||||
sql
|
||||
|
||||
docker/*/data/
|
||||
docker/minio/config
|
||||
docker/xxljob/logs
|
||||
logs/
|
||||
.history/
|
||||
lib/
|
||||
sql/
|
||||
docs/
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
# 基础镜像
|
||||
FROM openjdk:17-jdk-alpine
|
||||
|
||||
# 维护者信息
|
||||
MAINTAINER youlai <youlaitech@163.com>
|
||||
|
||||
# 设置国内镜像源(中国科技大学镜像源),修改容器时区(alpine镜像需安装tzdata来设置时区),安装字体库(验证码)
|
||||
RUN echo -e https://mirrors.ustc.edu.cn/alpine/v3.7/main/ > /etc/apk/repositories \
|
||||
&& apk --no-cache add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone \
|
||||
&& apk --no-cache add ttf-dejavu fontconfig
|
||||
|
||||
# 在运行时自动挂载 /tmp 目录为匿名卷,提高可移植性。如果 /tmp 目录没有挂载为卷,这些文件会写入容器的可写层,可能导致容器镜像膨胀。
|
||||
VOLUME /tmp
|
||||
|
||||
# 将构建的 Spring Boot 可执行 JAR 复制到容器中,重命名为 app.jar
|
||||
ADD target/youlai-boot.jar app.jar
|
||||
|
||||
# 指定容器启动时执行的命令
|
||||
CMD java \
|
||||
-Xms512m -Xmx512m \
|
||||
-Djava.security.egd=file:/dev/./urandom \
|
||||
-jar /app.jar
|
||||
|
||||
# 暴露容器的端口
|
||||
EXPOSE 8989
|
||||
@@ -1,69 +0,0 @@
|
||||
# 创建一个名为 "youlai-boot" 的桥接网络,在同一个网络中的容器可以通过容器名互相访问
|
||||
networks:
|
||||
youlai-boot:
|
||||
driver: bridge
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0.29
|
||||
container_name: mysql
|
||||
restart: unless-stopped # 重启策略:除非手动停止容器,否则自动重启
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- LANG= en_US.UTF-8
|
||||
- MYSQL_ROOT_PASSWORD=123456 #设置 root 用户的密码
|
||||
volumes:
|
||||
- ./mysql/conf/my.cnf:/etc/my.cnf # 挂载 my.cnf 文件到容器的指定路径
|
||||
- ./mysql/data:/var/lib/mysql # 持久化 MySQL 数据
|
||||
- ../sql/mysql:/docker-entrypoint-initdb.d # 初始化 SQL 脚本目录
|
||||
ports:
|
||||
- 3306:3306
|
||||
networks:
|
||||
- youlai-boot # 加入 "youlai-boot" 网络
|
||||
|
||||
redis:
|
||||
image: redis:7.2.3
|
||||
container_name: redis
|
||||
restart: unless-stopped
|
||||
command: redis-server /etc/redis/redis.conf --requirepass 123456 --appendonly no # 启动 Redis 服务并添加密码为:123456,默认不开启 Redis AOF 方式持久化配置
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
volumes:
|
||||
- ./redis/data:/data
|
||||
- ./redis/config/redis.conf:/etc/redis/redis.conf
|
||||
ports:
|
||||
- 6379:6379
|
||||
networks:
|
||||
- youlai-boot
|
||||
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
container_name: minio
|
||||
restart: unless-stopped
|
||||
command: server /data --console-address ":9001"
|
||||
ports:
|
||||
- 9000:9000
|
||||
- 9001:9001
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- LANG=en_US.UTF-8
|
||||
- MINIO_ROOT_USER=minioadmin
|
||||
- MINIO_ROOT_PASSWORD=minioadmin
|
||||
volumes:
|
||||
- ./minio/data:/data
|
||||
- ./minio/config:/root/.minio
|
||||
networks:
|
||||
- youlai-boot
|
||||
|
||||
xxl-job-admin:
|
||||
image: xuxueli/xxl-job-admin:2.4.0
|
||||
container_name: xxl-job-admin
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
PARAMS: '--spring.datasource.url=jdbc:mysql://mysql:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=123456 --spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver'
|
||||
volumes:
|
||||
- ./xxljob/logs:/data/applogs
|
||||
ports:
|
||||
- 8080:8080
|
||||
networks:
|
||||
- youlai-boot
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
|
||||
[mysqld]
|
||||
# 字符集与排序规则
|
||||
character-set-server = utf8mb4 # 服务端默认字符集
|
||||
collation-server = utf8mb4_0900_ai_ci # 服务端默认排序规则
|
||||
|
||||
# 网络与路径
|
||||
datadir = /var/lib/mysql # 数据文件存放的目录
|
||||
bind-address = 0.0.0.0 # 允许远程连接,默认 127.0.0.1 只允许本地连接
|
||||
port = 3306 # 显式指定端口(默认3306可不写)
|
||||
|
||||
# 客户端字符集同步(避免乱码)
|
||||
init_connect = 'SET NAMES utf8mb4' # 连接初始化时设置字符集
|
||||
|
||||
[client]
|
||||
default-character-set = utf8mb4 # 客户端默认字符集
|
||||
|
||||
[mysql]
|
||||
default-character-set = utf8mb4 # MySQL 命令行工具字符集
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
|
||||
# Docker Compose 安装中间件 MySQL、Redis、Minio、Xxl-Job
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
docker-compose -f ./docker-compose.yml -p youlai-boot up -d
|
||||
```
|
||||
|
||||
- p youlai-boot 指定命名空间,避免与其他容器冲突,这里方便管理,统一管理和卸载
|
||||
|
||||
## 卸载
|
||||
```bash
|
||||
docker-compose -f ./docker-compose.yml -p youlai-boot down
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.rnb</groupId>
|
||||
<artifactId>rnb</artifactId>
|
||||
<version>1.13</version>
|
||||
<version>1.15</version>
|
||||
<description>基于 Java 17 + SpringBoot 3 + Spring Security 构建的后台管理系统。</description>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -5,8 +5,6 @@ import com.rnb.rnb.util.ParamDecoder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@@ -39,9 +37,6 @@ public class ApiController {
|
||||
Integer sid = Integer.parseInt(map.get("sid"));
|
||||
Integer ver = Integer.parseInt(map.get("ver"));
|
||||
|
||||
// System.out.println(String.format("[%s]", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))
|
||||
// + map.toString());
|
||||
|
||||
return apiService.getInfo(sid, ver);
|
||||
}
|
||||
case "userLogin": {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.rnb.rnb.controller;
|
||||
|
||||
import cn.hutool.poi.excel.cell.CellSetter;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.rnb.common.annotation.RepeatSubmit;
|
||||
import com.rnb.common.base.BasePageQuery;
|
||||
@@ -17,8 +16,6 @@ import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/rnb")
|
||||
@@ -144,13 +141,13 @@ public class ServiceController {
|
||||
public Result<?> saveExtend(@RequestBody @Valid Extend ext) {
|
||||
Account acc = accountService.getById(ext.getAccId());
|
||||
|
||||
String unBac = acc.getBacAccount();
|
||||
if(unBac.startsWith("164agyl")){
|
||||
return Result.failed("彩乐园账号不再延期");
|
||||
}
|
||||
else if(unBac.startsWith("ngjjb")){
|
||||
return Result.failed("竞技宝账号不再延期");
|
||||
}
|
||||
// String unBac = acc.getBacAccount();
|
||||
// if(unBac.startsWith("164agyl")){
|
||||
// return Result.failed("彩乐园账号不再延期");
|
||||
// }
|
||||
// else if(unBac.startsWith("ngjjb")){
|
||||
// return Result.failed("竞技宝账号不再延期");
|
||||
// }
|
||||
|
||||
int tmNow = (int) (System.currentTimeMillis()/1000);
|
||||
boolean bRemark = true,
|
||||
|
||||
@@ -16,8 +16,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -13,10 +13,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@@ -89,7 +87,7 @@ public class ApiService {
|
||||
account.setBacAccount(uname);
|
||||
account.setBacPlatform(web);
|
||||
account.setAddTime(now);
|
||||
account.setExpireTime(now + 10800);//("ABG".equals(web) ? 86400 : 10800));
|
||||
account.setExpireTime(now + 86400);//("ABG".equals(web) ? 86400 : 10800));
|
||||
account.setLogCount(1);
|
||||
account.setStatus(0);
|
||||
}
|
||||
@@ -117,11 +115,13 @@ public class ApiService {
|
||||
String apiKey = "";
|
||||
if(account.getStatus()==0) {
|
||||
exp = account.getExpireTime();
|
||||
apiKey = account.getApiKey();
|
||||
// 如果没有 apiKey,立即在 one-api 创建令牌
|
||||
if (apiKey == null || apiKey.isEmpty()) {
|
||||
syncOneApiToken(account);
|
||||
if(exp>now) {
|
||||
apiKey = account.getApiKey();
|
||||
// 如果没有 apiKey,立即在 one-api 创建令牌
|
||||
if (apiKey == null || apiKey.isEmpty()) {
|
||||
syncOneApiToken(account);
|
||||
apiKey = account.getApiKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rnb.rnb.util;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.rnb.common.constant.SystemConstants;
|
||||
@@ -34,47 +35,91 @@ public class OneApiClient {
|
||||
* @return one-api token key,失败时返回 null
|
||||
*/
|
||||
public String createToken(String name) {
|
||||
String baseUrl = getBaseUrl();
|
||||
String baseUrl = normalizeBaseUrl(getBaseUrl());
|
||||
String authToken = getAuthToken();
|
||||
if (baseUrl == null || baseUrl.isEmpty() || authToken == null || authToken.isEmpty()) {
|
||||
log.warn("OneApiClient.createToken: ONE_API_URL or ONE_API_TOKEN not configured, skip token creation for name={}", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
// one-api 注册的路由是 POST /api/token/(带尾斜杠),不带斜杠会被 gin 307 重定向且丢失 body
|
||||
String url = baseUrl + "/api/token/";
|
||||
HttpResponse resp = null;
|
||||
try {
|
||||
JSONObject body = new JSONObject();
|
||||
body.set("name", name);
|
||||
body.set("remain_quota", 1000000);
|
||||
body.set("expired_time", -1); // 永不过期
|
||||
|
||||
String respStr = HttpRequest.post(baseUrl + "/api/token")
|
||||
resp = HttpRequest.post(url)
|
||||
.header("Authorization", "Bearer " + authToken)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body.toString())
|
||||
.timeout(10000)
|
||||
.execute().body();
|
||||
.execute();
|
||||
|
||||
int status = resp.getStatus();
|
||||
String respStr = resp.body();
|
||||
if (status < 200 || status >= 300) {
|
||||
log.warn("OneApiClient.createToken: http error, status={}, url={}, body={}", status, url, truncate(respStr));
|
||||
return null;
|
||||
}
|
||||
if (respStr == null || respStr.isEmpty()) {
|
||||
log.warn("OneApiClient.createToken: empty response for name={}", name);
|
||||
log.warn("OneApiClient.createToken: empty response, status={}, url={}, name={}", status, url, name);
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject resp = JSONUtil.parseObj(respStr);
|
||||
if (!resp.getBool("success", false)) {
|
||||
log.warn("OneApiClient.createToken: success=false, name={}, message={}", name, resp.getStr("message"));
|
||||
JSONObject json = JSONUtil.parseObj(respStr);
|
||||
if (!json.getBool("success", false)) {
|
||||
log.warn("OneApiClient.createToken: success=false, name={}, message={}", name, json.getStr("message"));
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = resp.getJSONObject("data").getStr("key");
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
String key = data == null ? null : data.getStr("key");
|
||||
if (key == null || key.isEmpty()) {
|
||||
log.warn("OneApiClient.createToken: missing data.key, name={}, resp={}", name, respStr);
|
||||
log.warn("OneApiClient.createToken: missing data.key, name={}, resp={}", name, truncate(respStr));
|
||||
return null;
|
||||
}
|
||||
log.info("OneApiClient.createToken: token created, name={}, key={}", name, maskKey(key));
|
||||
return key;
|
||||
} catch (Exception e) {
|
||||
log.warn("OneApiClient.createToken: exception, name={}", name, e);
|
||||
log.warn("OneApiClient.createToken: exception, name={}, url={}", name, url, e);
|
||||
return null;
|
||||
} finally {
|
||||
if (resp != null) {
|
||||
resp.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化 one-api 基础地址:去掉尾部斜杠,剥离误配的 /api、/v1 后缀。
|
||||
*/
|
||||
private static String normalizeBaseUrl(String baseUrl) {
|
||||
if (baseUrl == null) {
|
||||
return null;
|
||||
}
|
||||
String url = baseUrl.trim();
|
||||
while (url.endsWith("/")) {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
if (url.endsWith("/api")) {
|
||||
url = url.substring(0, url.length() - 4);
|
||||
} else if (url.endsWith("/v1")) {
|
||||
url = url.substring(0, url.length() - 3);
|
||||
}
|
||||
while (url.endsWith("/")) {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private static String truncate(String s) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
return s.length() <= 200 ? s : s.substring(0, 200) + "...";
|
||||
}
|
||||
|
||||
private static String maskKey(String key) {
|
||||
|
||||
@@ -155,7 +155,8 @@ springdoc:
|
||||
path: /v3/api-docs
|
||||
group-configs:
|
||||
- group: '系统管理'
|
||||
paths-to-match: "/**"
|
||||
paths-to-match:
|
||||
- /**
|
||||
packages-to-scan:
|
||||
- com.rnb.system.controller
|
||||
- com.rnb.shared.auth.controller
|
||||
@@ -221,7 +222,12 @@ captcha:
|
||||
expire-seconds: 120
|
||||
|
||||
# 微信小程配置
|
||||
wx:
|
||||
miniapp:
|
||||
app-id: xxxxxx
|
||||
app-secret: xxxxxx
|
||||
#wx:
|
||||
# miniapp:
|
||||
# app-id: xxxxxx
|
||||
# app-secret: xxxxxx
|
||||
|
||||
# 日志级别
|
||||
logging:
|
||||
level:
|
||||
org.springframework.web.socket: WARN
|
||||
|
||||
@@ -218,7 +218,11 @@ captcha:
|
||||
expire-seconds: 120
|
||||
|
||||
# 微信小程配置
|
||||
wx:
|
||||
miniapp:
|
||||
app-id: xxxxxx
|
||||
app-secret: xxxxxx
|
||||
#wx:
|
||||
# miniapp:
|
||||
# app-id: xxxxxx
|
||||
# app-secret: xxxxxx
|
||||
# 日志级别
|
||||
logging:
|
||||
level:
|
||||
org.springframework.web.socket: WARN
|
||||
|
||||
Reference in New Issue
Block a user