report.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package http
  2. import (
  3. "net/url"
  4. "strconv"
  5. pushmdl "go-common/app/service/main/push/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. const (
  11. timeZoneMin = -12
  12. timeZoneMax = 14
  13. )
  14. func report(c *bm.Context) {
  15. var (
  16. mid int64
  17. params = c.Request.Form
  18. )
  19. midItf, _ := c.Get("mid")
  20. if midItf != nil {
  21. mid = midItf.(int64)
  22. }
  23. platform := params.Get("mobi_app")
  24. if platform == "" {
  25. c.JSON(nil, ecode.RequestErr)
  26. log.Warn("mobi_app is empty")
  27. return
  28. }
  29. buvid := params.Get("buvid")
  30. if buvid == "" {
  31. c.JSON(nil, ecode.RequestErr)
  32. log.Warn("buvid is empty")
  33. return
  34. }
  35. dt := params.Get("device_token")
  36. build, _ := strconv.Atoi(params.Get("build"))
  37. if build < 1 {
  38. c.JSON(nil, ecode.RequestErr)
  39. log.Warn("build is wrong: %s", params.Get("build"))
  40. return
  41. }
  42. pushSDK, _ := strconv.Atoi(params.Get("push_sdk"))
  43. platformID := pushmdl.Platform(platform, pushSDK)
  44. if platformID == pushmdl.PlatformUnknown {
  45. c.JSON(nil, ecode.RequestErr)
  46. log.Warn("push_sdk is wrong: %s", params.Get("push_sdk"))
  47. return
  48. }
  49. tm, _ := strconv.Atoi(params.Get("time_zone"))
  50. if tm < timeZoneMin || tm > timeZoneMax {
  51. c.JSON(nil, ecode.RequestErr)
  52. log.Warn("time_zone is wrong: %s", params.Get("time_zone"))
  53. return
  54. }
  55. ns, _ := strconv.Atoi(params.Get("notify_switch"))
  56. if ns != 0 && ns != 1 {
  57. c.JSON(nil, ecode.RequestErr)
  58. log.Warn("notify_switch is wrong: %s", params.Get("notify_switch"))
  59. return
  60. }
  61. // tp, _ := strconv.Atoi(params.Get("type"))
  62. appID, _ := strconv.ParseInt(params.Get("app_id"), 10, 64)
  63. if appID == 0 {
  64. appID = pushmdl.APPIDBBPhone
  65. }
  66. deviceBrand, _ := url.QueryUnescape(params.Get("mobile_brand"))
  67. deviceModel, _ := url.QueryUnescape(params.Get("mobile_model"))
  68. osVersion, _ := url.QueryUnescape(params.Get("mobile_version"))
  69. r := &pushmdl.Report{
  70. APPID: appID,
  71. PlatformID: platformID,
  72. Mid: mid,
  73. Buvid: buvid,
  74. DeviceToken: dt,
  75. Build: build,
  76. TimeZone: tm,
  77. NotifySwitch: ns,
  78. DeviceBrand: deviceBrand,
  79. DeviceModel: deviceModel,
  80. OSVersion: osVersion,
  81. }
  82. if dt == "" {
  83. log.Warn("device_token is empty(%+v)", r)
  84. c.JSON(nil, nil) // iOS可能取不到device token
  85. return
  86. }
  87. c.JSON(nil, pushSrv.PubReport(c, r))
  88. }
  89. func reportOld(ctx *bm.Context) {
  90. var params = ctx.Request.Form
  91. buvid := params.Get("buvid")
  92. if buvid == "" {
  93. log.Warn("buvid is empty")
  94. ctx.JSON(nil, nil)
  95. return
  96. }
  97. token := params.Get("device_token")
  98. if token == "" {
  99. log.Warn("device_token is empty")
  100. ctx.JSON(nil, nil)
  101. return
  102. }
  103. ma := params.Get("mobi_app")
  104. if ma != "" && ma != "android" && ma != "iphone" && ma != "ipad" {
  105. log.Warn("invalid mobi_app(%s)", ma)
  106. ctx.JSON(nil, nil)
  107. return
  108. }
  109. mid, _ := strconv.ParseInt(params.Get("mid"), 10, 64)
  110. pid, _ := strconv.Atoi(params.Get("pid"))
  111. timezone, _ := strconv.Atoi(params.Get("time_zone"))
  112. version := params.Get("ver")
  113. ctx.JSON(nil, pushSrv.ReportOld(ctx, token, buvid, version, mid, pid, timezone))
  114. }