ads_handler.go 18 KB

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