|
@@ -66,6 +66,11 @@ func adsHandler(c *gin.Context) {
|
66
|
66
|
request.Parse(c)
|
67
|
67
|
|
68
|
68
|
log.Printf("%+v", request)
|
|
69
|
+
|
|
70
|
+ // 放这里主要为了拿到reqeust id做日志记录
|
|
71
|
+ dspInfo := utils.DspParam{}
|
|
72
|
+ dspInfo.Init()
|
|
73
|
+
|
69
|
74
|
advertiser := "xiaomi"
|
70
|
75
|
uaClient := request.UaClient
|
71
|
76
|
// 获取ua
|
|
@@ -144,7 +149,7 @@ func adsHandler(c *gin.Context) {
|
144
|
149
|
|
145
|
150
|
// 定制city code
|
146
|
151
|
cityCode, err := city.GetCityCode(ipInfo.City)
|
147
|
|
- log.Infof("got city code: %d", cityCode)
|
|
152
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("got city code: %d", cityCode)
|
148
|
153
|
if err != nil {
|
149
|
154
|
c.String(404, "get city code failed: %s", err)
|
150
|
155
|
return
|
|
@@ -164,12 +169,12 @@ func adsHandler(c *gin.Context) {
|
164
|
169
|
// 频率控制
|
165
|
170
|
freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
|
166
|
171
|
if err != nil {
|
167
|
|
- log.Errorf("get freq control conf failed: %s", err)
|
|
172
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("get freq control conf failed: %s", err)
|
168
|
173
|
c.String(404, "get freq control conf failed: %s", err)
|
169
|
174
|
return
|
170
|
175
|
}
|
171
|
176
|
|
172
|
|
- log.Infof("freq control conf: %+v", freqControlConf)
|
|
177
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("freq control conf: %+v", freqControlConf)
|
173
|
178
|
hour, _ := strconv.Atoi(time.Now().Format("01"))
|
174
|
179
|
tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
|
175
|
180
|
if ok {
|
|
@@ -187,7 +192,7 @@ func adsHandler(c *gin.Context) {
|
187
|
192
|
needControl := false
|
188
|
193
|
if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
|
189
|
194
|
// 需要凭空
|
190
|
|
- log.Infof("need control: %d", lastReqTime)
|
|
195
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("need control: %d", lastReqTime)
|
191
|
196
|
needControl = true
|
192
|
197
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
|
193
|
198
|
} else {
|
|
@@ -197,7 +202,7 @@ func adsHandler(c *gin.Context) {
|
197
|
202
|
//### 检查是否是ip黑名单
|
198
|
203
|
isIpBlack, err := ads_checker.CheckBlackIp(ip)
|
199
|
204
|
if err != nil {
|
200
|
|
- log.Errorf("check black ip failed: %s", err)
|
|
205
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("check black ip failed: %s", err)
|
201
|
206
|
c.String(404, "check black ip failed: %s", err)
|
202
|
207
|
return
|
203
|
208
|
}
|
|
@@ -209,7 +214,7 @@ func adsHandler(c *gin.Context) {
|
209
|
214
|
// 获取渠道的黑白性
|
210
|
215
|
reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
|
211
|
216
|
if err != nil {
|
212
|
|
- log.Errorf("get req channel flag failed: %s", err)
|
|
217
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("get req channel flag failed: %s", err)
|
213
|
218
|
c.String(404, "get req channel flag failed: %s", err)
|
214
|
219
|
return
|
215
|
220
|
}
|
|
@@ -241,12 +246,12 @@ func adsHandler(c *gin.Context) {
|
241
|
246
|
randomNum := 3
|
242
|
247
|
deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
|
243
|
248
|
if err != nil {
|
244
|
|
- log.Errorf("get mi device conf failed: %s", err)
|
|
249
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("get mi device conf failed: %s", err)
|
245
|
250
|
c.String(404, "get mi device conf failed: %s", err)
|
246
|
251
|
return
|
247
|
252
|
}
|
248
|
253
|
if deviceConf != nil {
|
249
|
|
- log.Infof("use cache imei: %+v", deviceConf)
|
|
254
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("use cache imei: %+v", deviceConf)
|
250
|
255
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CACHE", cityCode) // 通过缓存请求
|
251
|
256
|
imei = deviceConf.Imei
|
252
|
257
|
uaClient = deviceConf.Ua
|
|
@@ -266,7 +271,7 @@ func adsHandler(c *gin.Context) {
|
266
|
271
|
fakeImei := ""
|
267
|
272
|
fakeDeviceConf, leftCnt, err := device.GetDailyFakeDeviceConfByCityCode(cityCode)
|
268
|
273
|
if err != nil {
|
269
|
|
- log.Errorf("get device conf failed: %s", err)
|
|
274
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("get device conf failed: %s", err)
|
270
|
275
|
c.String(404, "get device conf failed: %s", err)
|
271
|
276
|
return
|
272
|
277
|
}
|
|
@@ -278,7 +283,7 @@ func adsHandler(c *gin.Context) {
|
278
|
283
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_REPL", cityCode)
|
279
|
284
|
err := device.SetMiDeviceConf(realRedisKey, *fakeDeviceConf)
|
280
|
285
|
if err != nil {
|
281
|
|
- log.Errorf("set mi device conf failed: %s", err)
|
|
286
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("set mi device conf failed: %s", err)
|
282
|
287
|
}
|
283
|
288
|
imei = fakeDeviceConf.Imei
|
284
|
289
|
uaClient = fakeDeviceConf.Ua
|
|
@@ -325,34 +330,37 @@ func adsHandler(c *gin.Context) {
|
325
|
330
|
// 解码ua_client
|
326
|
331
|
uaClient, _ = url.QueryUnescape(uaClient)
|
327
|
332
|
} else if request.IsMiDevice() {
|
328
|
|
- log.Info("real mi")
|
|
333
|
+ log.WithField("request_id", dspInfo.RequestId).Info("real mi")
|
329
|
334
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
|
330
|
335
|
userFlag = 3
|
331
|
336
|
sendPhoneType = 1
|
332
|
337
|
}
|
333
|
338
|
|
334
|
339
|
// 检查下,替换后的设备是否是黑名单, 再次检查, 防止放入cache后, 新增了黑名单
|
335
|
|
- isBlackImei, err := device.CheckIsBlackImei(imei, false)
|
|
340
|
+ checkImei := imei
|
|
341
|
+ // 替换过的imei从redis取的, 都是md5后的, 不需要再md5
|
|
342
|
+ if replaceFlag != 1 {
|
|
343
|
+ checkImei = utils.Md5(imei)
|
|
344
|
+ }
|
|
345
|
+ isBlackImei, err := device.CheckIsBlackImei(checkImei)
|
336
|
346
|
if err != nil {
|
337
|
|
- log.Errorf("get device conf failed: %s", err)
|
|
347
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("get device conf failed: %s", err)
|
338
|
348
|
c.String(404, "get device conf failed: %s", err)
|
339
|
349
|
return
|
340
|
350
|
}
|
341
|
351
|
|
342
|
|
- log.Tracef("replace flag: %d", replaceFlag)
|
|
352
|
+ log.WithField("request_id", dspInfo.RequestId).Tracef("replace flag: %d", replaceFlag)
|
343
|
353
|
if isBlackImei {
|
344
|
354
|
if replaceFlag == 1 {
|
345
|
|
- log.Trace("replace")
|
|
355
|
+ log.WithField("request_id", dspInfo.RequestId).Trace("replace")
|
346
|
356
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
|
347
|
357
|
} else {
|
348
|
|
- log.Trace("not replace")
|
|
358
|
+ log.WithField("request_id", dspInfo.RequestId).Trace("not replace")
|
349
|
359
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI", cityCode)
|
350
|
360
|
}
|
351
|
361
|
}
|
352
|
362
|
|
353
|
363
|
// 组装公共的dsp_info
|
354
|
|
- dspInfo := utils.DspParam{}
|
355
|
|
- dspInfo.Init()
|
356
|
364
|
dspInfo.DspCityCode = cityCode
|
357
|
365
|
dspInfo.Imei = imei
|
358
|
366
|
dspInfo.OriginImei = originImei
|
|
@@ -379,12 +387,12 @@ func adsHandler(c *gin.Context) {
|
379
|
387
|
dspInfo.RealReqSource = request.ReqSource
|
380
|
388
|
dspInfo.SendPhoneType = sendPhoneType
|
381
|
389
|
md5Imei := imei
|
382
|
|
- if dspInfo.ReplaceFlag == 0 {
|
383
|
|
- md5Imei = utils.Md5(imei)
|
|
390
|
+ if dspInfo.OriginImei != "" {
|
|
391
|
+ md5Imei = utils.Md5(dspInfo.OriginImei)
|
384
|
392
|
}
|
385
|
393
|
|
386
|
394
|
dspInfo.RealMd5Imei = md5Imei
|
387
|
|
- log.Infof("dsp: %+v", dspInfo)
|
|
395
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("dsp: %+v", dspInfo)
|
388
|
396
|
//ads_item = None
|
389
|
397
|
//xiaomi_response = []
|
390
|
398
|
hour, _ := strconv.Atoi(time.Now().Format("01"))
|
|
@@ -397,7 +405,7 @@ func adsHandler(c *gin.Context) {
|
397
|
405
|
}
|
398
|
406
|
}
|
399
|
407
|
|
400
|
|
- log.Infof("can request: %t", canRequest)
|
|
408
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("can request: %t", canRequest)
|
401
|
409
|
|
402
|
410
|
var adData *addata.AdData
|
403
|
411
|
|
|
@@ -405,11 +413,11 @@ func adsHandler(c *gin.Context) {
|
405
|
413
|
if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
|
406
|
414
|
adData, err = addata.GetAdsInfos(&dspInfo, advertiser)
|
407
|
415
|
if err != nil {
|
408
|
|
- log.Errorf("get mi ad data failed: %s", err)
|
|
416
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("get mi ad data failed: %s", err)
|
409
|
417
|
c.String(404, "get mi ad data failed: %s", err)
|
410
|
418
|
return
|
411
|
419
|
}
|
412
|
|
- log.Infof("get mi ads data: %+v", adData)
|
|
420
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("get mi ads data: %+v", adData)
|
413
|
421
|
}
|
414
|
422
|
|
415
|
423
|
canMixFlag := 1
|
|
@@ -417,7 +425,7 @@ func adsHandler(c *gin.Context) {
|
417
|
425
|
response := Response{}
|
418
|
426
|
response.Msg = "ok"
|
419
|
427
|
if adData != nil && len(adData.TargetAddition) > 1 {
|
420
|
|
- log.Infof("add target js order")
|
|
428
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("add target js order")
|
421
|
429
|
xiaomiResponseFlag = 1
|
422
|
430
|
realTarget := ""
|
423
|
431
|
if adData.Target != "" {
|
|
@@ -432,11 +440,11 @@ func adsHandler(c *gin.Context) {
|
432
|
440
|
adData.Target = realTarget
|
433
|
441
|
adData.JsOrderId, err = redis_data.GetMinScriptOrderByAdv(advertiser)
|
434
|
442
|
if err != nil {
|
435
|
|
- log.Errorf("get min script order by adv failed: %s", err)
|
|
443
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("get min script order by adv failed: %s", err)
|
436
|
444
|
c.String(404, "get min script order by adv failed: %s", err)
|
437
|
445
|
return
|
438
|
446
|
}
|
439
|
|
- log.Infof("got min script order: %d", adData.JsOrderId)
|
|
447
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("got min script order: %d", adData.JsOrderId)
|
440
|
448
|
adData.UserAgent = uaClient
|
441
|
449
|
|
442
|
450
|
if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
|
|
@@ -452,11 +460,11 @@ func adsHandler(c *gin.Context) {
|
452
|
460
|
// // 判断这个渠道是否要去融合和融合的流量占比
|
453
|
461
|
// mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
|
454
|
462
|
// if err != nil {
|
455
|
|
- // log.Errorf("get device conf failed: %s", err)
|
|
463
|
+ // log.WithField("request_id", dspInfo.RequestId).Errorf("get device conf failed: %s", err)
|
456
|
464
|
// c.String(404, "get device conf failed: %s", err)
|
457
|
465
|
// return
|
458
|
466
|
// }
|
459
|
|
- flowRandomNum = rand.Intn(100)
|
|
467
|
+ // flowRandomNum = rand.Intn(100)
|
460
|
468
|
//isOverFlow := false
|
461
|
469
|
//if flowRandomNum > mixChannelFlag.Weigth {
|
462
|
470
|
// isOverFlow = true
|
|
@@ -481,25 +489,25 @@ func adsHandler(c *gin.Context) {
|
481
|
489
|
serverActionResponse["server_video_timer"] = 1
|
482
|
490
|
}
|
483
|
491
|
}
|
484
|
|
- log.Infof("server action response: %+v", serverActionResponse)
|
|
492
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("server action response: %+v", serverActionResponse)
|
485
|
493
|
// 增加跟随订单
|
486
|
494
|
if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
|
487
|
|
- log.Infof("add more order")
|
|
495
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("add more order")
|
488
|
496
|
adData, err = addata.CombineOrderBy(adData, &dspInfo)
|
489
|
497
|
if err != nil {
|
490
|
|
- log.Errorf("combine order failed: %s", err)
|
|
498
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("combine order failed: %s", err)
|
491
|
499
|
c.String(404, "combine order failed: %s", err.Error())
|
492
|
500
|
return
|
493
|
501
|
}
|
494
|
|
- log.Infof("get custom order: %+v", adData)
|
|
502
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("get custom order: %+v", adData)
|
495
|
503
|
}
|
496
|
504
|
|
497
|
505
|
//# 检查最后是否有click
|
498
|
|
- log.Infof("check ads item new: %+v", adData)
|
|
506
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("check ads item new: %+v", adData)
|
499
|
507
|
|
500
|
508
|
for _, targetAddition := range adData.TargetAddition {
|
501
|
509
|
if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
|
502
|
|
- log.Infof("can't mix, targetAddition: %+v", targetAddition)
|
|
510
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("can't mix, targetAddition: %+v", targetAddition)
|
503
|
511
|
canMixFlag = 0
|
504
|
512
|
break
|
505
|
513
|
}
|
|
@@ -507,7 +515,7 @@ func adsHandler(c *gin.Context) {
|
507
|
515
|
|
508
|
516
|
if request.NewAdsFlag == 0 {
|
509
|
517
|
response.AdData = *adData
|
510
|
|
- log.Infof("update response: +%v", response)
|
|
518
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("update response: +%v", response)
|
511
|
519
|
} else {
|
512
|
520
|
jsonBytes, err := json.Marshal(*adData)
|
513
|
521
|
if err != nil {
|
|
@@ -519,7 +527,7 @@ func adsHandler(c *gin.Context) {
|
519
|
527
|
}
|
520
|
528
|
}
|
521
|
529
|
|
522
|
|
- log.Infof("can mix: %d, xiaomi rsp flag: %d", canMixFlag, xiaomiResponseFlag)
|
|
530
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("can mix: %d, xiaomi rsp flag: %d", canMixFlag, xiaomiResponseFlag)
|
523
|
531
|
if canMixFlag == 1 {
|
524
|
532
|
response.Result = 2
|
525
|
533
|
response.Msg = "no ads"
|
|
@@ -536,7 +544,7 @@ func adsHandler(c *gin.Context) {
|
536
|
544
|
c.String(404, "get custom ads info failed: %s", err.Error())
|
537
|
545
|
return
|
538
|
546
|
}
|
539
|
|
- log.Infof("dingtou: %+v", customAdData)
|
|
547
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("dingtou: %+v", customAdData)
|
540
|
548
|
|
541
|
549
|
// 定投没有就跑其他的
|
542
|
550
|
if customAdData == nil {
|
|
@@ -554,7 +562,7 @@ func adsHandler(c *gin.Context) {
|
554
|
562
|
if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
|
555
|
563
|
adDataBytes, err := json.Marshal(*customAdData)
|
556
|
564
|
if err != nil {
|
557
|
|
- log.Errorf("marshal adData failed: %s\n", err)
|
|
565
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("marshal adData failed: %s\n", err)
|
558
|
566
|
}
|
559
|
567
|
grayLogData := struct {
|
560
|
568
|
Ip string
|
|
@@ -606,7 +614,7 @@ func adsHandler(c *gin.Context) {
|
606
|
614
|
|
607
|
615
|
adDataBytes, err := json.Marshal(lastAdData)
|
608
|
616
|
if err != nil {
|
609
|
|
- log.Errorf("marshal adData failed: %s", err)
|
|
617
|
+ log.WithField("request_id", dspInfo.RequestId).Errorf("marshal adData failed: %s", err)
|
610
|
618
|
}
|
611
|
619
|
grayLogData := struct {
|
612
|
620
|
ShortMessage string `json:"short_message"`
|
|
@@ -617,7 +625,7 @@ func adsHandler(c *gin.Context) {
|
617
|
625
|
}
|
618
|
626
|
|
619
|
627
|
graylog.Log(grayLogData)
|
620
|
|
- log.Infof("replace addata: %+v", lastAdData)
|
|
628
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("replace addata: %+v", lastAdData)
|
621
|
629
|
customAdData = &lastAdData
|
622
|
630
|
}
|
623
|
631
|
}
|
|
@@ -627,19 +635,19 @@ func adsHandler(c *gin.Context) {
|
627
|
635
|
response.Result = 0
|
628
|
636
|
response.Msg = "ok"
|
629
|
637
|
|
630
|
|
- log.Infof("rsp1: %+v", customAdData)
|
|
638
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %+v", customAdData)
|
631
|
639
|
jsonBytes, err := json.Marshal(customAdData)
|
632
|
640
|
if err != nil {
|
633
|
641
|
c.String(404, "marsha custom addata failed: %s", err.Error())
|
634
|
642
|
return
|
635
|
643
|
}
|
636
|
|
- log.Infof("rsp1: %s", jsonBytes)
|
|
644
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %s", jsonBytes)
|
637
|
645
|
encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
|
638
|
646
|
response.AdsResult = encryptData
|
639
|
647
|
|
640
|
|
- log.Infof("encrypt: %s", encryptData)
|
|
648
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("encrypt: %s", encryptData)
|
641
|
649
|
s, err := encrypt.Decrypt(encryptData, []byte(adslib.GetConf().SecretKey))
|
642
|
|
- log.Info(s, err)
|
|
650
|
+ log.WithField("request_id", dspInfo.RequestId).Info(s, err)
|
643
|
651
|
|
644
|
652
|
graylog.ReportGrayLog(request, dspInfo, 0, 0)
|
645
|
653
|
rspBytes, err := json.Marshal(response)
|
|
@@ -647,7 +655,7 @@ func adsHandler(c *gin.Context) {
|
647
|
655
|
c.String(404, "marshal Response failed: %s", err.Error())
|
648
|
656
|
return
|
649
|
657
|
}
|
650
|
|
- log.Infof("rsp1: %s", rspBytes)
|
|
658
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %s", rspBytes)
|
651
|
659
|
c.String(200, string(rspBytes))
|
652
|
660
|
return
|
653
|
661
|
} else {
|
|
@@ -676,6 +684,6 @@ func adsHandler(c *gin.Context) {
|
676
|
684
|
graylog.ReportGrayLog(request, dspInfo, 0, 0)
|
677
|
685
|
}
|
678
|
686
|
device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
|
679
|
|
- log.Infof("rsp3: %s", rspBytes)
|
|
687
|
+ log.WithField("request_id", dspInfo.RequestId).Infof("rsp3: %s", rspBytes)
|
680
|
688
|
c.String(200, string(rspBytes))
|
681
|
689
|
}
|