|
@@ -4,6 +4,7 @@ import (
|
4
|
4
|
"encoding/json"
|
5
|
5
|
"fmt"
|
6
|
6
|
"github.com/gin-gonic/gin"
|
|
7
|
+ "io"
|
7
|
8
|
"math/rand"
|
8
|
9
|
"miads/adslib"
|
9
|
10
|
"miads/adslib/addata"
|
|
@@ -16,9 +17,13 @@ import (
|
16
|
17
|
"miads/adslib/redis_data"
|
17
|
18
|
"miads/adslib/utils"
|
18
|
19
|
"net/url"
|
|
20
|
+ "os"
|
19
|
21
|
"strconv"
|
20
|
22
|
"strings"
|
21
|
23
|
"time"
|
|
24
|
+
|
|
25
|
+ "github.com/lestrrat-go/file-rotatelogs"
|
|
26
|
+ log "github.com/sirupsen/logrus"
|
22
|
27
|
)
|
23
|
28
|
|
24
|
29
|
type Response struct {
|
|
@@ -28,13 +33,39 @@ type Response struct {
|
28
|
33
|
addata.AdData
|
29
|
34
|
}
|
30
|
35
|
|
|
36
|
+func setupLogger(logName string, logLevel log.Level) {
|
|
37
|
+ writer, err := rotatelogs.New(
|
|
38
|
+ logName+".%Y%m%d",
|
|
39
|
+
|
|
40
|
+ // WithLinkName为最新的日志建立软连接,以方便随着找到当前日志文件
|
|
41
|
+ rotatelogs.WithLinkName(logName),
|
|
42
|
+
|
|
43
|
+ // WithRotationTime设置日志分割的时间,这里设置为一小时分割一次
|
|
44
|
+ rotatelogs.WithRotationTime(time.Hour),
|
|
45
|
+
|
|
46
|
+ // WithMaxAge和WithRotationCount二者只能设置一个,
|
|
47
|
+ // WithMaxAge设置文件清理前的最长保存时间,
|
|
48
|
+ // WithRotationCount设置文件清理前最多保存的个数。
|
|
49
|
+ rotatelogs.WithMaxAge(time.Hour*24*3),
|
|
50
|
+ )
|
|
51
|
+
|
|
52
|
+ if err != nil {
|
|
53
|
+ log.Errorf("config local file system for logger error: %v", err)
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ log.SetReportCaller(true)
|
|
57
|
+ log.SetLevel(logLevel)
|
|
58
|
+ log.SetOutput(io.MultiWriter(writer, os.Stdout))
|
|
59
|
+}
|
|
60
|
+
|
31
|
61
|
func adsHandler(c *gin.Context) {
|
|
62
|
+ setupLogger("log/ads.log", log.TraceLevel)
|
32
|
63
|
c.Header("Content-Type", "application/json")
|
33
|
64
|
|
34
|
65
|
request := adslib.Request{}
|
35
|
66
|
request.Parse(c)
|
36
|
67
|
|
37
|
|
- fmt.Printf("%+v\n", request)
|
|
68
|
+ log.Printf("%+v", request)
|
38
|
69
|
advertiser := "xiaomi"
|
39
|
70
|
uaClient := request.UaClient
|
40
|
71
|
// 获取ua
|
|
@@ -111,7 +142,9 @@ func adsHandler(c *gin.Context) {
|
111
|
142
|
graylog.Log(grayLogData)
|
112
|
143
|
}
|
113
|
144
|
|
|
145
|
+ // 定制city code
|
114
|
146
|
cityCode, err := city.GetCityCode(ipInfo.City)
|
|
147
|
+ log.Infof("got city code: %d", cityCode)
|
115
|
148
|
if err != nil {
|
116
|
149
|
c.String(404, "get city code failed: %s", err)
|
117
|
150
|
return
|
|
@@ -131,11 +164,12 @@ func adsHandler(c *gin.Context) {
|
131
|
164
|
// 频率控制
|
132
|
165
|
freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
|
133
|
166
|
if err != nil {
|
|
167
|
+ log.Errorf("get freq control conf failed: %s", err)
|
134
|
168
|
c.String(404, "get freq control conf failed: %s", err)
|
135
|
169
|
return
|
136
|
170
|
}
|
137
|
171
|
|
138
|
|
- fmt.Printf("freq control conf: %+v\n", freqControlConf)
|
|
172
|
+ log.Infof("freq control conf: %+v", freqControlConf)
|
139
|
173
|
hour, _ := strconv.Atoi(time.Now().Format("01"))
|
140
|
174
|
tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
|
141
|
175
|
if ok {
|
|
@@ -153,16 +187,17 @@ func adsHandler(c *gin.Context) {
|
153
|
187
|
needControl := false
|
154
|
188
|
if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
|
155
|
189
|
// 需要凭空
|
|
190
|
+ log.Infof("need control: %d", lastReqTime)
|
156
|
191
|
needControl = true
|
157
|
192
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
|
158
|
193
|
} else {
|
159
|
194
|
device.SetIpReqTime(ip, time.Now().Unix())
|
160
|
195
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
|
161
|
196
|
}
|
162
|
|
-
|
163
|
197
|
//### 检查是否是ip黑名单
|
164
|
198
|
isIpBlack, err := ads_checker.CheckBlackIp(ip)
|
165
|
199
|
if err != nil {
|
|
200
|
+ log.Errorf("check black ip failed: %s", err)
|
166
|
201
|
c.String(404, "check black ip failed: %s", err)
|
167
|
202
|
return
|
168
|
203
|
}
|
|
@@ -174,6 +209,7 @@ func adsHandler(c *gin.Context) {
|
174
|
209
|
// 获取渠道的黑白性
|
175
|
210
|
reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
|
176
|
211
|
if err != nil {
|
|
212
|
+ log.Errorf("get req channel flag failed: %s", err)
|
177
|
213
|
c.String(404, "get req channel flag failed: %s", err)
|
178
|
214
|
return
|
179
|
215
|
}
|
|
@@ -205,10 +241,12 @@ func adsHandler(c *gin.Context) {
|
205
|
241
|
randomNum := 3
|
206
|
242
|
deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
|
207
|
243
|
if err != nil {
|
208
|
|
- c.String(404, "get req channel flag failed")
|
|
244
|
+ log.Errorf("get mi device conf failed: %s", err)
|
|
245
|
+ c.String(404, "get mi device conf failed: %s", err)
|
209
|
246
|
return
|
210
|
247
|
}
|
211
|
248
|
if deviceConf != nil {
|
|
249
|
+ log.Infof("use cache imei: %+v", deviceConf)
|
212
|
250
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CACHE", cityCode) // 通过缓存请求
|
213
|
251
|
imei = deviceConf.Imei
|
214
|
252
|
uaClient = deviceConf.Ua
|
|
@@ -228,7 +266,8 @@ func adsHandler(c *gin.Context) {
|
228
|
266
|
fakeImei := ""
|
229
|
267
|
fakeDeviceConf, leftCnt, err := device.GetDailyFakeDeviceConfByCityCode(cityCode)
|
230
|
268
|
if err != nil {
|
231
|
|
- c.String(404, "get device conf failed")
|
|
269
|
+ log.Errorf("get device conf failed: %s", err)
|
|
270
|
+ c.String(404, "get device conf failed: %s", err)
|
232
|
271
|
return
|
233
|
272
|
}
|
234
|
273
|
|
|
@@ -237,7 +276,10 @@ func adsHandler(c *gin.Context) {
|
237
|
276
|
replaceUa := ""
|
238
|
277
|
if fakeDeviceConf != nil {
|
239
|
278
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_REPL", cityCode)
|
240
|
|
- device.SetMiDeviceConf(realRedisKey, *fakeDeviceConf)
|
|
279
|
+ err := device.SetMiDeviceConf(realRedisKey, *fakeDeviceConf)
|
|
280
|
+ if err != nil {
|
|
281
|
+ log.Errorf("set mi device conf failed: %s", err)
|
|
282
|
+ }
|
241
|
283
|
imei = fakeDeviceConf.Imei
|
242
|
284
|
uaClient = fakeDeviceConf.Ua
|
243
|
285
|
originImei = fakeDeviceConf.OriginImei
|
|
@@ -283,6 +325,7 @@ func adsHandler(c *gin.Context) {
|
283
|
325
|
// 解码ua_client
|
284
|
326
|
uaClient, _ = url.QueryUnescape(uaClient)
|
285
|
327
|
} else if request.IsMiDevice() {
|
|
328
|
+ log.Info("real mi")
|
286
|
329
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
|
287
|
330
|
userFlag = 3
|
288
|
331
|
sendPhoneType = 1
|
|
@@ -291,14 +334,18 @@ func adsHandler(c *gin.Context) {
|
291
|
334
|
// 检查下,替换后的设备是否是黑名单, 再次检查, 防止放入cache后, 新增了黑名单
|
292
|
335
|
isBlackImei, err := device.CheckIsBlackImei(imei, false)
|
293
|
336
|
if err != nil {
|
294
|
|
- c.String(404, "get device conf failed")
|
|
337
|
+ log.Errorf("get device conf failed: %s", err)
|
|
338
|
+ c.String(404, "get device conf failed: %s", err)
|
295
|
339
|
return
|
296
|
340
|
}
|
297
|
341
|
|
|
342
|
+ log.Tracef("replace flag: %d", replaceFlag)
|
298
|
343
|
if isBlackImei {
|
299
|
344
|
if replaceFlag == 1 {
|
|
345
|
+ log.Trace("replace")
|
300
|
346
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
|
301
|
347
|
} else {
|
|
348
|
+ log.Trace("not replace")
|
302
|
349
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI", cityCode)
|
303
|
350
|
}
|
304
|
351
|
}
|
|
@@ -337,6 +384,7 @@ func adsHandler(c *gin.Context) {
|
337
|
384
|
}
|
338
|
385
|
|
339
|
386
|
dspInfo.RealMd5Imei = md5Imei
|
|
387
|
+ log.Infof("dsp: %+v", dspInfo)
|
340
|
388
|
//ads_item = None
|
341
|
389
|
//xiaomi_response = []
|
342
|
390
|
hour, _ := strconv.Atoi(time.Now().Format("01"))
|
|
@@ -349,17 +397,27 @@ func adsHandler(c *gin.Context) {
|
349
|
397
|
}
|
350
|
398
|
}
|
351
|
399
|
|
|
400
|
+ log.Infof("can request: %t", canRequest)
|
|
401
|
+
|
352
|
402
|
var adData *addata.AdData
|
353
|
403
|
|
354
|
404
|
// 非频率控制,设备黑名单,ip黑名单,白名单渠道,并且替换了小米设备的
|
355
|
405
|
if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
|
356
|
406
|
adData, err = addata.GetAdsInfos(&dspInfo, advertiser)
|
|
407
|
+ if err != nil {
|
|
408
|
+ log.Errorf("get mi ad data failed: %s", err)
|
|
409
|
+ c.String(404, "get mi ad data failed: %s", err)
|
|
410
|
+ return
|
|
411
|
+ }
|
|
412
|
+ log.Infof("get mi ads data: %+v", adData)
|
357
|
413
|
}
|
358
|
414
|
|
359
|
|
- canMixFlag := 0
|
|
415
|
+ canMixFlag := 1
|
360
|
416
|
xiaomiResponseFlag := 0
|
361
|
417
|
response := Response{}
|
|
418
|
+ response.Msg = "ok"
|
362
|
419
|
if adData != nil && len(adData.TargetAddition) > 1 {
|
|
420
|
+ log.Infof("add target js order")
|
363
|
421
|
xiaomiResponseFlag = 1
|
364
|
422
|
realTarget := ""
|
365
|
423
|
if adData.Target != "" {
|
|
@@ -372,7 +430,13 @@ func adsHandler(c *gin.Context) {
|
372
|
430
|
redis_data.SetSkipInfo(md5Skip, adData.Target)
|
373
|
431
|
}
|
374
|
432
|
adData.Target = realTarget
|
375
|
|
- adData.JsOrderId, _ = redis_data.GetMinScriptOrderByAdv(advertiser)
|
|
433
|
+ adData.JsOrderId, err = redis_data.GetMinScriptOrderByAdv(advertiser)
|
|
434
|
+ if err != nil {
|
|
435
|
+ log.Errorf("get min script order by adv failed: %s", err)
|
|
436
|
+ c.String(404, "get min script order by adv failed: %s", err)
|
|
437
|
+ return
|
|
438
|
+ }
|
|
439
|
+ log.Infof("got min script order: %d", adData.JsOrderId)
|
376
|
440
|
adData.UserAgent = uaClient
|
377
|
441
|
|
378
|
442
|
if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
|
|
@@ -385,21 +449,21 @@ func adsHandler(c *gin.Context) {
|
385
|
449
|
device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET_1", cityCode) // 广告获取成功
|
386
|
450
|
}
|
387
|
451
|
device.SetAdsTagLog(advertiser, dspInfo.ReqSource, fmt.Sprintf("ADS_USER_%d", userFlag), cityCode) // 广告类型,缓存,新用户,小米手机
|
388
|
|
- // 判断这个渠道是否要去融合和融合的流量占比
|
389
|
|
- mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
|
390
|
|
- if err != nil {
|
391
|
|
- c.String(404, "get device conf failed")
|
392
|
|
- return
|
393
|
|
- }
|
|
452
|
+ // // 判断这个渠道是否要去融合和融合的流量占比
|
|
453
|
+ // mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
|
|
454
|
+ // if err != nil {
|
|
455
|
+ // log.Errorf("get device conf failed: %s", err)
|
|
456
|
+ // c.String(404, "get device conf failed: %s", err)
|
|
457
|
+ // return
|
|
458
|
+ // }
|
394
|
459
|
flowRandomNum = rand.Intn(100)
|
395
|
|
- isOverFlow := false
|
396
|
|
- //flow_flag = 0
|
397
|
|
- if flowRandomNum > mixChannelFlag.Weigth {
|
398
|
|
- isOverFlow = true
|
399
|
|
- }
|
400
|
|
- if mixChannelFlag.ChannelFlag != 1 || isOverFlow {
|
401
|
|
- //extra_infos = []
|
402
|
|
- }
|
|
460
|
+ //isOverFlow := false
|
|
461
|
+ //if flowRandomNum > mixChannelFlag.Weigth {
|
|
462
|
+ // isOverFlow = true
|
|
463
|
+ //}
|
|
464
|
+ //if mixChannelFlag.ChannelFlag != 1 || isOverFlow {
|
|
465
|
+ // //extra_infos = []
|
|
466
|
+ //}
|
403
|
467
|
|
404
|
468
|
// 组装返回去的action
|
405
|
469
|
serverActionResponse := map[string]int{"server_view": 0, "server_click": 0, "server_close": 0, "server_video_finish": 0, "server_video_timer": 0}
|
|
@@ -417,27 +481,33 @@ func adsHandler(c *gin.Context) {
|
417
|
481
|
serverActionResponse["server_video_timer"] = 1
|
418
|
482
|
}
|
419
|
483
|
}
|
420
|
|
-
|
|
484
|
+ log.Infof("server action response: %+v", serverActionResponse)
|
421
|
485
|
// 增加跟随订单
|
422
|
486
|
if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
|
423
|
|
- adData, err = addata.CombineOrderBy(adData, advertiser, &dspInfo)
|
|
487
|
+ log.Infof("add more order")
|
|
488
|
+ adData, err = addata.CombineOrderBy(adData, &dspInfo)
|
424
|
489
|
if err != nil {
|
|
490
|
+ log.Errorf("combine order failed: %s", err)
|
425
|
491
|
c.String(404, "combine order failed: %s", err.Error())
|
426
|
492
|
return
|
427
|
493
|
}
|
|
494
|
+ log.Infof("get custom order: %+v", adData)
|
428
|
495
|
}
|
429
|
496
|
|
430
|
497
|
//# 检查最后是否有click
|
431
|
|
- //last_target_addition_infos = ads_item_new.get('target_addition',[])
|
|
498
|
+ log.Infof("check ads item new: %+v", adData)
|
|
499
|
+
|
432
|
500
|
for _, targetAddition := range adData.TargetAddition {
|
433
|
501
|
if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
|
|
502
|
+ log.Infof("can't mix, targetAddition: %+v", targetAddition)
|
434
|
503
|
canMixFlag = 0
|
435
|
504
|
break
|
436
|
505
|
}
|
437
|
506
|
}
|
438
|
507
|
|
439
|
508
|
if request.NewAdsFlag == 0 {
|
440
|
|
- //response.update(ads_item_new)
|
|
509
|
+ response.AdData = *adData
|
|
510
|
+ log.Infof("update response: +%v", response)
|
441
|
511
|
} else {
|
442
|
512
|
jsonBytes, err := json.Marshal(*adData)
|
443
|
513
|
if err != nil {
|
|
@@ -448,6 +518,8 @@ func adsHandler(c *gin.Context) {
|
448
|
518
|
response.AdsResult = encryptData
|
449
|
519
|
}
|
450
|
520
|
}
|
|
521
|
+
|
|
522
|
+ log.Infof("can mix: %d, xiaomi rsp flag: %d", canMixFlag, xiaomiResponseFlag)
|
451
|
523
|
if canMixFlag == 1 {
|
452
|
524
|
response.Result = 2
|
453
|
525
|
response.Msg = "no ads"
|
|
@@ -458,15 +530,17 @@ func adsHandler(c *gin.Context) {
|
458
|
530
|
// 增加打底广告
|
459
|
531
|
if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needControl && !isBlackImei {
|
460
|
532
|
shortMessage := "kong"
|
461
|
|
- customAdData, err := addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 0, xiaomiResponseFlag)
|
|
533
|
+ // 先跑定投
|
|
534
|
+ customAdData, err := addata.GetCustomAdsInfos(&dspInfo, 0, 0, xiaomiResponseFlag)
|
462
|
535
|
if err != nil {
|
463
|
536
|
c.String(404, "get custom ads info failed: %s", err.Error())
|
464
|
537
|
return
|
465
|
538
|
}
|
|
539
|
+ log.Infof("dingtou: %+v", customAdData)
|
466
|
540
|
|
467
|
541
|
// 定投没有就跑其他的
|
468
|
542
|
if customAdData == nil {
|
469
|
|
- customAdData, err = addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 1, xiaomiResponseFlag)
|
|
543
|
+ customAdData, err = addata.GetCustomAdsInfos(&dspInfo, 0, 1, xiaomiResponseFlag)
|
470
|
544
|
if err != nil {
|
471
|
545
|
c.String(404, "get fix custom ads info failed: %s", err.Error())
|
472
|
546
|
return
|
|
@@ -478,9 +552,9 @@ func adsHandler(c *gin.Context) {
|
478
|
552
|
}
|
479
|
553
|
|
480
|
554
|
if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
|
481
|
|
- adDataBytes, err := json.Marshal(*adData)
|
|
555
|
+ adDataBytes, err := json.Marshal(*customAdData)
|
482
|
556
|
if err != nil {
|
483
|
|
- fmt.Sprintf("marshal addata failed: %s\n", err)
|
|
557
|
+ log.Errorf("marshal adData failed: %s\n", err)
|
484
|
558
|
}
|
485
|
559
|
grayLogData := struct {
|
486
|
560
|
Ip string
|
|
@@ -508,43 +582,44 @@ func adsHandler(c *gin.Context) {
|
508
|
582
|
if len(response.TargetAddition) != 0 && len(customAdData.TargetAddition) != 0 {
|
509
|
583
|
rspTargetAddition = response.TargetAddition
|
510
|
584
|
lastAdData.UserAgent = response.UserAgent
|
511
|
|
- }
|
512
|
|
- // 当只有view的时候
|
513
|
|
- if len(customAdData.TargetAddition) == 1 {
|
514
|
|
- for _, url := range customAdData.TargetAddition[0].Urls {
|
515
|
|
- rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
|
516
|
|
- }
|
517
|
|
- } else {
|
518
|
|
- // 当自由订单有view和click的时候
|
519
|
|
- for _, url := range customAdData.TargetAddition[0].Urls {
|
520
|
|
- rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
|
|
585
|
+ // 当只有view的时候
|
|
586
|
+ if len(customAdData.TargetAddition) == 1 {
|
|
587
|
+ for _, targetUrl := range customAdData.TargetAddition[0].Urls {
|
|
588
|
+ rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, targetUrl)
|
|
589
|
+ }
|
|
590
|
+ } else {
|
|
591
|
+ // 当自由订单有view和click的时候
|
|
592
|
+ for _, targetUrl := range customAdData.TargetAddition[0].Urls {
|
|
593
|
+ rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, targetUrl)
|
|
594
|
+ }
|
|
595
|
+
|
|
596
|
+ for _, targetUrl := range customAdData.TargetAddition[1].Urls {
|
|
597
|
+ rspTargetAddition[1].Urls = append(rspTargetAddition[1].Urls, targetUrl)
|
|
598
|
+ }
|
|
599
|
+ rspTargetAddition[1].Type = "CLICK"
|
521
|
600
|
}
|
|
601
|
+ lastAdData.Target = customAdData.Target
|
|
602
|
+ lastAdData.JsOrderId = customAdData.JsOrderId
|
|
603
|
+ lastAdData.TargetAddition = rspTargetAddition
|
|
604
|
+ lastAdData.DpReport = response.DpReport
|
|
605
|
+ lastAdData.Dp = response.Dp
|
522
|
606
|
|
523
|
|
- for _, url := range customAdData.TargetAddition[1].Urls {
|
524
|
|
- rspTargetAddition[1].Urls = append(rspTargetAddition[1].Urls, url)
|
|
607
|
+ adDataBytes, err := json.Marshal(lastAdData)
|
|
608
|
+ if err != nil {
|
|
609
|
+ log.Errorf("marshal adData failed: %s", err)
|
|
610
|
+ }
|
|
611
|
+ grayLogData := struct {
|
|
612
|
+ ShortMessage string `json:"short_message"`
|
|
613
|
+ ResponseVast string `json:"response_vast"`
|
|
614
|
+ }{
|
|
615
|
+ ShortMessage: "third_mix_xiaomi",
|
|
616
|
+ ResponseVast: string(adDataBytes),
|
525
|
617
|
}
|
526
|
|
- rspTargetAddition[1].Type = "CLICK"
|
527
|
|
- }
|
528
|
|
- lastAdData.Target = customAdData.Target
|
529
|
|
- lastAdData.JsOrderId = customAdData.JsOrderId
|
530
|
|
- lastAdData.TargetAddition = rspTargetAddition
|
531
|
|
- lastAdData.DpReport = response.DpReport
|
532
|
|
- lastAdData.Dp = response.Dp
|
533
|
618
|
|
534
|
|
- adDataBytes, err := json.Marshal(lastAdData)
|
535
|
|
- if err != nil {
|
536
|
|
- fmt.Sprintf("marshal addata failed: %s\n", err)
|
|
619
|
+ graylog.Log(grayLogData)
|
|
620
|
+ log.Infof("replace addata: %+v", lastAdData)
|
|
621
|
+ customAdData = &lastAdData
|
537
|
622
|
}
|
538
|
|
- grayLogData := struct {
|
539
|
|
- ShortMessage string `json:"short_message"`
|
540
|
|
- ResponseVast string `json:"response_vast"`
|
541
|
|
- }{
|
542
|
|
- ShortMessage: "third_mix_xiaomi",
|
543
|
|
- ResponseVast: string(adDataBytes),
|
544
|
|
- }
|
545
|
|
-
|
546
|
|
- graylog.Log(grayLogData)
|
547
|
|
- customAdData = &lastAdData
|
548
|
623
|
}
|
549
|
624
|
if customAdData != nil {
|
550
|
625
|
device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_HAVE", cityCode) // 广告获取成功
|
|
@@ -552,19 +627,27 @@ func adsHandler(c *gin.Context) {
|
552
|
627
|
response.Result = 0
|
553
|
628
|
response.Msg = "ok"
|
554
|
629
|
|
|
630
|
+ log.Infof("rsp1: %+v", customAdData)
|
555
|
631
|
jsonBytes, err := json.Marshal(customAdData)
|
556
|
632
|
if err != nil {
|
557
|
633
|
c.String(404, "marsha custom addata failed: %s", err.Error())
|
558
|
634
|
return
|
559
|
635
|
}
|
|
636
|
+ log.Infof("rsp1: %s", jsonBytes)
|
560
|
637
|
encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
|
561
|
638
|
response.AdsResult = encryptData
|
|
639
|
+
|
|
640
|
+ log.Infof("encrypt: %s", encryptData)
|
|
641
|
+ s, err := encrypt.Decrypt(encryptData, []byte(adslib.GetConf().SecretKey))
|
|
642
|
+ log.Info(s, err)
|
|
643
|
+
|
562
|
644
|
graylog.ReportGrayLog(request, dspInfo, 0, 0)
|
563
|
645
|
rspBytes, err := json.Marshal(response)
|
564
|
646
|
if err != nil {
|
565
|
647
|
c.String(404, "marshal Response failed: %s", err.Error())
|
566
|
648
|
return
|
567
|
649
|
}
|
|
650
|
+ log.Infof("rsp1: %s", rspBytes)
|
568
|
651
|
c.String(200, string(rspBytes))
|
569
|
652
|
return
|
570
|
653
|
} else {
|
|
@@ -593,5 +676,6 @@ func adsHandler(c *gin.Context) {
|
593
|
676
|
graylog.ReportGrayLog(request, dspInfo, 0, 0)
|
594
|
677
|
}
|
595
|
678
|
device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
|
|
679
|
+ log.Infof("rsp3: %s", rspBytes)
|
596
|
680
|
c.String(200, string(rspBytes))
|
597
|
681
|
}
|