mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-06-28 13:34:18 +08:00
feat: 新增 sa-token-okhttps 插件,整合 OkHttps 作为请求处理器模块
This commit is contained in:
parent
760cac764b
commit
6ce8f38aaf
@ -139,6 +139,16 @@
|
|||||||
<artifactId>sa-token-redis-jackson</artifactId>
|
<artifactId>sa-token-redis-jackson</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-forest</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-okhttps</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
<artifactId>sa-token-redisson-spring-boot-starter</artifactId>
|
<artifactId>sa-token-redisson-spring-boot-starter</artifactId>
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020-2099 sa-token.cc
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package cn.dev33.satoken.http;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.SaManager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Http 请求处理器 工具类
|
||||||
|
*
|
||||||
|
* @author click33
|
||||||
|
* @since 1.43.0
|
||||||
|
*/
|
||||||
|
public class SaHttpUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get 请求
|
||||||
|
*
|
||||||
|
* @param url /
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static String get(String url) {
|
||||||
|
return SaManager.getSaHttpTemplate().get(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post 请求,form-data 格式参数
|
||||||
|
*
|
||||||
|
* @param url /
|
||||||
|
* @param params /
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static String postByFormData(String url, Map<String, Object> params) {
|
||||||
|
return SaManager.getSaHttpTemplate().postByFormData(url, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -41,6 +41,7 @@
|
|||||||
<hutool-cache.version>5.8.36</hutool-cache.version>
|
<hutool-cache.version>5.8.36</hutool-cache.version>
|
||||||
<caffeine.version>3.2.0</caffeine.version>
|
<caffeine.version>3.2.0</caffeine.version>
|
||||||
<forest.version>1.6.4</forest.version>
|
<forest.version>1.6.4</forest.version>
|
||||||
|
<okhttps.version>4.1.0</okhttps.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@ -282,6 +283,13 @@
|
|||||||
<version>${forest.version}</version>
|
<version>${forest.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Forest -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.zhxu</groupId>
|
||||||
|
<artifactId>okhttps</artifactId>
|
||||||
|
<version>${okhttps.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- sa-token 自身依赖 -->
|
<!-- sa-token 自身依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
|
@ -214,7 +214,8 @@ Maven依赖一直无法加载成功?[参考解决方案](https://sa-token.cc/d
|
|||||||
├── sa-token-grpc // [插件] Sa-Token 整合 gRPC (RPC 调用鉴权、状态传递)
|
├── sa-token-grpc // [插件] Sa-Token 整合 gRPC (RPC 调用鉴权、状态传递)
|
||||||
├── sa-token-quick-login // [插件] Sa-Token 快速注入登录页插件
|
├── sa-token-quick-login // [插件] Sa-Token 快速注入登录页插件
|
||||||
├── sa-token-redisson-spring-boot-starter // [插件] Sa-Token 整合 Redisson - SpringBoot 自动配置包 (数据缓存插件)
|
├── sa-token-redisson-spring-boot-starter // [插件] Sa-Token 整合 Redisson - SpringBoot 自动配置包 (数据缓存插件)
|
||||||
├── sa-token-forest // [插件] Sa-Token 整合 Forest,http 请求
|
├── sa-token-forest // [插件] Sa-Token 整合 Forest,http 请求处理器
|
||||||
|
├── sa-token-okhttps // [插件] Sa-Token 整合 OkHttps,http 请求处理器
|
||||||
├── sa-token-demo // [示例] Sa-Token 示例合集
|
├── sa-token-demo // [示例] Sa-Token 示例合集
|
||||||
├── sa-token-demo-alone-redis // [示例] Sa-Token 集成 alone-redis 模块
|
├── sa-token-demo-alone-redis // [示例] Sa-Token 集成 alone-redis 模块
|
||||||
├── sa-token-demo-alone-redis-cluster // [示例] Sa-Token 集成 alone-redis 模块、集群模式
|
├── sa-token-demo-alone-redis-cluster // [示例] Sa-Token 集成 alone-redis 模块、集群模式
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
<module>sa-token-redisx</module>
|
<module>sa-token-redisx</module>
|
||||||
<module>sa-token-serializer-features</module>
|
<module>sa-token-serializer-features</module>
|
||||||
<module>sa-token-forest</module>
|
<module>sa-token-forest</module>
|
||||||
|
<module>sa-token-okhttps</module>
|
||||||
|
|
||||||
<!-- SpringBoot 环境插件 -->
|
<!-- SpringBoot 环境插件 -->
|
||||||
<module>sa-token-redis-template</module>
|
<module>sa-token-redis-template</module>
|
||||||
|
25
sa-token-plugin/sa-token-okhttps/pom.xml
Normal file
25
sa-token-plugin/sa-token-okhttps/pom.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>sa-token-plugin</artifactId>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>sa-token-okhttps</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.zhxu</groupId>
|
||||||
|
<artifactId>okhttps</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020-2099 sa-token.cc
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package cn.dev33.satoken.http;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.SaManager;
|
||||||
|
import cn.zhxu.okhttps.OkHttps;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Http 请求处理器, OkHttps 版实现
|
||||||
|
*
|
||||||
|
* @author click33
|
||||||
|
* @since 1.43.0
|
||||||
|
*/
|
||||||
|
public class SaHttpTemplateForOkHttps implements SaHttpTemplate {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(String url) {
|
||||||
|
SaManager.log.debug("发起请求,GET:{}", url);
|
||||||
|
String res = OkHttps.sync(url).get().getBody().toString();
|
||||||
|
SaManager.log.debug("返回结果:{}", res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String postByFormData(String url, Map<String, Object> params) {
|
||||||
|
SaManager.log.debug("发起请求,POST:{}\t参数:{}", url, params);
|
||||||
|
String res = OkHttps.sync(url).addBodyPara(params).post().getBody().toString();
|
||||||
|
SaManager.log.debug("返回结果:{}", res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020-2099 sa-token.cc
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package cn.dev33.satoken.plugin;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.SaManager;
|
||||||
|
import cn.dev33.satoken.http.SaHttpTemplateForOkHttps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SaToken 插件安装:Http 请求处理器 - OkHttps 版
|
||||||
|
*
|
||||||
|
* @author click33
|
||||||
|
* @since 1.43.0
|
||||||
|
*/
|
||||||
|
public class SaTokenPluginForOkHttps implements SaTokenPlugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void install() {
|
||||||
|
// 设置 OkHttps 作为 Http 请求处理器
|
||||||
|
SaManager.setSaHttpTemplate(new SaHttpTemplateForOkHttps());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
cn.dev33.satoken.plugin.SaTokenPluginForOkHttps
|
Loading…
Reference in New Issue
Block a user