@@ -2,65 +2,65 @@ package data | |||||
// 星座信息 | // 星座信息 | ||||
var Constellation = [12]map[string]string{ | |||||
{ | |||||
"name": "水瓶座", | |||||
"start_date": "01-20", | |||||
"end_date": "02-18", | |||||
}, | |||||
{ | |||||
"name": "双鱼座", | |||||
"start_date": "02-19", | |||||
"end_date": "03-20", | |||||
}, | |||||
{ | |||||
"name": "白羊座", | |||||
"start_date": "03-21", | |||||
"end_date": "04-19", | |||||
}, | |||||
{ | |||||
"name": "金牛座", | |||||
"start_date": "04-20", | |||||
"end_date": "05-20", | |||||
}, | |||||
{ | |||||
"name": "双子座", | |||||
"start_date": "05-21", | |||||
"end_date": "06-21", | |||||
}, | |||||
{ | |||||
"name": "巨蟹座", | |||||
"start_date": "06-22", | |||||
"end_date": "07-22", | |||||
}, | |||||
{ | |||||
"name": "狮子座", | |||||
"start_date": "07-23", | |||||
"end_date": "08-22", | |||||
}, | |||||
{ | |||||
"name": "处女座", | |||||
"start_date": "08-23", | |||||
"end_date": "09-22", | |||||
}, | |||||
{ | |||||
"name": "天秤座", | |||||
"start_date": "09-23", | |||||
"end_date": "10-23", | |||||
}, | |||||
{ | |||||
"name": "天蝎座", | |||||
"start_date": "10-24", | |||||
"end_date": "11-22", | |||||
}, | |||||
{ | |||||
"name": "射手座", | |||||
"start_date": "11-23", | |||||
"end_date": "12-21", | |||||
}, | |||||
{ | |||||
"name": "摩羯座", | |||||
"start_date": "12-22", | |||||
"end_date": "01-19", | |||||
}, | |||||
var Constellation = [13]map[string]string{ | |||||
1: { | |||||
"name": "水瓶座", | |||||
"start_date": "01-20", | |||||
"end_date": "02-18", | |||||
}, | |||||
2: { | |||||
"name": "双鱼座", | |||||
"start_date": "02-19", | |||||
"end_date": "03-20", | |||||
}, | |||||
3: { | |||||
"name": "白羊座", | |||||
"start_date": "03-21", | |||||
"end_date": "04-19", | |||||
}, | |||||
4: { | |||||
"name": "金牛座", | |||||
"start_date": "04-20", | |||||
"end_date": "05-20", | |||||
}, | |||||
5: { | |||||
"name": "双子座", | |||||
"start_date": "05-21", | |||||
"end_date": "06-21", | |||||
}, | |||||
6: { | |||||
"name": "巨蟹座", | |||||
"start_date": "06-22", | |||||
"end_date": "07-22", | |||||
}, | |||||
7: { | |||||
"name": "狮子座", | |||||
"start_date": "07-23", | |||||
"end_date": "08-22", | |||||
}, | |||||
8: { | |||||
"name": "处女座", | |||||
"start_date": "08-23", | |||||
"end_date": "09-22", | |||||
}, | |||||
9: { | |||||
"name": "天秤座", | |||||
"start_date": "09-23", | |||||
"end_date": "10-23", | |||||
}, | |||||
10: { | |||||
"name": "天蝎座", | |||||
"start_date": "10-24", | |||||
"end_date": "11-22", | |||||
}, | |||||
11: { | |||||
"name": "射手座", | |||||
"start_date": "11-23", | |||||
"end_date": "12-21", | |||||
}, | |||||
12: { | |||||
"name": "摩羯座", | |||||
"start_date": "12-22", | |||||
"end_date": "01-19", | |||||
}, | |||||
} | } |
@@ -2,6 +2,7 @@ package id_validator | |||||
import ( | import ( | ||||
"strconv" | "strconv" | ||||
"strings" | |||||
"id-validator/data" | "id-validator/data" | ||||
) | ) | ||||
@@ -58,6 +59,36 @@ func GetAddress(addressCode string, birthdayCode string) string { | |||||
return address | return address | ||||
} | } | ||||
// 获取星座信息 | |||||
func GetConstellation(birthdayCode string) string { | |||||
monthStr := Substr(birthdayCode, 4, 6) | |||||
dayStr := Substr(birthdayCode, 6, 8) | |||||
month, _ := strconv.Atoi(monthStr) | |||||
day, _ := strconv.Atoi(dayStr) | |||||
startDate := data.Constellation[month]["start_date"] | |||||
startDay, _ := strconv.Atoi(strings.Split(startDate, "-")[1]) | |||||
if day >= startDay { | |||||
return data.Constellation[month]["name"] | |||||
} | |||||
tmpMonth := month - 1 | |||||
if month == 1 { | |||||
tmpMonth = 12 | |||||
} | |||||
return data.Constellation[tmpMonth]["name"] | |||||
} | |||||
// 获取生肖信息 | |||||
func GetChineseZodiac(birthdayCode string) string { | |||||
// 子鼠 | |||||
start := 1900 | |||||
end, _ := strconv.Atoi(Substr(birthdayCode, 0, 4)) | |||||
key := (end - start) % 12 | |||||
return data.ChineseZodiac[key] | |||||
} | |||||
// Substr 截取字符串 | // Substr 截取字符串 | ||||
func Substr(source string, start int, end int) string { | func Substr(source string, start int, end int) string { | ||||
var r = []rune(source) | var r = []rune(source) | ||||
@@ -1,5 +1,12 @@ | |||||
package id_validator | package id_validator | ||||
import ( | |||||
"fmt" | |||||
"strconv" | |||||
"id-validator/data" | |||||
) | |||||
// 验证身份证号合法性 | // 验证身份证号合法性 | ||||
func IsValid(id string) bool { | func IsValid(id string) bool { | ||||
if !CheckIdArgument(id) { | if !CheckIdArgument(id) { | ||||
@@ -21,3 +28,42 @@ func IsValid(id string) bool { | |||||
return code["checkBit"] == checkBit | return code["checkBit"] == checkBit | ||||
} | } | ||||
// 获取身份证信息 | |||||
func GetInfo(id string) map[string]string { | |||||
// 验证有效性 | |||||
if !IsValid(id) { | |||||
return map[string]string{} | |||||
} | |||||
code := GenerateType(id) | |||||
addressInfo := GetAddressInfo(code["addressCode"], code["birthdayCode"]) | |||||
fmt.Println(addressInfo) | |||||
address, _ := strconv.Atoi(code["addressCode"]) | |||||
abandoned := "0" | |||||
if data.AddressCode[address] == "" { | |||||
abandoned = "1" | |||||
} | |||||
// birthday, _ := time.Parse("20060102", code["birthdayCode"]) | |||||
sex := "1" | |||||
sexCode, _ := strconv.Atoi(code["order"]) | |||||
if (sexCode % 2) == 0 { | |||||
sex = "0" | |||||
} | |||||
info := map[string]string{ | |||||
"addressCode": code["addressCode"], | |||||
"abandoned": abandoned, | |||||
"address": addressInfo["province"] + addressInfo["city"] + addressInfo["district"], | |||||
// "addressTree": addressInfo, | |||||
// "birthdayCode": birthday, | |||||
"constellation": GetConstellation(code["birthdayCode"]), | |||||
"chineseZodiac": GetChineseZodiac(code["birthdayCode"]), | |||||
"sex": sex, | |||||
"length": code["type"], | |||||
"checkBit": code["checkBit"], | |||||
} | |||||
return info | |||||
} |