修改--给获取实名认证token添加定时任务,每隔一天请求一次token

This commit is contained in:
haotian 2025-02-27 10:58:13 +08:00
parent 13b1293b5a
commit ec13f48fde
5 changed files with 33 additions and 7 deletions

View File

@ -41,6 +41,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- <version>5.1.38</version>-->
</dependency>
<!-- 核心模块-->

View File

@ -3,13 +3,20 @@ package com.ruoyi.web.controller.app.baidu;
import com.ruoyi.system.domain.BaiduToken;
import okhttp3.*;
import org.json.JSONObject;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.web.bind.annotation.RestController;
import java.io.*;
@RestController
class GetToken {
static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
static String access_token = "24.d6e37cf9b67921a112de974d2a4930c8.2592000.1743216019.282335-115883169";
@Scheduled(cron = "0 0 * */1 * *")
public static String getToken() throws IOException{
MediaType mediaType = MediaType.parse("application/json");
@ -23,14 +30,24 @@ class GetToken {
Response response = HTTP_CLIENT.newCall(request).execute();
BaiduToken baiduToken = GsonUtils.fromJson(response.body().string(), BaiduToken.class);
// System.out.println(response.body().string());
//// System.out.println(response.body().string());
access_token = baiduToken.getAccess_token();
System.out.println("获取token定时任务触发");
return baiduToken.getAccess_token();
// return baiduToken.getAccess_token();
return "";
}
public static void main(String []args) throws IOException{
String accessToken = getToken();
System.out.println(accessToken);
System.out.println(GetToken.access_token);
System.out.println(getToken());
System.out.println(GetToken.access_token);
System.out.println(getToken());
System.out.println(GetToken.access_token);
System.out.println(getToken());
System.out.println(GetToken.access_token);
// System.out.println(accessToken);
// MediaType mediaType = MediaType.parse("application/json");
// RequestBody body = RequestBody.create(mediaType, "");
// Request request = new Request.Builder()

View File

@ -46,8 +46,9 @@ public class OcrIdCardBAI {
String param = "id_card_side=" + id_card_side + "&detect_ps=" + detect_ps + "&detect_risk=" + detect_risk + "&detect_quality=" + detect_quality + "&detect_card=" + detect_card + "&image=" + imgParam;
// 注意这里仅为了简化编码每一次请求都去获取access_token线上环境access_token有过期时间 客户端可自行缓存过期后重新获取
// 使用之前要通过GetToken方法获取token token默认30天有效
String accessToken = "24.001b9417059a9d3c9643d26df82f6e4d.2592000.1742109506.282335-115883169";
// 使用之前要通过GetToken方法获取token token默认30天有效, 30天内token不变, 即使再次请求也不变
// String accessToken = "24.d6e37cf9b67921a112de974d2a4930c8.2592000.1743216019.282335-115883169";
String accessToken = GetToken.getToken();
String result = HttpUtil.post(url, accessToken, param);
// System.out.println(result);

View File

@ -3,13 +3,18 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
# driverClassName: com.mysql.jdbc.Driver
druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/wenlvapp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# url: jdbc:mysql://172.17.0.7:3306/wenlvapp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# url: jdbc:mysql://localhost:3306/xingming?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# url: jdbc:mysql://172.17.0.7:3306/wenlvapp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: root
# password: dnxxkj
# 从库数据源
slave:
# 从数据源开关/默认关闭

View File

@ -10,6 +10,7 @@ ruoyi:
demoEnabled: true
# 文件路径 示例( Windows配置D:/ruoyi/uploadPathLinux配置 /home/ruoyi/uploadPath
profile: D:/ruoyi/uploadPath
# profile: /home/uploadPath
# 获取ip地址开关
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证
@ -71,7 +72,8 @@ spring:
redis:
# 地址
host: localhost
# 端口默认为6379
# host: 172.17.0.3
# 端口默认为6379
port: 6379
# 数据库索引
database: 0