anxin-ruoyi/ruoyi-verification/README.md

107 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# RuoYi Verification Module
## 模块说明
本模块是独立的认证服务模块提供CA服务适配器和身份认证相关功能。
## 主要功能
### 1. CA服务适配器接口
- `CAServiceAdapter`: CA服务适配器接口定义标准化的CA服务接口规范
- 支持不同CA服务提供商的对接
### 2. 身份认证模型
- `IdentityVerificationRequest`: 身份认证请求对象
- `IdentityVerificationResponse`: 身份认证响应对象
### 3. Mock实现
- `MockCAServiceAdapter`: Mock CA服务适配器用于开发和测试环境
## 模块结构
```
ruoyi-verification
├── src/main/java/com/ruoyi/verification
│ └── ca
│ ├── CAServiceAdapter.java # CA服务适配器接口
│ ├── impl
│ │ └── MockCAServiceAdapter.java # Mock实现
│ └── model
│ ├── IdentityVerificationRequest.java # 请求对象
│ └── IdentityVerificationResponse.java # 响应对象
└── pom.xml
```
## 使用方式
### 1. 添加依赖
在需要使用CA服务的模块中添加依赖
```xml
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-verification</artifactId>
</dependency>
```
### 2. 注入CA服务适配器
```java
@Autowired
private CAServiceAdapter caServiceAdapter;
```
### 3. 调用身份认证
```java
IdentityVerificationRequest request = new IdentityVerificationRequest(
userId.toString(),
realName,
idCardNumber,
"IDENTITY"
);
IdentityVerificationResponse response = caServiceAdapter.verifyIdentity(request);
```
## Mock实现说明
Mock CA服务适配器的认证逻辑
- 身份证号以"1"开头:认证通过
- 身份证号以"2"开头:认证拒绝
- 其他情况:认证通过
## 扩展真实CA服务
要对接真实的CA服务只需
1. 创建新的实现类,实现 `CAServiceAdapter` 接口
2. 在实现类中调用真实的CA服务API
3. 通过配置切换使用Mock实现或真实实现
示例:
```java
@Component("realCAServiceAdapter")
public class RealCAServiceAdapter implements CAServiceAdapter {
@Override
public IdentityVerificationResponse verifyIdentity(IdentityVerificationRequest request) {
// 调用真实CA服务API
// ...
}
@Override
public boolean isServiceAvailable() {
// 检查真实CA服务可用性
// ...
}
}
```
## 依赖模块
- `ruoyi-common`: 通用工具模块
- `httpclient`: HTTP客户端用于调用外部CA服务