ads_handler.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "math/rand"
  7. "miads/adslib"
  8. "miads/adslib/addata"
  9. "miads/adslib/ads_checker"
  10. "miads/adslib/city"
  11. "miads/adslib/device"
  12. "miads/adslib/encrypt"
  13. "miads/adslib/graylog"
  14. "miads/adslib/ip2region"
  15. "miads/adslib/redis_data"
  16. "miads/adslib/utils"
  17. "net/url"
  18. "strconv"
  19. "strings"
  20. "time"
  21. )
  22. type Response struct {
  23. Result int `json:"result"`
  24. Msg string `json:"msg"`
  25. AdsResult string `json:"ads_result"`
  26. addata.AdData
  27. }
  28. func adsHandler(c *gin.Context) {
  29. c.Header("Content-Type", "application/json")
  30. request := adslib.Request{}
  31. request.Parse(c)
  32. fmt.Printf("%+v\n", request)
  33. advertiser := "xiaomi"
  34. uaClient := request.UaClient
  35. // 获取ua
  36. if uaClient == "" {
  37. uaClient = c.GetHeader("User-Agent")
  38. if uaClient == "" {
  39. uaClient = "Dalvik/2.1.0 (Linux; U; Android 6.0.1; MI 4LTE MIUI/6.9.1)"
  40. }
  41. }
  42. // 获取ip
  43. checkReqSourceFlag, err := ads_checker.CheckReqSource(request.ReqSource)
  44. if err != nil {
  45. c.String(404, "check req source failed: %s", err)
  46. return
  47. }
  48. ip := ""
  49. if checkReqSourceFlag {
  50. ip = request.ReqSourceIp
  51. }
  52. if ip == "" {
  53. ip = c.GetHeader("X-Forwarded-For")
  54. }
  55. if ip == "" {
  56. ip = c.GetHeader("X-Real-IP")
  57. }
  58. if ip == "" {
  59. ip = c.Request.RemoteAddr
  60. }
  61. if strings.Index(ip, ",") != -1 {
  62. ip = strings.Split(ip, ",")[0]
  63. }
  64. ipInfo, err := ip2region.Ip2Region(ip)
  65. if err != nil {
  66. c.String(404, "ip 2 region failed: %s", err)
  67. return
  68. }
  69. fmt.Printf("ip 2 region: %s, %+v\n", ip, ipInfo)
  70. // 上報
  71. if request.NewAdsFlag == 1 {
  72. grayLogData := struct {
  73. Ip string
  74. Imei string
  75. Model string
  76. NetworkType int `json:"network_type"`
  77. Province string
  78. City string
  79. ScreeSize string `json:"screen_size"`
  80. Ua string
  81. Brand string
  82. Androidid string `json:"android_id"`
  83. ShortMessage string `json:"short_message"`
  84. ReqSource string `json:"req_source"`
  85. }{
  86. Ip: ip,
  87. Imei: request.Imei,
  88. Model: request.Model,
  89. NetworkType: request.NetworkType,
  90. Province: ipInfo.Province,
  91. City: ipInfo.City,
  92. ScreeSize: request.ScreenSize,
  93. Ua: request.UaClient,
  94. Brand: request.Brand,
  95. Androidid: request.Androidid,
  96. ShortMessage: "ads_api_log",
  97. ReqSource: "zhiku",
  98. }
  99. graylog.Log(grayLogData)
  100. }
  101. cityCode, err := city.GetCityCode(ipInfo.City)
  102. if err != nil {
  103. c.String(404, "get city code failed: %s", err)
  104. return
  105. }
  106. // 是否是安卓
  107. if request.Imei == "" {
  108. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_IOS", cityCode)
  109. graylog.LogApi("ios_device", request.Idfa, "", request.ReqSource)
  110. } else {
  111. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_ANDRIOID", cityCode)
  112. }
  113. freqControlInterval := 600
  114. // 深圳,东莞强行用600秒控制, 其他地区从配置读取
  115. if strings.Index(ipInfo.City, "深圳") == -1 && strings.Index(ipInfo.City, "东莞") == -1 {
  116. // 频率控制
  117. freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
  118. if err != nil {
  119. c.String(404, "get freq control conf failed")
  120. return
  121. }
  122. hour, _ := strconv.Atoi(time.Now().Format("01"))
  123. tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
  124. if ok {
  125. freqControlInterval = tmpControlInterval
  126. }
  127. }
  128. lastReqTime, err := device.GetIpReqTime(ip)
  129. if err != nil {
  130. c.String(404, "get last req time failed")
  131. return
  132. }
  133. needControl := false
  134. if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
  135. // 需要凭空
  136. needControl = true
  137. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
  138. } else {
  139. device.SetIpReqTime(ip, time.Now().Unix())
  140. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
  141. }
  142. //### 检查是否是ip黑名单
  143. isIpBlack, err := ads_checker.CheckBlackIp(ip)
  144. if err != nil {
  145. c.String(404, "get city code failed")
  146. return
  147. }
  148. if isIpBlack {
  149. graylog.LogApi("black_ip_list", ip, "", request.ReqSource)
  150. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IP", cityCode)
  151. }
  152. // 获取渠道的黑白性
  153. reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
  154. if err != nil {
  155. c.String(404, "get req channel flag failed")
  156. return
  157. }
  158. flowWeight := reqChannelFlag.Weigth
  159. flowRandomNum := rand.Intn(100)
  160. flowFlag := 0 // 有效的百分比
  161. if flowRandomNum <= flowWeight {
  162. flowFlag = 1
  163. }
  164. if reqChannelFlag.ChannelFlag == 1 {
  165. device.SetAdsTagLog(advertiser, request.ReqSource, fmt.Sprintf("DS_REQ_SOURCE_{%d}", reqChannelFlag.ChannelFlag), cityCode)
  166. }
  167. // 替换成小米的设备
  168. replaceFlag := 0
  169. imei := request.Imei
  170. sendPhoneType := 0
  171. userFlag := 0
  172. originImei := ""
  173. // 检查是否是小米的设备
  174. specialDeviceNum := 0
  175. if request.ReqSource == "wzb_h5" {
  176. specialDeviceNum = 6 // wzb_h5渠道只綁定一个imei, 具体愿意不知道
  177. }
  178. if request.ReqSource == "moyuntv" || (!request.IsMiDevice() &&
  179. (!isIpBlack && !needControl && reqChannelFlag.ChannelFlag == 1) && flowFlag == 1) {
  180. randomNum := 3
  181. deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
  182. if err != nil {
  183. c.String(404, "get req channel flag failed")
  184. return
  185. }
  186. if deviceConf != nil {
  187. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CACHE", cityCode) // 通过缓存请求
  188. imei = deviceConf.Imei
  189. uaClient = deviceConf.Ua
  190. originImei = deviceConf.OriginImei
  191. if imei != "" {
  192. replaceFlag = 1
  193. userFlag = 1
  194. }
  195. } else {
  196. // 先从对应的城市找,找不到在走原来的逻辑
  197. // 上报事件
  198. graylog.LogApi("city_search_city_code", strconv.Itoa(cityCode), ipInfo.City, request.ReqSource)
  199. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CODE_REQ", cityCode) // 可做城市替换
  200. if cityCode != 0 {
  201. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CODE", cityCode) // 替换成功
  202. fakeImei := ""
  203. fakeDeviceConf, leftCnt, err := device.GetDailyFakeDeviceConfByCityCode(cityCode)
  204. if err != nil {
  205. c.String(404, "get device conf failed")
  206. return
  207. }
  208. // 0 没有获取到, 1 获取到了
  209. gotCityFakeDeviceConfFlag := 0
  210. replaceUa := ""
  211. if fakeDeviceConf != nil {
  212. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_REPL", cityCode)
  213. device.SetMiDeviceConf(realRedisKey, *fakeDeviceConf)
  214. imei = fakeDeviceConf.Imei
  215. uaClient = fakeDeviceConf.Ua
  216. originImei = fakeDeviceConf.OriginImei
  217. fakeImei = fakeDeviceConf.Imei
  218. if fakeDeviceConf.Imei != "" {
  219. gotCityFakeDeviceConfFlag = 1
  220. userFlag = 2
  221. replaceFlag = 1
  222. }
  223. }
  224. grayLogData := struct {
  225. ReqSource string `json:"req_source"`
  226. OldImei string `json:"old_imei"`
  227. NewImei string `json:"new_imei"`
  228. IP string `json:"ip"`
  229. City string `json:"city"`
  230. CityCode int `json:"city_code"`
  231. Province string
  232. HitFlag int `json:"hit_flag"`
  233. LeftCnt int `json:"left_cnt"`
  234. ReplaceUa string `json:"replace_ua"`
  235. ShortMessage string `json:"short_message"`
  236. }{
  237. ReqSource: request.ReqSource,
  238. OldImei: request.Imei,
  239. NewImei: fakeImei,
  240. IP: ip,
  241. City: ipInfo.City,
  242. CityCode: cityCode,
  243. Province: ipInfo.Province,
  244. HitFlag: gotCityFakeDeviceConfFlag,
  245. LeftCnt: leftCnt,
  246. ReplaceUa: replaceUa,
  247. ShortMessage: "",
  248. }
  249. // 进行日志的上报
  250. graylog.Log(grayLogData)
  251. }
  252. }
  253. // 解码ua_client
  254. uaClient, _ = url.QueryUnescape(uaClient)
  255. } else if request.IsMiDevice() {
  256. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
  257. userFlag = 3
  258. sendPhoneType = 1
  259. }
  260. // 检查下,替换后的设备是否是黑名单, 再次检查, 防止放入cache后, 新增了黑名单
  261. isBlackImei, err := device.CheckIsBlackImei(imei, false)
  262. if err != nil {
  263. c.String(404, "get device conf failed")
  264. return
  265. }
  266. if isBlackImei {
  267. if replaceFlag == 1 {
  268. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
  269. } else {
  270. device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI", cityCode)
  271. }
  272. }
  273. // 组装公共的dsp_info
  274. dspInfo := utils.DspParam{}
  275. dspInfo.Init()
  276. dspInfo.DspCityCode = cityCode
  277. dspInfo.Imei = imei
  278. dspInfo.OriginImei = originImei
  279. dspInfo.OsVersion = request.OsVersion
  280. dspInfo.Mac = strings.ToUpper(request.Mac)
  281. dspInfo.OriginMac = request.Mac
  282. dspInfo.Idfa = request.Idfa
  283. dspInfo.Model = request.Model
  284. dspInfo.Brand = request.Brand
  285. dspInfo.ScreenSize = request.ScreenSize
  286. dspInfo.NetworkType = request.NetworkType
  287. dspInfo.Androidid = request.Androidid
  288. dspInfo.Platform = request.Platform
  289. dspInfo.Ip = ip
  290. dspInfo.Ua = uaClient
  291. dspInfo.City = ipInfo.City
  292. dspInfo.Province = ipInfo.Province
  293. dspInfo.UaOrigin = request.UaClient
  294. dspInfo.ReqSource = request.ReqSource
  295. if request.IsMiDevice() {
  296. dspInfo.RealMiFlag = 1
  297. }
  298. dspInfo.ReplaceFlag = replaceFlag
  299. dspInfo.RealReqSource = request.ReqSource
  300. dspInfo.SendPhoneType = sendPhoneType
  301. md5Imei := imei
  302. if dspInfo.ReplaceFlag == 0 {
  303. md5Imei = utils.Md5(imei)
  304. }
  305. dspInfo.RealMd5Imei = md5Imei
  306. //ads_item = None
  307. //xiaomi_response = []
  308. hour, _ := strconv.Atoi(time.Now().Format("01"))
  309. canRequest := true
  310. if 0 <= hour && hour <= 1 {
  311. randNum := rand.Intn(100)
  312. if randNum > 5 {
  313. canRequest = false
  314. }
  315. }
  316. var adData *addata.AdData
  317. // 非频率控制,设备黑名单,ip黑名单,白名单渠道,并且替换了小米设备的
  318. if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
  319. adData, err = addata.GetAdsInfos(&dspInfo, advertiser)
  320. }
  321. canMixFlag := 0
  322. xiaomiResponseFlag := 0
  323. response := Response{}
  324. if adData != nil && len(adData.TargetAddition) > 1 {
  325. xiaomiResponseFlag = 1
  326. realTarget := ""
  327. if adData.Target != "" {
  328. md5Skip := utils.Md5(adData.Target)
  329. conf := adslib.GetConf()
  330. realTarget = conf.Host + fmt.Sprintf("?action=LOADING&req_source=%s&advertiser=video&skip=%s&brand=%s&request_id=%s&skip_other=%s",
  331. dspInfo.ReqSource, "", dspInfo.Brand, dspInfo.RequestId, md5Skip)
  332. // 塞入Redis中
  333. redis_data.SetSkipInfo(md5Skip, adData.Target)
  334. }
  335. adData.Target = realTarget
  336. adData.JsOrderId, _ = redis_data.GetMinScriptOrderByAdv(advertiser)
  337. adData.UserAgent = uaClient
  338. if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
  339. adData.DpReport = fmt.Sprintf("%s?action=DP_CLICK&advertiser=video&req_source=%s", adslib.GetConf().HostIos, dspInfo.ReqSource)
  340. adData.Dp = adslib.GetConf().DpTest
  341. }
  342. if dspInfo.SendPhoneType == 0 {
  343. device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET", cityCode) // 广告获取成功
  344. } else if dspInfo.SendPhoneType == 1 {
  345. device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET_1", cityCode) // 广告获取成功
  346. }
  347. device.SetAdsTagLog(advertiser, dspInfo.ReqSource, fmt.Sprintf("ADS_USER_%d", userFlag), cityCode) // 广告类型,缓存,新用户,小米手机
  348. // 判断这个渠道是否要去融合和融合的流量占比
  349. mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
  350. if err != nil {
  351. c.String(404, "get device conf failed")
  352. return
  353. }
  354. flowRandomNum = rand.Intn(100)
  355. isOverFlow := false
  356. //flow_flag = 0
  357. if flowRandomNum > mixChannelFlag.Weigth {
  358. isOverFlow = true
  359. }
  360. if mixChannelFlag.ChannelFlag != 1 || isOverFlow {
  361. //extra_infos = []
  362. }
  363. // 组装返回去的action
  364. serverActionResponse := map[string]int{"server_view": 0, "server_click": 0, "server_close": 0, "server_video_finish": 0, "server_video_timer": 0}
  365. for _, targetInfo := range adData.TargetAddition {
  366. if targetInfo.Type == "VIEW" {
  367. serverActionResponse["server_view"] = 1
  368. redis_data.SetReqSourceView(advertiser, dspInfo.ReqSource, "xiafa")
  369. } else if targetInfo.Type == "CLICK" {
  370. serverActionResponse["server_click"] = 1
  371. } else if targetInfo.Type == "CLOSE" {
  372. serverActionResponse["server_close"] = 1
  373. } else if targetInfo.Type == "VIDEO_FINISH" {
  374. serverActionResponse["server_video_finish"] = 1
  375. } else if targetInfo.Type == "VIDEO_TIMER" {
  376. serverActionResponse["server_video_timer"] = 1
  377. }
  378. }
  379. // 增加跟随订单
  380. if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
  381. adData, err = addata.CombineOrderBy(adData, advertiser, &dspInfo)
  382. if err != nil {
  383. c.String(404, "combine order failed: %s", err.Error())
  384. return
  385. }
  386. }
  387. //# 检查最后是否有click
  388. //last_target_addition_infos = ads_item_new.get('target_addition',[])
  389. for _, targetAddition := range adData.TargetAddition {
  390. if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
  391. canMixFlag = 0
  392. break
  393. }
  394. }
  395. if request.NewAdsFlag == 0 {
  396. //response.update(ads_item_new)
  397. } else {
  398. jsonBytes, err := json.Marshal(*adData)
  399. if err != nil {
  400. c.String(404, "marshal AdData failed: %s", err.Error())
  401. return
  402. }
  403. encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
  404. response.AdsResult = encryptData
  405. }
  406. }
  407. if canMixFlag == 1 {
  408. response.Result = 2
  409. response.Msg = "no ads"
  410. if xiaomiResponseFlag == 1 {
  411. response.Result = 0
  412. response.Msg = "ok"
  413. }
  414. // 增加打底广告
  415. if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needControl && !isBlackImei {
  416. shortMessage := "kong"
  417. customAdData, err := addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 0, xiaomiResponseFlag)
  418. if err != nil {
  419. c.String(404, "get custom ads info failed: %s", err.Error())
  420. return
  421. }
  422. // 定投没有就跑其他的
  423. if customAdData == nil {
  424. customAdData, err = addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 1, xiaomiResponseFlag)
  425. if err != nil {
  426. c.String(404, "get fix custom ads info failed: %s", err.Error())
  427. return
  428. }
  429. }
  430. device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_GET", cityCode) // 广告获取成功
  431. if customAdData != nil {
  432. shortMessage = "ads_tt_thirds"
  433. }
  434. if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
  435. adDataBytes, err := json.Marshal(*adData)
  436. if err != nil {
  437. fmt.Sprintf("marshal addata failed: %s\n", err)
  438. }
  439. grayLogData := struct {
  440. Ip string
  441. ShortMessage string `json:"short_message"`
  442. ReqSource string `json:"req_source"`
  443. ResponseVast string `json:"response_vast"`
  444. OrderName string `json:"order_name"`
  445. Advertiser string `json:"advertiser"`
  446. }{
  447. Ip: ip,
  448. ShortMessage: "ads_api_log",
  449. ReqSource: "zhiku",
  450. ResponseVast: string(adDataBytes),
  451. OrderName: customAdData.OrderName,
  452. Advertiser: advertiser,
  453. }
  454. graylog.Log(grayLogData)
  455. }
  456. if shortMessage == "ads_tt_thirds" {
  457. // 组装最后的信息
  458. lastAdData := addata.AdData{}
  459. rspTargetAddition := make([]addata.AdAction, 0, 50)
  460. // 当小米有填充的时候
  461. if len(response.TargetAddition) != 0 && len(customAdData.TargetAddition) != 0 {
  462. rspTargetAddition = response.TargetAddition
  463. lastAdData.UserAgent = response.UserAgent
  464. }
  465. // 当只有view的时候
  466. if len(customAdData.TargetAddition) == 1 {
  467. for _, url := range customAdData.TargetAddition[0].Urls {
  468. rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
  469. }
  470. } else {
  471. // 当自由订单有view和click的时候
  472. for _, url := range customAdData.TargetAddition[0].Urls {
  473. rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
  474. }
  475. for _, url := range customAdData.TargetAddition[1].Urls {
  476. rspTargetAddition[1].Urls = append(rspTargetAddition[1].Urls, url)
  477. }
  478. rspTargetAddition[1].Type = "CLICK"
  479. }
  480. lastAdData.Target = customAdData.Target
  481. lastAdData.JsOrderId = customAdData.JsOrderId
  482. lastAdData.TargetAddition = rspTargetAddition
  483. lastAdData.DpReport = response.DpReport
  484. lastAdData.Dp = response.Dp
  485. adDataBytes, err := json.Marshal(lastAdData)
  486. if err != nil {
  487. fmt.Sprintf("marshal addata failed: %s\n", err)
  488. }
  489. grayLogData := struct {
  490. ShortMessage string `json:"short_message"`
  491. ResponseVast string `json:"response_vast"`
  492. }{
  493. ShortMessage: "third_mix_xiaomi",
  494. ResponseVast: string(adDataBytes),
  495. }
  496. graylog.Log(grayLogData)
  497. customAdData = &lastAdData
  498. }
  499. if customAdData != nil {
  500. device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_HAVE", cityCode) // 广告获取成功
  501. if dspInfo.ReqSource == "zhiku" {
  502. response.Result = 0
  503. response.Msg = "ok"
  504. jsonBytes, err := json.Marshal(customAdData)
  505. if err != nil {
  506. c.String(404, "marsha custom addata failed: %s", err.Error())
  507. return
  508. }
  509. encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
  510. response.AdsResult = encryptData
  511. graylog.ReportGrayLog(request, dspInfo, 0, 0)
  512. rspBytes, err := json.Marshal(response)
  513. if err != nil {
  514. c.String(404, "marshal Response failed: %s", err.Error())
  515. return
  516. }
  517. c.String(200, string(rspBytes))
  518. return
  519. } else {
  520. customAdData.Result = 0
  521. customAdData.Msg = "ok"
  522. graylog.ReportGrayLog(request, dspInfo, 0, 0)
  523. rspBytes, err := json.Marshal(customAdData)
  524. if err != nil {
  525. c.String(404, err.Error())
  526. return
  527. }
  528. c.String(200, string(rspBytes))
  529. return
  530. }
  531. }
  532. }
  533. }
  534. redis_data.SetAdsRealRequestNum(advertiser)
  535. rspBytes, err := json.Marshal(response)
  536. if err != nil {
  537. c.String(404, err.Error())
  538. return
  539. }
  540. if request.NewAdsFlag == 0 {
  541. graylog.ReportGrayLog(request, dspInfo, 0, 0)
  542. }
  543. device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
  544. c.String(200, string(rspBytes))
  545. }