🚀 AI 近视防控系统 - 生产环境上线版本 v1.0
✅ 已完成功能: - 后端 Go 服务 (认证/授权/检测) - JWT 认证 + RBAC 权限控制 - 登录速率限制 (5 次失败锁定 15 分钟) - 密码强度校验 - 敏感数据脱敏 - Vue3 管理后台 - 路由守卫 - 删除二次确认 📦 部署配置: - Docker Compose 生产环境配置 - MySQL/Redis/MongoDB 数据库 - Nginx 前端服务 - 强密码安全配置 ⚠️ P2 待办 (下次迭代): - 学生/检测/预警等业务模块实现 - 错误处理统一化 - 缓存策略优化 - 日志分级 📍 生产环境: - 服务器:192.168.15.222 - 管理后台:http://192.168.15.222:8081 - API 服务:http://192.168.15.222:8080 2026-03-29 上线部署完成
This commit is contained in:
100
internal/utils/data_masker.go
Normal file
100
internal/utils/data_masker.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// MaskPhone 脱敏手机号
|
||||
func MaskPhone(phone string) string {
|
||||
if len(phone) != 11 {
|
||||
return phone // 如果不是标准手机号格式,直接返回
|
||||
}
|
||||
|
||||
// 保留前3位和后4位,中间4位用*代替
|
||||
return phone[:3] + "****" + phone[7:]
|
||||
}
|
||||
|
||||
// MaskIDCard 脱敏身份证号
|
||||
func MaskIDCard(idCard string) string {
|
||||
if len(idCard) != 18 {
|
||||
return idCard // 如果不是标准身份证格式,直接返回
|
||||
}
|
||||
|
||||
// 保留前6位和后4位,中间8位用*代替
|
||||
return idCard[:6] + "********" + idCard[14:]
|
||||
}
|
||||
|
||||
// MaskEmail 脱敏邮箱
|
||||
func MaskEmail(email string) string {
|
||||
emailParts := strings.Split(email, "@")
|
||||
if len(emailParts) != 2 {
|
||||
return email // 不是标准邮箱格式,直接返回
|
||||
}
|
||||
|
||||
localPart := emailParts[0]
|
||||
if len(localPart) <= 2 {
|
||||
return "*" + "@" + emailParts[1]
|
||||
}
|
||||
|
||||
// 保留前1位,其余用*代替,但不超过3个*
|
||||
maskLen := len(localPart) - 1
|
||||
if maskLen > 3 {
|
||||
maskLen = 3
|
||||
}
|
||||
|
||||
return localPart[0:1] + strings.Repeat("*", maskLen) + "@" + emailParts[1]
|
||||
}
|
||||
|
||||
// MaskName 脱敏姓名(保留姓氏)
|
||||
func MaskName(name string) string {
|
||||
if len(name) == 0 {
|
||||
return name
|
||||
}
|
||||
|
||||
// 对于中文姓名,保留第一个字符
|
||||
if len(name) == 2 {
|
||||
return name[:1] + "*"
|
||||
} else if len(name) > 2 {
|
||||
return name[:1] + "**"
|
||||
}
|
||||
|
||||
// 对于其他情况,直接返回
|
||||
return name
|
||||
}
|
||||
|
||||
// MaskBankCard 脱敏银行卡号
|
||||
func MaskBankCard(card string) string {
|
||||
// 移除空格
|
||||
card = strings.ReplaceAll(card, " ", "")
|
||||
|
||||
if len(card) < 8 {
|
||||
return card
|
||||
}
|
||||
|
||||
// 保留前4位和后4位
|
||||
prefix := card[:4]
|
||||
suffix := card[len(card)-4:]
|
||||
|
||||
return prefix + " **** **** " + suffix
|
||||
}
|
||||
|
||||
// MaskAddress 脱敏地址信息
|
||||
func MaskAddress(address string) string {
|
||||
if len(address) <= 6 {
|
||||
return "***"
|
||||
}
|
||||
|
||||
// 保留前6个字符
|
||||
return address[:6] + "***"
|
||||
}
|
||||
|
||||
// MaskID 脱敏ID(如果是身份证号格式则调用MaskIDCard)
|
||||
func MaskID(id string) string {
|
||||
// 检查是否为身份证号格式
|
||||
matched, _ := regexp.MatchString(`^\d{17}[\dXx]$`, id)
|
||||
if matched {
|
||||
return MaskIDCard(id)
|
||||
}
|
||||
return id
|
||||
}
|
||||
Reference in New Issue
Block a user