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

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