Przeglądaj źródła

隐藏电话号码

icole 4 lat temu
rodzic
commit
93562f1e24

+ 6 - 1
internal/logic/acquirer_student/acquirer_student_page_logic.go

@@ -77,7 +77,12 @@ func (l *AcquirerStudentPageLogic) AcquirerStudentPage(r *http.Request) (*types.
 					break
 				}
 			}
-
+			phone := r["stu_phone"].(string)
+			if len(phone) >= 11 {
+				r["stu_phone"] = utils.ReplaceSub(phone, "*", 3, 4)
+			} else if len(phone) > 5 {
+				r["stu_phone"] = utils.ReplaceSub(phone, "*", 2, 2)
+			}
 		}
 	}
 	return &types.Response{200, "", res}, nil

+ 13 - 0
internal/utils/strings.go

@@ -0,0 +1,13 @@
+package utils
+
+func ReplaceSub(s, sub string, start, count int) string {
+	var newStr string
+	for i, v := range s {
+		var p = string(v)
+		if i >= start && i < start+count {
+			p = sub
+		}
+		newStr += p
+	}
+	return newStr
+}