蛋蛋星球-客户端
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.
 
 
 
 
 

165 lines
4.7 KiB

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