12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package main
- import (
- "encoding/json"
- "fmt"
- "github.com/gin-gonic/gin"
- "miads/adslib/encrypt"
- "miads/adslib/utils"
- "net/url"
- "strings"
- )
- type Request struct {
- Imei string
- Idfa string
- Model string
- Brand string
- ScreenSize string `json:"screen_size"`
- NetworkType int `json:"network_type"`
- Androidid string `json:"android_id"`
- Platform int `json:"platform"`
- OsVersion string `json:"os_version"`
- UaClient string `json:"ua"`
- ReqSource string `json:"req_source"`
- Mac string `json:"mac"`
- ReqSourceIp string `json:"ip"`
- NewAdsFlag int64
- content string
- }
- func (self *Request) Parse(c *gin.Context) {
- self.Imei = utils.GetArgument(c, "imei", "")
- self.Idfa = utils.GetArgument(c, "idfa", "")
- self.Model = utils.GetArgument(c, "model", "")
- self.Brand = utils.GetArgument(c, "brand", "")
- self.ScreenSize = utils.GetArgument(c, "screen_size", "")
- self.NetworkType = int(utils.GetIntArgument(c, "network_type", 3))
- self.Androidid = utils.GetArgument(c, "android_id", "")
- self.Platform = int(utils.GetIntArgument(c, "platform", 1))
- self.OsVersion = utils.GetArgument(c, "os_version", "")
- self.UaClient = utils.GetArgument(c, "ua", "")
- self.ReqSource = utils.GetArgument(c, "req_source", "")
- self.Mac = utils.GetArgument(c, "mac", "")
- self.ReqSourceIp = utils.GetArgument(c, "ip", "")
- self.NewAdsFlag = utils.GetIntArgument(c, "new_ads_flag", 0)
- self.content = utils.GetArgument(c, "ads_content", "")
- fmt.Printf("ads flag: %d, content: %s\n", self.NewAdsFlag, self.content)
- // 进行解密
- if self.NewAdsFlag == 1 && self.content != "" {
- contentDecode, err := encrypt.Decrypt(self.content, []byte(SECERET_KEY))
- if err != nil {
- fmt.Printf("error: %s", err)
- c.String(404, "decode failed")
- return
- }
- contentDecode = utils.Rstrip(contentDecode)
- err = json.Unmarshal([]byte(contentDecode), self)
- if err != nil {
- fmt.Println(err)
- c.String(404, "decode json body failed")
- return
- }
- fmt.Println(contentDecode)
- }
- self.UaClient, _ = url.QueryUnescape(self.UaClient)
- self.Mac = strings.ReplaceAll(self.Mac, ":", "")
- }
- func (self *Request) IsMiDevice() bool {
- if strings.Index(self.Brand, "mi") != -1 ||
- strings.Index(self.Brand, "MI") != -1 ||
- strings.Index(self.Brand, "Mi") != -1 {
- return true
- }
- return false
- }
|