蛋蛋星球-客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

hdl_callback_advertising.go 5.0 KiB

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