蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

138 lines
4.0 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. phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String())
  25. platform := "chuanshanjia"
  26. isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform)
  27. if isEnd == 1 {
  28. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  29. return
  30. }
  31. keyStr := spaceKey + ":" + transId
  32. // 1. 使用SHA256算法计算摘要
  33. hash := sha256.Sum256([]byte(keyStr))
  34. // 2. 将摘要转换为十六进制字符串
  35. signStr := hex.EncodeToString(hash[:])
  36. fmt.Println(signStr)
  37. if strings.Contains(signStr, sign) == false {
  38. c.String(200, "{\"is_verify\":true,\"reason\":50002}")
  39. return
  40. }
  41. isEnds := commDoing(c, platform, transId, userId, extra, primeRit)
  42. if isEnds == 1 {
  43. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  44. return
  45. }
  46. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  47. return
  48. }
  49. func CallbackYoulianghui(c *gin.Context) {
  50. userId := c.Query("userid")
  51. transId := c.Query("transid")
  52. primeRit := c.Query("pid")
  53. sign := c.Query("sig")
  54. extra := c.Query("extrainfo")
  55. id := gjson.Get(extra, "id").String()
  56. phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String())
  57. platform := "youlianghui"
  58. isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform)
  59. if isEnd == 1 {
  60. c.String(200, "success")
  61. return
  62. }
  63. keyStr := spaceKey + ":" + transId
  64. // 1. 使用SHA256算法计算摘要
  65. hash := sha256.Sum256([]byte(keyStr))
  66. // 2. 将摘要转换为十六进制字符串
  67. signStr := hex.EncodeToString(hash[:])
  68. fmt.Println(signStr)
  69. if strings.Contains(signStr, sign) == false {
  70. c.String(200, "success")
  71. return
  72. }
  73. isEnds := commDoing(c, platform, transId, userId, extra, primeRit)
  74. if isEnds == 1 {
  75. c.String(200, "success")
  76. return
  77. }
  78. c.String(200, "success")
  79. return
  80. }
  81. // 公共处理
  82. func commDoing(c *gin.Context, platform, transId, userId, extra, primeRit string) int {
  83. types := gjson.Get(extra, "type").String()
  84. exist, _ := db.Db.Where("platform=? and oid=?", platform, transId).Exist(&model.AdvertisingCallback{})
  85. if exist {
  86. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  87. return 1
  88. }
  89. var tmp = model.AdvertisingCallback{
  90. Platform: platform,
  91. Oid: transId,
  92. Uid: utils.StrToInt(userId),
  93. Extra: extra,
  94. SpaceId: primeRit,
  95. }
  96. db.Db.Insert(&tmp)
  97. // 写入mq处理
  98. ch, err := rabbit.Cfg.Pool.GetChannel()
  99. if err == nil {
  100. defer ch.Release()
  101. }
  102. if types == "incentive_eggSmash" { //首页砸蛋
  103. arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
  104. err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
  105. if err != nil {
  106. ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
  107. }
  108. }
  109. if types == "incentive_eggSign" { //首页签到
  110. arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
  111. err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
  112. if err != nil {
  113. ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
  114. }
  115. }
  116. return 0
  117. }
  118. func comm(c *gin.Context, id, primeRit, platform, phonePlatform string) (int, string) {
  119. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
  120. space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(id)
  121. if space == nil {
  122. return 1, ""
  123. }
  124. spaceData := gjson.Get(space.Info, platform+"."+phonePlatform+"_ad_id").String()
  125. spaceList := make([]map[string]string, 0)
  126. json.Unmarshal([]byte(spaceData), &spaceList)
  127. spaceKey := ""
  128. for _, v := range spaceList {
  129. if v["id"] == primeRit { //找到对应广告位的key
  130. spaceKey = v["key"]
  131. }
  132. }
  133. return 0, spaceKey
  134. }