mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-01 10:00:19 +08:00
Support mobile in DingTalk userinfo
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/mail"
|
||||
"regexp"
|
||||
|
||||
@ -48,3 +49,21 @@ func GetE164Number(phone string, countryCode string) (string, bool) {
|
||||
phoneNumber, _ := phonenumbers.Parse(phone, countryCode)
|
||||
return phonenumbers.Format(phoneNumber, phonenumbers.E164), phonenumbers.IsValidNumber(phoneNumber)
|
||||
}
|
||||
|
||||
func GetCountryCode(prefix string, phone string) (string, error) {
|
||||
if prefix == "" || phone == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
phoneNumber, err := phonenumbers.Parse(fmt.Sprintf("+%s%s", prefix, phone), "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
countryCode := phonenumbers.GetRegionCodeForNumber(phoneNumber)
|
||||
if countryCode == "" {
|
||||
return "", fmt.Errorf("country code not found for phone prefix: %s", prefix)
|
||||
}
|
||||
|
||||
return countryCode, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user