const.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package model
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "net"
  6. )
  7. const (
  8. TypeIOS = "ios"
  9. TypeAndriod = "android"
  10. GdtIOSAppID = "736536022"
  11. GdtAndroidAppID = "100951776"
  12. ChannelToutiao = "toutiao"
  13. ChannelShike = "2883"
  14. ChannelDontin = "415209141"
  15. )
  16. type GdtKey struct {
  17. Encrypt string
  18. Sign string
  19. }
  20. var (
  21. ChannelGdt = map[string]*GdtKey{
  22. "1439767": &GdtKey{Encrypt: "BAAAAAAAAAAAFfgX", Sign: "ee358e8dccbbc4ba"},
  23. "406965": &GdtKey{Encrypt: "BAAAAAAAAAAABjW1", Sign: "a45cbd2d4c5344b3"},
  24. "7799673": &GdtKey{Encrypt: "BAAAAAAAAAAAdwN5", Sign: "54b6deffcd64b6b0"},
  25. }
  26. AppIDGdt = map[string]string{
  27. TypeIOS: GdtIOSAppID,
  28. TypeAndriod: GdtAndroidAppID,
  29. }
  30. )
  31. func GdtIMEI(imei string) (gdtImei string) {
  32. if imei == "" {
  33. return
  34. }
  35. bs := md5.Sum([]byte(imei))
  36. gdtImei = hex.EncodeToString(bs[:])
  37. return
  38. }
  39. // InetAtoN conver ip addr to uint32.
  40. func InetAtoN(s string) (sum uint32) {
  41. ip := net.ParseIP(s)
  42. if ip == nil {
  43. return
  44. }
  45. ip = ip.To4()
  46. if ip == nil {
  47. return
  48. }
  49. sum += uint32(ip[0]) << 24
  50. sum += uint32(ip[1]) << 16
  51. sum += uint32(ip[2]) << 8
  52. sum += uint32(ip[3])
  53. return sum
  54. }
  55. // InetNtoA conver uint32 to ip addr.
  56. func InetNtoA(sum uint32) string {
  57. ip := make(net.IP, net.IPv4len)
  58. ip[0] = byte((sum >> 24) & 0xFF)
  59. ip[1] = byte((sum >> 16) & 0xFF)
  60. ip[2] = byte((sum >> 8) & 0xFF)
  61. ip[3] = byte(sum & 0xFF)
  62. return ip.String()
  63. }
  64. // IsIPv4 is ipv4
  65. func IsIPv4(addr string) bool {
  66. ipv := net.ParseIP(addr)
  67. if ip := ipv.To4(); ip != nil {
  68. return true
  69. } else {
  70. return false
  71. }
  72. }