quanshi.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. quanshiReq "hongze/hongze_open_api/models/request/quanshi"
  6. "hongze/hongze_open_api/services/quanshi"
  7. "hongze/hongze_open_api/services/yb"
  8. "hongze/hongze_open_api/utils"
  9. "strconv"
  10. )
  11. // QuanShiControllerCommon 报告模块
  12. type QuanShiControllerCommon struct {
  13. BaseCommon
  14. }
  15. // CallBack
  16. // @Title 全时回调接口
  17. // @Description 全时回调接口
  18. // @router /callback [post]
  19. func (c *QuanShiControllerCommon) CallBack() {
  20. //回调中url参数要做签名(get请求中的参数,按照自己的方式签名,避免链接被别人拿去随意请求)
  21. utils.FileLog.Info(fmt.Sprintf("全时回调参数:%s", string(c.Ctx.Input.RequestBody)))
  22. //c.OkDetailed("ok", "获取成功")
  23. activityId, _ := c.GetInt("activity_id")
  24. timeInt, _ := c.GetInt("time")
  25. paramStr := fmt.Sprintf(`activity_id=%d&time=%d`, activityId, timeInt)
  26. signStr := quanshi.GetSign(paramStr)
  27. ownSign := c.GetString("sign")
  28. if ownSign != signStr {
  29. c.FailWithMessage("请求异常")
  30. return
  31. }
  32. var req1 quanshiReq.QsCallBackReq
  33. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req1)
  34. if err != nil {
  35. c.FailWithMessage("参数解析异常")
  36. return
  37. }
  38. switch req1.Method {
  39. case "report":
  40. //报告
  41. var req quanshiReq.QsCallBackReportReq
  42. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  43. if err != nil {
  44. c.FailWithMessage("参数解析异常")
  45. return
  46. }
  47. eventId, err := strconv.Atoi(req.Report.EventID)
  48. if err != nil {
  49. c.FailWithMessage("会议id异常:" + req.Report.EventID)
  50. return
  51. }
  52. err = yb.SyncUser(eventId)
  53. case "record":
  54. //录制
  55. var req quanshiReq.QsCallBackRecordReq
  56. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  57. if err != nil {
  58. c.FailWithMessage("参数解析异常")
  59. return
  60. }
  61. eventId, err := strconv.Atoi(req.Record.EventID)
  62. if err != nil {
  63. c.FailWithMessage("会议id异常:" + req.Record.EventID)
  64. return
  65. }
  66. err = yb.SyncVideo(eventId, req.Record.VideoURL)
  67. default:
  68. c.OkWithMessage("ok")
  69. return
  70. }
  71. if err != nil {
  72. c.FailWithMessage("同步数据失败")
  73. return
  74. }
  75. c.Ok()
  76. }