蛋蛋星球-客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

159 行
4.5 KiB

  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  10. "crypto/sha256"
  11. "encoding/hex"
  12. "encoding/json"
  13. "fmt"
  14. "github.com/gin-gonic/gin"
  15. "github.com/tidwall/gjson"
  16. "io/ioutil"
  17. "net/url"
  18. "strings"
  19. )
  20. func CallbackAlipayFace(c *gin.Context) {
  21. body, _ := ioutil.ReadAll(c.Request.Body)
  22. decodeArgs, err := url.QueryUnescape(string(body))
  23. if err != nil {
  24. _ = logx.Warn(err)
  25. return
  26. }
  27. data, err := url.ParseQuery(decodeArgs)
  28. if err != nil {
  29. return
  30. }
  31. dataMap := make(map[string]interface{})
  32. for k := range data {
  33. dataMap[k] = data.Get(k)
  34. }
  35. callbackStr := utils.Serialize(dataMap)
  36. fmt.Println("支付宝回调数据", string(callbackStr))
  37. }
  38. func CallbackChuanshanjia(c *gin.Context) {
  39. userId := c.Query("user_id")
  40. transId := c.Query("trans_id")
  41. primeRit := c.Query("prime_rit")
  42. sign := c.Query("sign")
  43. extra := c.Query("extra")
  44. id := gjson.Get(extra, "id").String()
  45. phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String())
  46. platform := "chuanshanjia"
  47. isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform)
  48. if isEnd == 1 {
  49. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  50. return
  51. }
  52. keyStr := spaceKey + ":" + transId
  53. // 1. 使用SHA256算法计算摘要
  54. hash := sha256.Sum256([]byte(keyStr))
  55. // 2. 将摘要转换为十六进制字符串
  56. signStr := hex.EncodeToString(hash[:])
  57. fmt.Println(signStr)
  58. if strings.Contains(signStr, sign) == false {
  59. c.String(200, "{\"is_verify\":true,\"reason\":50002}")
  60. return
  61. }
  62. isEnds := commDoing(c, platform, transId, userId, extra, primeRit)
  63. if isEnds == 1 {
  64. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  65. return
  66. }
  67. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  68. return
  69. }
  70. func CallbackYoulianghui(c *gin.Context) {
  71. userId := c.Query("userid")
  72. transId := c.Query("transid")
  73. primeRit := c.Query("pid")
  74. sign := c.Query("sig")
  75. extra := c.Query("extrainfo")
  76. id := gjson.Get(extra, "id").String()
  77. phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String())
  78. platform := "youlianghui"
  79. isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform)
  80. if isEnd == 1 {
  81. c.String(200, "success")
  82. return
  83. }
  84. keyStr := spaceKey + ":" + transId
  85. // 1. 使用SHA256算法计算摘要
  86. hash := sha256.Sum256([]byte(keyStr))
  87. // 2. 将摘要转换为十六进制字符串
  88. signStr := hex.EncodeToString(hash[:])
  89. fmt.Println(signStr)
  90. if strings.Contains(signStr, sign) == false {
  91. c.String(200, "success")
  92. return
  93. }
  94. isEnds := commDoing(c, platform, transId, userId, extra, primeRit)
  95. if isEnds == 1 {
  96. c.String(200, "success")
  97. return
  98. }
  99. c.String(200, "success")
  100. return
  101. }
  102. // 公共处理
  103. func commDoing(c *gin.Context, platform, transId, userId, extra, primeRit string) int {
  104. types := gjson.Get(extra, "type").String()
  105. exist, _ := db.Db.Where("platform=? and oid=?", platform, transId).Exist(&model.AdvertisingCallback{})
  106. if exist {
  107. c.String(200, "{\"is_verify\":true,\"reason\":20000}")
  108. return 1
  109. }
  110. var tmp = model.AdvertisingCallback{
  111. Platform: platform,
  112. Oid: transId,
  113. Uid: utils.StrToInt(userId),
  114. Extra: extra,
  115. SpaceId: primeRit,
  116. }
  117. db.Db.Insert(&tmp)
  118. // 写入mq处理
  119. ch, err := rabbit.Cfg.Pool.GetChannel()
  120. if err == nil {
  121. defer ch.Release()
  122. }
  123. if types == "incentive_eggSmash" { //首页砸蛋
  124. arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
  125. err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
  126. if err != nil {
  127. ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
  128. }
  129. }
  130. if types == "incentive_eggSign" { //首页签到
  131. arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
  132. err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
  133. if err != nil {
  134. ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
  135. }
  136. }
  137. return 0
  138. }
  139. func comm(c *gin.Context, id, primeRit, platform, phonePlatform string) (int, string) {
  140. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
  141. space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(id)
  142. if space == nil {
  143. return 1, ""
  144. }
  145. spaceData := gjson.Get(space.Info, platform+"."+phonePlatform+"_ad_id").String()
  146. spaceList := make([]map[string]string, 0)
  147. json.Unmarshal([]byte(spaceData), &spaceList)
  148. spaceKey := ""
  149. for _, v := range spaceList {
  150. if v["id"] == primeRit { //找到对应广告位的key
  151. spaceKey = v["key"]
  152. }
  153. }
  154. return 0, spaceKey
  155. }