query_windows.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //go:build windows
  2. package yu_phone
  3. import (
  4. _ "embed"
  5. yu_deflate "gogs.qqck.cn/s/tools/deflate"
  6. yu_fast "gogs.qqck.cn/s/tools/fast"
  7. yu_strconv "gogs.qqck.cn/s/tools/strconv"
  8. "strings"
  9. )
  10. var (
  11. //go:embed phone.dat
  12. data []byte
  13. phone2D [][]int
  14. addrArr []string
  15. ispArr []string
  16. )
  17. func init() {
  18. data = yu_deflate.DeflateDe(data)
  19. PrefSize := int(data[0]) | int(data[1])<<8 | int(data[2])<<16 | int(data[3])<<24
  20. descLength := int(data[8]) | int(data[9])<<8 | int(data[10])<<16 | int(data[11])<<24
  21. ispLength := int(data[12]) | int(data[13])<<8 | int(data[14])<<16 | int(data[15])<<24
  22. // PhoneSize := binary.LittleEndian.Uint32(data[4:8])
  23. // verNum := binary.LittleEndian.Uint32(data[16:20])
  24. headLength := 20
  25. startIndex := headLength + descLength + ispLength
  26. // Description array
  27. descString := yu_fast.B2S(data[headLength : headLength+descLength])
  28. addrArr = strings.Split(descString, "&")
  29. // ISP array
  30. ispString := yu_fast.B2S(data[headLength+descLength : headLength+descLength+ispLength])
  31. ispArr = strings.Split(ispString, "&")
  32. // Phone2D array
  33. phone2D = make([][]int, 200)
  34. for m := 0; m < PrefSize; m++ {
  35. i := m*7 + startIndex
  36. pref := int(data[i])
  37. index := int(data[i+1]) | int(data[i+2])<<8 | int(data[i+3])<<16 | int(data[i+4])<<24
  38. length := int(data[i+5]) | int(data[i+6])<<8
  39. phone2D[pref] = make([]int, 10000)
  40. for n := 0; n < length; n++ {
  41. p := startIndex + PrefSize*7 + (n+index)*4
  42. suff := int(data[p]) | int(data[p+1])<<8
  43. addrispIndex := int(data[p+2]) | int(data[p+3])<<8
  44. phone2D[pref][suff] = addrispIndex
  45. }
  46. }
  47. }
  48. type Info struct {
  49. // 区划:530400
  50. AreaCode string `json:"areacode"`
  51. // 城市:玉溪
  52. City string `json:"city"`
  53. // 区号:0877
  54. CityCode string `json:"citycode"`
  55. // 运营商:中国移动
  56. Isp string `json:"isp"`
  57. // 邮编:653100
  58. PostCode string `json:"postcode"`
  59. // 省份:云南
  60. Province string `json:"province"`
  61. }
  62. func (t *Info) IsVaild() bool {
  63. return t.Province != ""
  64. }
  65. // Query
  66. //
  67. // @Description: 查询手机号信息
  68. func Query(phone string) (info Info) {
  69. if len(phone) < 7 {
  70. return
  71. }
  72. prefix := phone[:3]
  73. suffix := phone[3:7]
  74. pref := yu_strconv.ParseInt(prefix)
  75. suff := yu_strconv.ParseInt(suffix)
  76. if pref >= len(phone2D) || suff >= len(phone2D[pref]) {
  77. return
  78. }
  79. addrispIndex := phone2D[pref][suff]
  80. if addrispIndex == 0 {
  81. return
  82. }
  83. j_info := strings.Split(addrArr[addrispIndex/100], "|")
  84. if len(j_info) != 5 {
  85. return
  86. }
  87. info.AreaCode, info.City, info.CityCode, info.PostCode, info.Province = j_info[4], j_info[1], j_info[3], j_info[2], j_info[0]
  88. info.Isp = ispArr[addrispIndex%100]
  89. return
  90. }