package hdl import ( "applet/app/cfg" "applet/app/db" "applet/app/md" "applet/app/utils" "applet/app/utils/logx" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "code.fnuoos.com/EggPlanet/egg_system_rules.git" "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" "io/ioutil" "net/url" "strings" "time" ) func CallbackAlipayFace(c *gin.Context) { body, _ := ioutil.ReadAll(c.Request.Body) decodeArgs, err := url.QueryUnescape(string(body)) if err != nil { _ = logx.Warn(err) return } data, err := url.ParseQuery(decodeArgs) if err != nil { return } dataMap := make(map[string]interface{}) for k := range data { dataMap[k] = data.Get(k) } callbackStr := utils.Serialize(dataMap) fmt.Println("支付宝回调数据", string(callbackStr)) } func CallbackChuanshanjia(c *gin.Context) { egg_system_rules.Init(cfg.RedisAddr) 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() uniqId := gjson.Get(extra, "uniqId").String() phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String()) platform := "chuanshanjia" isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform) if isEnd == 1 { fmt.Println("isEnd") c.String(200, "{\"is_verify\":true,\"reason\":20000}") return } keyStr := spaceKey + ":" + transId // 1. 使用SHA256算法计算摘要 hash := sha256.Sum256([]byte(keyStr)) // 2. 将摘要转换为十六进制字符串 signStr := hex.EncodeToString(hash[:]) fmt.Println("keyStr:" + keyStr) fmt.Println("signStr:" + signStr) if strings.Contains(signStr, sign) == false { fmt.Println("签名不一致") c.String(200, "{\"is_verify\":true,\"reason\":50002}") return } isEnds := commDoing(c, platform, transId, userId, extra, primeRit, uniqId) if isEnds == 1 { fmt.Println("处理结束") c.String(200, "{\"is_verify\":true,\"reason\":20000}") return } c.String(200, "{\"is_verify\":true,\"reason\":20000}") return } func CallbackYoulianghui(c *gin.Context) { egg_system_rules.Init(cfg.RedisAddr) userId := c.Query("userid") transId := c.Query("transid") primeRit := c.Query("pid") sign := c.Query("sig") extra := c.Query("extrainfo") id := gjson.Get(extra, "id").String() uniqId := gjson.Get(extra, "uniqId").String() phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String()) platform := "youlianghui" isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform) if isEnd == 1 { c.String(200, "success") return } 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, "success") return } isEnds := commDoing(c, platform, transId, userId, extra, primeRit, uniqId) if isEnds == 1 { c.String(200, "success") return } c.String(200, "success") return } // 公共处理 func commDoing(c *gin.Context, platform, transId, userId, extra, primeRit, uniqId string) int { types := gjson.Get(extra, "type").String() exist, _ := db.Db.Where("platform=? and oid=?", platform, transId).Exist(&model.AdvertisingCallback{}) if exist { c.String(200, "{\"is_verify\":true,\"reason\":20000}") return 1 } var tmp = model.AdvertisingCallback{ Platform: platform, Oid: transId, Uid: utils.StrToInt(userId), Extra: extra, SpaceId: primeRit, UniqId: uniqId, CreateAt: time.Now(), } 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) } } return 0 } func comm(c *gin.Context, id, primeRit, platform, phonePlatform string) (int, string) { NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db) space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(id) if space == nil { return 1, "" } spaceData := gjson.Get(space.Info, platform+"."+phonePlatform+"_ad_id").String() spaceList := make([]interface{}, 0) json.Unmarshal([]byte(spaceData), &spaceList) spaceKey := "" for _, v := range spaceList { v1, ok := v.(map[string]interface{}) if ok == false { continue } if v1["id"] == primeRit { //找到对应广告位的key spaceKey = utils.AnyToString(v1["key"]) } } return 0, spaceKey }