From 3fcafc909aa305ff4e99be043266082f16560cda Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 12 Sep 2023 09:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=82=A3=E8=80=85=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orderInquiryResponse/orderInquiry.go | 3 ++- utils/mask.go | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/responses/orderInquiryResponse/orderInquiry.go b/api/responses/orderInquiryResponse/orderInquiry.go index 6503350..b4022d7 100644 --- a/api/responses/orderInquiryResponse/orderInquiry.go +++ b/api/responses/orderInquiryResponse/orderInquiry.go @@ -8,6 +8,7 @@ import ( "hospital-admin-api/api/responses/orderInquiryCouponResponse" "hospital-admin-api/api/responses/orderInquiryRefundResponse" "hospital-admin-api/api/responses/userDoctorResponse" + "hospital-admin-api/utils" ) // getOrderInquiryPage 获取医生列表-分页 @@ -134,7 +135,7 @@ func GetOrderInquiryPageResponse(orderInquiry []*model.OrderInquiry) []getOrderI PatientNameMask: v.PatientNameMask, PatientSex: v.PatientSex, PatientAge: v.PatientAge, - PatientMobile: v.User.Mobile, + PatientMobile: utils.MaskPhoneStr(v.User.Mobile), CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, } diff --git a/utils/mask.go b/utils/mask.go index a90743f..c3317f5 100644 --- a/utils/mask.go +++ b/utils/mask.go @@ -64,3 +64,26 @@ func MaskNameStr(str string, maskType int) string { return str } + +// MaskPhoneStr 手机号、固话加密 +// 固话:0510-89754815 0510-8****815 +// 手机号:18221234158 18*******58 +func MaskPhoneStr(phone string) string { + if phone == "" { + return phone + } + + // 使用正则表达式匹配固定电话 + phonePattern := `(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)` + isFixedLine := regexp.MustCompile(phonePattern).MatchString(phone) + + if isFixedLine { + // 匹配到固定电话 + // 替换匹配的部分为固定格式 + return regexp.MustCompile(`(0[0-9]{2,3}[\-]?[2-9])[0-9]{3,4}([0-9]{3}[\-]?[0-9]?)`).ReplaceAllString(phone, "$1****$2") + } else { + // 匹配到手机号 + // 替换匹配的部分为固定格式 + return regexp.MustCompile(`(1[0-9]{1})[0-9]{7}([0-9]{2})`).ReplaceAllString(phone, "$1*******$2") + } +}