|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package hdl
-
- import (
- "applet/app/db"
- "applet/app/md"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
- "crypto/sha256"
- "encoding/hex"
- "encoding/json"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/tidwall/gjson"
- "strings"
- )
-
- func CallbackChuanshanjia(c *gin.Context) {
- userId := c.Query("user_id")
- transId := c.Query("trans_id")
- primeRit := c.Query("prime_rit")
- sign := c.Query("sign")
- extra := c.Query("extra")
- id := gjson.Get(extra, "id").String()
- types := gjson.Get(extra, "type").String()
- phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String())
- platform := "chuanshanjia"
- NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
- space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(id)
- if space == nil {
- c.String(200, "{\"is_verify\":true,\"reason\":20000}")
- return
- }
- spaceData := gjson.Get(space.Info, platform+"."+phonePlatform+"_ad_id").String()
- spaceList := make([]map[string]string, 0)
- json.Unmarshal([]byte(spaceData), &spaceList)
- spaceKey := ""
- for _, v := range spaceList {
- if v["id"] == primeRit { //找到对应广告位的key
- spaceKey = v["key"]
- }
- }
- keyStr := spaceKey + ":" + transId
- // 1. 使用SHA256算法计算摘要
- hash := sha256.Sum256([]byte(keyStr))
- // 2. 将摘要转换为十六进制字符串
- signStr := hex.EncodeToString(hash[:])
- fmt.Println(signStr)
- if strings.Contains(signStr, sign) == false {
- c.String(200, "{\"is_verify\":true,\"reason\":50002}")
- return
- }
- exist, _ := db.Db.Where("platform=? and oid=?", platform, transId).Exist(&model.AdvertisingCallback{})
- if exist {
- c.String(200, "{\"is_verify\":true,\"reason\":20000}")
- return
- }
- var tmp = model.AdvertisingCallback{
- Platform: platform,
- Oid: transId,
- Uid: utils.StrToInt(userId),
- Extra: extra,
- SpaceId: primeRit,
- }
- db.Db.Insert(&tmp)
- // 写入mq处理
- ch, err := rabbit.Cfg.Pool.GetChannel()
- if err == nil {
- defer ch.Release()
- }
- if types == "incentive_eggSmash" { //首页砸蛋
- arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
- err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
- if err != nil {
- ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSmash)
- }
- }
- if types == "incentive_eggSign" { //首页签到
- arg := md.AdvertisingWatch{Id: utils.IntToStr(tmp.Id)}
- err := ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
- if err != nil {
- ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign)
- }
- }
- c.String(200, "{\"is_verify\":true,\"reason\":20000}")
- return
- }
|