push.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package http
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. pushmdl "go-common/app/service/main/push/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. xtime "go-common/library/time"
  11. )
  12. func testToken(c *bm.Context) {
  13. params := c.Request.Form
  14. appID, _ := strconv.ParseInt(params.Get("app_id"), 10, 64)
  15. if appID < 1 {
  16. c.JSON(nil, ecode.RequestErr)
  17. log.Error("app_id is wrong: %s", params.Get("app_id"))
  18. return
  19. }
  20. alertTitle := params.Get("alert_title")
  21. if alertTitle == "" {
  22. alertTitle = "哔哩哔哩消息"
  23. }
  24. alertBody := params.Get("alert_body")
  25. if alertBody == "" {
  26. c.JSON(nil, ecode.RequestErr)
  27. log.Error("alert_body is empty")
  28. return
  29. }
  30. token := params.Get("token")
  31. if token == "" {
  32. c.JSON(nil, ecode.RequestErr)
  33. log.Error("token is empty")
  34. return
  35. }
  36. linkType, _ := strconv.Atoi(params.Get("link_type"))
  37. if linkType < 1 {
  38. c.JSON(nil, ecode.RequestErr)
  39. log.Error("link_type is wrong: %s", params.Get("link_type"))
  40. return
  41. }
  42. linkValue := params.Get("link_value")
  43. expireTime, _ := strconv.ParseInt(params.Get("expire_time"), 10, 64)
  44. if expireTime == 0 {
  45. expireTime = time.Now().Add(7 * 24 * time.Hour).Unix()
  46. }
  47. sound, vibration := pushmdl.SwitchOn, pushmdl.SwitchOn
  48. if params.Get("sound") != "" {
  49. if sd, _ := strconv.Atoi(params.Get("sound")); sd == pushmdl.SwitchOff {
  50. sound = pushmdl.SwitchOff
  51. }
  52. }
  53. if params.Get("vibration") != "" {
  54. if vr, _ := strconv.Atoi(params.Get("vibration")); vr == pushmdl.SwitchOff {
  55. vibration = pushmdl.SwitchOff
  56. }
  57. }
  58. passThrough, _ := strconv.Atoi(params.Get("pass_through"))
  59. if passThrough != pushmdl.SwitchOn {
  60. passThrough = pushmdl.SwitchOff
  61. }
  62. img := params.Get("image_url")
  63. info := &pushmdl.PushInfo{
  64. TaskID: pushmdl.TempTaskID(),
  65. APPID: appID,
  66. Title: alertTitle,
  67. Summary: alertBody,
  68. LinkType: int8(linkType),
  69. LinkValue: linkValue,
  70. ExpireTime: xtime.Time(expireTime),
  71. PassThrough: passThrough,
  72. Sound: sound,
  73. Vibration: vibration,
  74. ImageURL: img,
  75. }
  76. c.JSON(nil, pushSrv.TestToken(context.Background(), info, token))
  77. }