accountType

This commit is contained in:
李子铭 2024-11-11 17:04:05 +08:00
parent 9b0801fd34
commit 796650d161
2 changed files with 13 additions and 6 deletions

View File

@ -49,12 +49,10 @@ func (c *Config) orderReq(in *proto.OrderRequest) *api.OrderCreateReq {
accountType := int64(0)
if in.Order.Account == "" {
accountType = 0
} else {
if helper.IsPhoneNumber(in.Order.Account) {
accountType = 1
} else {
accountType = 2
}
} else if helper.IsPhoneNumber(in.Order.Account) {
accountType = 1
} else if helper.IsValidQQ(in.Order.Account) {
accountType = 2
}
return &api.OrderCreateReq{
OutTradeNo: in.Order.OrderNo, // 商户侧订单号长度只能是1-64位

View File

@ -19,12 +19,21 @@ func ToChinese(s string) string {
return encodedName
}
// IsPhoneNumber 检查给定的字符串是否为有效的手机号码
func IsPhoneNumber(phoneNumber string) bool {
phoneRegex := `^1[34578]\d{9}$`
return regexp.MustCompile(phoneRegex).MatchString(phoneNumber)
}
// IsEmail 检查给定的字符串是否为有效的电子邮箱地址
func IsEmail(email string) bool {
var emailRegex = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
return emailRegex.MatchString(email)
}
// IsValidQQ 检查给定的字符串是否为有效的 QQ 号
func IsValidQQ(qq string) bool {
// QQ号正则表达式5到11位数字且开头不为0的情况
re := regexp.MustCompile(`^(?!0)[0-9]{5,11}$`)
return re.MatchString(qq)
}