蛋蛋星球-客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

89 строки
2.7 KiB

  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  9. "crypto/sha256"
  10. "encoding/hex"
  11. "encoding/json"
  12. "fmt"
  13. "github.com/gin-gonic/gin"
  14. "github.com/tidwall/gjson"
  15. "strings"
  16. )
  17. func CallbackChuanshanjia(c *gin.Context) {
  18. userId := c.Query("user_id")
  19. transId := c.Query("trans_id")
  20. primeRit := c.Query("prime_rit")
  21. sign := c.Query("sign")
  22. extra := c.Query("extra")
  23. id := gjson.Get(extra, "id").String()
  24. types := gjson.Get(extra, "type").String()
  25. phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String())
  26. platform := "chuanshanjia"
  27. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
  28. space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(id)
  29. if space == nil {
  30. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  31. return
  32. }
  33. spaceData := gjson.Get(space.Info, platform+"."+phonePlatform+"_ad_id").String()
  34. spaceList := make([]map[string]string, 0)
  35. json.Unmarshal([]byte(spaceData), &spaceList)
  36. spaceKey := ""
  37. for _, v := range spaceList {
  38. if v["id"] == primeRit { //找到对应广告位的key
  39. spaceKey = v["key"]
  40. }
  41. }
  42. keyStr := spaceKey + ":" + transId
  43. // 1. 使用SHA256算法计算摘要
  44. hash := sha256.Sum256([]byte(keyStr))
  45. // 2. 将摘要转换为十六进制字符串
  46. signStr := hex.EncodeToString(hash[:])
  47. fmt.Println(signStr)
  48. if strings.Contains(signStr, sign) == false {
  49. c.String(200, "{\"is_verify\":true,\"reason\":50002}")
  50. return
  51. }
  52. exist, _ := db.Db.Where("platform=? and oid=?", platform, transId).Exist(&model.AdvertisingCallback{})
  53. if exist {
  54. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  55. return
  56. }
  57. var tmp = model.AdvertisingCallback{
  58. Platform: platform,
  59. Oid: transId,
  60. Uid: utils.StrToInt(userId),
  61. Extra: extra,
  62. SpaceId: primeRit,
  63. }
  64. db.Db.Insert(&tmp)
  65. // 写入mq处理
  66. ch, err := rabbit.Cfg.Pool.GetChannel()
  67. if err == nil {
  68. defer ch.Release()
  69. }
  70. if types == "incentive_eggSmash" { //首页砸蛋
  71. arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
  72. err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
  73. if err != nil {
  74. ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
  75. }
  76. }
  77. if types == "incentive_eggSign" { //首页签到
  78. arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
  79. err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
  80. if err != nil {
  81. ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
  82. }
  83. }
  84. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  85. return
  86. }