Files
1818web-hoduan/docs/cloudauth-config-file-setup.md
2025-11-14 17:41:15 +08:00

190 lines
4.8 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.

# 阿里云身份认证配置文件设置指南
## 配置方式说明
根据用户需求,系统已配置为**直接从配置文件读取**阿里云身份认证信息,不使用环境变量。
## 配置文件结构
### application.yml 配置
```yaml
aliyun:
# --- 阿里云身份认证服务配置 ---
cloudauth:
region: cn-hangzhou # 区域配置
endpoint: cloudauth.aliyuncs.com # API端点
# 直接从配置文件读取认证信息
access-key-id: LTAI5t68do3qVXx5Rufugt3X # AccessKey ID
access-key-secret: 2vD9ToIff49Vph4JQXsn0Cy8nXQfzA # AccessKey Secret
connection-timeout: 10000 # 连接超时时间(ms)
response-timeout: 10000 # 响应超时时间(ms)
# 身份认证配置
biz-type: ID_2META # 业务类型:身份证二要素验证
param-type: normal # 参数类型normal表示不加密
```
## 代码配置读取
### Java 配置注入
```java
@Value("${aliyun.cloudauth.access-key-id}")
private String accessKeyId;
@Value("${aliyun.cloudauth.access-key-secret}")
private String accessKeySecret;
@Value("${aliyun.cloudauth.region}")
private String region;
@Value("${aliyun.cloudauth.endpoint}")
private String endpoint;
@Value("${aliyun.cloudauth.param-type}")
private String paramType;
```
### 特点说明
-**直接读取**: 无默认值,直接从配置文件读取
-**无环境变量依赖**: 完全不依赖环境变量
-**配置集中**: 所有配置在application.yml中统一管理
-**类型安全**: Spring会自动进行类型转换和验证
## 配置参数说明
| 参数 | 说明 | 示例值 | 必需 |
|------|------|--------|------|
| `region` | 阿里云区域 | cn-hangzhou | ✅ |
| `endpoint` | API端点 | cloudauth.aliyuncs.com | ✅ |
| `access-key-id` | 阿里云AccessKey ID | LTAI5t68... | ✅ |
| `access-key-secret` | 阿里云AccessKey Secret | 2vD9ToIf... | ✅ |
| `connection-timeout` | 连接超时时间(毫秒) | 10000 | ✅ |
| `response-timeout` | 响应超时时间(毫秒) | 10000 | ✅ |
| `biz-type` | 业务类型 | ID_2META | ✅ |
| `param-type` | 参数类型 | normal | ✅ |
## 配置验证
### 启动时验证
应用启动时会自动验证配置:
```
2024-09-01 10:30:00 INFO - 阿里云身份认证配置加载成功
2024-09-01 10:30:00 INFO - Region: cn-hangzhou
2024-09-01 10:30:00 INFO - Endpoint: cloudauth.aliyuncs.com
2024-09-01 10:30:00 INFO - ParamType: normal
```
### 运行时日志
API调用时会显示配置信息
```
调用阿里云Id2MetaStandardVerify API - 姓名: 张三, 身份证: 110101****, ParamType: normal
```
## 安全配置建议
### 1. 生产环境配置
```yaml
aliyun:
cloudauth:
region: cn-hangzhou
endpoint: cloudauth.aliyuncs.com
access-key-id: [生产环境AccessKey ID]
access-key-secret: [生产环境AccessKey Secret]
param-type: normal
```
### 2. 测试环境配置
```yaml
aliyun:
cloudauth:
region: cn-hangzhou
endpoint: cloudauth.aliyuncs.com
access-key-id: [测试环境AccessKey ID]
access-key-secret: [测试环境AccessKey Secret]
param-type: normal
```
### 3. 权限要求
确保AccessKey具有以下权限
- `AliyunCloudAuthFullAccess` (推荐)
- 或最小权限:`cloudauth:Id2MetaStandardVerify`
## 配置修改步骤
### 1. 更新AccessKey
```yaml
# 修改application.yml
aliyun:
cloudauth:
access-key-id: [新的AccessKey ID]
access-key-secret: [新的AccessKey Secret]
```
### 2. 重启应用
```bash
# 重启Spring Boot应用
mvn spring-boot:run
# 或
java -jar target/1818_user_server-1.0-SNAPSHOT.jar
```
### 3. 验证配置
查看启动日志确认配置加载成功
## 故障排除
### 配置缺失错误
```
Error: Could not resolve placeholder 'aliyun.cloudauth.access-key-id'
```
**解决方案**: 检查application.yml中是否正确配置了所有必需参数
### 权限错误
```
API响应Code: 440, Message: 无权限调用
```
**解决方案**:
1. 检查AccessKey权限
2. 确认实人认证服务已开通
3. 验证区域配置正确
### 网络连接错误
```
调用阿里云身份认证API失败: Connect timeout
```
**解决方案**:
1. 检查网络连接
2. 验证endpoint配置
3. 检查防火墙设置
## 配置文件示例
### 完整配置示例
```yaml
# application.yml
server:
port: 8081
spring:
application:
name: 1818-user-server
# 其他配置...
aliyun:
cloudauth:
region: cn-hangzhou
endpoint: cloudauth.aliyuncs.com
access-key-id: LTAI5t68do3qVXx5Rufugt3X
access-key-secret: 2vD9ToIff49Vph4JQXsn0Cy8nXQfzA
connection-timeout: 10000
response-timeout: 10000
biz-type: ID_2META
param-type: normal
```
---
*配置方式:直接配置文件读取*
*更新时间2024年9月1日*
*状态:✅ 已实施并验证*