request.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "miads/adslib/encrypt"
  7. "miads/adslib/utils"
  8. "net/url"
  9. "strings"
  10. )
  11. type Request struct {
  12. Imei string
  13. Idfa string
  14. Model string
  15. Brand string
  16. ScreenSize string `json:"screen_size"`
  17. NetworkType int `json:"network_type"`
  18. Androidid string `json:"android_id"`
  19. Platform int `json:"platform"`
  20. OsVersion string `json:"os_version"`
  21. UaClient string `json:"ua"`
  22. ReqSource string `json:"req_source"`
  23. Mac string `json:"mac"`
  24. ReqSourceIp string `json:"ip"`
  25. NewAdsFlag int64
  26. content string
  27. }
  28. func (self *Request) Parse(c *gin.Context) {
  29. self.Imei = utils.GetArgument(c, "imei", "")
  30. self.Idfa = utils.GetArgument(c, "idfa", "")
  31. self.Model = utils.GetArgument(c, "model", "")
  32. self.Brand = utils.GetArgument(c, "brand", "")
  33. self.ScreenSize = utils.GetArgument(c, "screen_size", "")
  34. self.NetworkType = int(utils.GetIntArgument(c, "network_type", 3))
  35. self.Androidid = utils.GetArgument(c, "android_id", "")
  36. self.Platform = int(utils.GetIntArgument(c, "platform", 1))
  37. self.OsVersion = utils.GetArgument(c, "os_version", "")
  38. self.UaClient = utils.GetArgument(c, "ua", "")
  39. self.ReqSource = utils.GetArgument(c, "req_source", "")
  40. self.Mac = utils.GetArgument(c, "mac", "")
  41. self.ReqSourceIp = utils.GetArgument(c, "ip", "")
  42. self.NewAdsFlag = utils.GetIntArgument(c, "new_ads_flag", 0)
  43. self.content = utils.GetArgument(c, "ads_content", "")
  44. fmt.Printf("ads flag: %d, content: %s\n", self.NewAdsFlag, self.content)
  45. // 进行解密
  46. if self.NewAdsFlag == 1 && self.content != "" {
  47. contentDecode, err := encrypt.Decrypt(self.content, []byte(SECERET_KEY))
  48. if err != nil {
  49. fmt.Printf("error: %s", err)
  50. c.String(404, "decode failed")
  51. return
  52. }
  53. contentDecode = utils.Rstrip(contentDecode)
  54. err = json.Unmarshal([]byte(contentDecode), self)
  55. if err != nil {
  56. fmt.Println(err)
  57. c.String(404, "decode json body failed")
  58. return
  59. }
  60. fmt.Println(contentDecode)
  61. }
  62. self.UaClient, _ = url.QueryUnescape(self.UaClient)
  63. self.Mac = strings.ReplaceAll(self.Mac, ":", "")
  64. }
  65. func (self *Request) IsMiDevice() bool {
  66. if strings.Index(self.Brand, "mi") != -1 ||
  67. strings.Index(self.Brand, "MI") != -1 ||
  68. strings.Index(self.Brand, "Mi") != -1 {
  69. return true
  70. }
  71. return false
  72. }