|
@@ -25,9 +25,10 @@ import (
|
25
|
25
|
var SECERET_KEY = "%videoopen%!@#$%"
|
26
|
26
|
|
27
|
27
|
type Response struct {
|
28
|
|
- Result int `json:"result"`
|
29
|
|
- Msg string`json:"msg"`
|
30
|
|
- AdsResult string`json:"ads_result"`
|
|
28
|
+ Result int `json:"result"`
|
|
29
|
+ Msg string `json:"msg"`
|
|
30
|
+ AdsResult string `json:"ads_result"`
|
|
31
|
+ addata.AdData
|
31
|
32
|
}
|
32
|
33
|
|
33
|
34
|
func adsHandler(c *gin.Context) {
|
|
@@ -62,7 +63,7 @@ func adsHandler(c *gin.Context) {
|
62
|
63
|
ip = request.ReqSourceIp
|
63
|
64
|
}
|
64
|
65
|
|
65
|
|
- if ip=="" {
|
|
66
|
+ if ip == "" {
|
66
|
67
|
ip = c.GetHeader("X-Forwarded-For")
|
67
|
68
|
}
|
68
|
69
|
|
|
@@ -85,24 +86,24 @@ func adsHandler(c *gin.Context) {
|
85
|
86
|
// 上報
|
86
|
87
|
if request.NewAdsFlag == 1 {
|
87
|
88
|
grayLogData := struct {
|
88
|
|
- Ip string
|
89
|
|
- Imei string
|
90
|
|
- Model string
|
91
|
|
- NetworkType int `json:"network_type"`
|
92
|
|
- Province string
|
93
|
|
- City string
|
94
|
|
- ScreeSize string `json:"screen_size"`
|
95
|
|
- Ua string
|
96
|
|
- Brand string
|
97
|
|
- Androidid string `json:"android_id"`
|
|
89
|
+ Ip string
|
|
90
|
+ Imei string
|
|
91
|
+ Model string
|
|
92
|
+ NetworkType int `json:"network_type"`
|
|
93
|
+ Province string
|
|
94
|
+ City string
|
|
95
|
+ ScreeSize string `json:"screen_size"`
|
|
96
|
+ Ua string
|
|
97
|
+ Brand string
|
|
98
|
+ Androidid string `json:"android_id"`
|
98
|
99
|
ShortMessage string `json:"short_message"`
|
99
|
|
- ReqSource string `json:"req_source"`
|
|
100
|
+ ReqSource string `json:"req_source"`
|
100
|
101
|
}{
|
101
|
102
|
Ip: ip,
|
102
|
103
|
Imei: request.Imei,
|
103
|
104
|
Model: request.Model,
|
104
|
105
|
NetworkType: request.NetworkType,
|
105
|
|
- Province: ipInfo.Province,
|
|
106
|
+ Province: ipInfo.Province,
|
106
|
107
|
City: ipInfo.City,
|
107
|
108
|
ScreeSize: request.ScreenSize,
|
108
|
109
|
Ua: request.UaClient,
|
|
@@ -122,16 +123,16 @@ func adsHandler(c *gin.Context) {
|
122
|
123
|
}
|
123
|
124
|
|
124
|
125
|
// 是否是安卓
|
125
|
|
- if request.Imei =="" {
|
|
126
|
+ if request.Imei == "" {
|
126
|
127
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_IOS", cityCode)
|
127
|
|
- graylog.LogApi("ios_device", request.Idfa,"", request.ReqSource)
|
|
128
|
+ graylog.LogApi("ios_device", request.Idfa, "", request.ReqSource)
|
128
|
129
|
} else {
|
129
|
|
- device.SetAdsTagLog(advertiser, request.ReqSource,"DS_ANDRIOID", cityCode)
|
|
130
|
+ device.SetAdsTagLog(advertiser, request.ReqSource, "DS_ANDRIOID", cityCode)
|
130
|
131
|
}
|
131
|
132
|
|
132
|
133
|
freqControlInterval := 600
|
133
|
134
|
// 深圳,东莞强行用600秒控制, 其他地区从配置读取
|
134
|
|
- if strings.Index(ipInfo.City, "深圳")== -1 && strings.Index(ipInfo.City, "东莞")==-1 {
|
|
135
|
+ if strings.Index(ipInfo.City, "深圳") == -1 && strings.Index(ipInfo.City, "东莞") == -1 {
|
135
|
136
|
// 频率控制
|
136
|
137
|
freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
|
137
|
138
|
if err != nil {
|
|
@@ -153,13 +154,13 @@ func adsHandler(c *gin.Context) {
|
153
|
154
|
}
|
154
|
155
|
|
155
|
156
|
needControl := false
|
156
|
|
- if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix() - lastReqTime < int64(freqControlInterval) {
|
|
157
|
+ if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
|
157
|
158
|
// 需要凭空
|
158
|
159
|
needControl = true
|
159
|
|
- device.SetAdsTagLog(advertiser, request.ReqSource,"DS_FREQ_0", cityCode)
|
|
160
|
+ device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
|
160
|
161
|
} else {
|
161
|
162
|
device.SetIpReqTime(ip, time.Now().Unix())
|
162
|
|
- device.SetAdsTagLog(advertiser, request.ReqSource,"DS_FREQ_1", cityCode)
|
|
163
|
+ device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
|
163
|
164
|
}
|
164
|
165
|
|
165
|
166
|
//### 检查是否是ip黑名单
|
|
@@ -169,12 +170,12 @@ func adsHandler(c *gin.Context) {
|
169
|
170
|
return
|
170
|
171
|
}
|
171
|
172
|
if isIpBlack {
|
172
|
|
- graylog.LogApi("black_ip_list", ip,"", request.ReqSource)
|
173
|
|
- device.SetAdsTagLog(advertiser, request.ReqSource,"DS_BLACK_IP", cityCode)
|
|
173
|
+ graylog.LogApi("black_ip_list", ip, "", request.ReqSource)
|
|
174
|
+ device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IP", cityCode)
|
174
|
175
|
}
|
175
|
176
|
|
176
|
177
|
// 获取渠道的黑白性
|
177
|
|
- reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource,"ads_req")
|
|
178
|
+ reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
|
178
|
179
|
if err != nil {
|
179
|
180
|
c.String(404, "get req channel flag failed")
|
180
|
181
|
return
|
|
@@ -182,12 +183,12 @@ func adsHandler(c *gin.Context) {
|
182
|
183
|
flowWeight := reqChannelFlag.Weigth
|
183
|
184
|
flowRandomNum := rand.Intn(100)
|
184
|
185
|
|
185
|
|
- flowFlag := 0 // 有效的百分比
|
186
|
|
- if flowRandomNum <= flowWeight{
|
|
186
|
+ flowFlag := 0 // 有效的百分比
|
|
187
|
+ if flowRandomNum <= flowWeight {
|
187
|
188
|
flowFlag = 1
|
188
|
189
|
}
|
189
|
190
|
if reqChannelFlag.ChannelFlag == 1 {
|
190
|
|
- device.SetAdsTagLog(advertiser, request.ReqSource,fmt.Sprintf("DS_REQ_SOURCE_{%d}", reqChannelFlag.ChannelFlag), cityCode)
|
|
191
|
+ device.SetAdsTagLog(advertiser, request.ReqSource, fmt.Sprintf("DS_REQ_SOURCE_{%d}", reqChannelFlag.ChannelFlag), cityCode)
|
191
|
192
|
}
|
192
|
193
|
|
193
|
194
|
// 替换成小米的设备
|
|
@@ -200,10 +201,10 @@ func adsHandler(c *gin.Context) {
|
200
|
201
|
// 检查是否是小米的设备
|
201
|
202
|
specialDeviceNum := 0
|
202
|
203
|
if request.ReqSource == "wzb_h5" {
|
203
|
|
- specialDeviceNum = 6 // wzb_h5渠道只綁定一个imei, 具体愿意不知道
|
|
204
|
+ specialDeviceNum = 6 // wzb_h5渠道只綁定一个imei, 具体愿意不知道
|
204
|
205
|
}
|
205
|
206
|
if request.ReqSource == "moyuntv" || (!request.IsMiDevice() &&
|
206
|
|
- (!isIpBlack && !needControl && reqChannelFlag.ChannelFlag ==1) && flowFlag == 1) {
|
|
207
|
+ (!isIpBlack && !needControl && reqChannelFlag.ChannelFlag == 1) && flowFlag == 1) {
|
207
|
208
|
randomNum := 3
|
208
|
209
|
deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
|
209
|
210
|
if err != nil {
|
|
@@ -257,7 +258,7 @@ func adsHandler(c *gin.Context) {
|
257
|
258
|
NewImei string `json:"new_imei"`
|
258
|
259
|
IP string `json:"ip"`
|
259
|
260
|
City string `json:"city"`
|
260
|
|
- CityCode int `json:"city_code"`
|
|
261
|
+ CityCode int `json:"city_code"`
|
261
|
262
|
Province string
|
262
|
263
|
HitFlag int `json:"hit_flag"`
|
263
|
264
|
LeftCnt int `json:"left_cnt"`
|
|
@@ -285,7 +286,7 @@ func adsHandler(c *gin.Context) {
|
285
|
286
|
// 解码ua_client
|
286
|
287
|
uaClient, _ = url.QueryUnescape(uaClient)
|
287
|
288
|
} else if request.IsMiDevice() {
|
288
|
|
- device.SetAdsTagLog(advertiser, request.ReqSource,"DS_MI_REAL", cityCode) // 是小米设备
|
|
289
|
+ device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
|
289
|
290
|
userFlag = 3
|
290
|
291
|
sendPhoneType = 1
|
291
|
292
|
}
|
|
@@ -301,7 +302,7 @@ func adsHandler(c *gin.Context) {
|
301
|
302
|
if replaceFlag == 1 {
|
302
|
303
|
device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
|
303
|
304
|
} else {
|
304
|
|
- device.SetAdsTagLog(advertiser, request.ReqSource,"DS_BLACK_IMEI", cityCode)
|
|
305
|
+ device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI", cityCode)
|
305
|
306
|
}
|
306
|
307
|
}
|
307
|
308
|
|
|
@@ -339,13 +340,12 @@ func adsHandler(c *gin.Context) {
|
339
|
340
|
}
|
340
|
341
|
|
341
|
342
|
dspInfo.RealMd5Imei = md5Imei
|
342
|
|
- //response = {'result': 0, 'msg': 'ok','ads_result':''}
|
343
|
343
|
//ads_item = None
|
344
|
344
|
//xiaomi_response = []
|
345
|
345
|
hour, _ := strconv.Atoi(time.Now().Format("01"))
|
346
|
346
|
|
347
|
347
|
canRequest := true
|
348
|
|
- if 0 <= hour && hour <=1 {
|
|
348
|
+ if 0 <= hour && hour <= 1 {
|
349
|
349
|
randNum := rand.Intn(100)
|
350
|
350
|
if randNum > 5 {
|
351
|
351
|
canRequest = false
|
|
@@ -358,16 +358,16 @@ func adsHandler(c *gin.Context) {
|
358
|
358
|
var adDataNum int
|
359
|
359
|
|
360
|
360
|
// 非频率控制,设备黑名单,ip黑名单,白名单渠道,并且替换了小米设备的
|
361
|
|
- if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag ==1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !isBlackImei && !needControl && (replaceFlag==1 || request.IsMiDevice()) {
|
|
361
|
+ if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !isBlackImei && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
|
362
|
362
|
adData, xiaomiResponse, xiaomiRspAction, adDataNum, err = addata.GetAdsInfos(&dspInfo, advertiser)
|
363
|
363
|
}
|
364
|
364
|
|
365
|
365
|
canMixFlag := 0
|
366
|
366
|
xiaomiResponseFlag := 0
|
367
|
367
|
response := Response{}
|
368
|
|
- if adData != nil && len(adData.TargetAddition) > 1 {
|
|
368
|
+ if adData != nil && len(adData.TargetAddition) > 1 {
|
369
|
369
|
realTarget := ""
|
370
|
|
- if adData.Target != ""{
|
|
370
|
+ if adData.Target != "" {
|
371
|
371
|
md5Skip := utils.Md5(addata.Target)
|
372
|
372
|
conf := adslib.GetConf()
|
373
|
373
|
realTarget = conf.Host + fmt.Sprintf("?action=LOADING&req_source=%s&advertiser=video&skip=%s&brand=%s&request_id=%s&skip_other=%s",
|
|
@@ -380,16 +380,16 @@ func adsHandler(c *gin.Context) {
|
380
|
380
|
adData.JsOrderId, _ = redis_data.GetMinScriptOrderByAdv(advertiser)
|
381
|
381
|
adData.UserAgent = uaClient
|
382
|
382
|
|
383
|
|
- if dspInfo.ReqSource =="kuxin" && adData.Target != "" {
|
|
383
|
+ if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
|
384
|
384
|
adData.DpReport = fmt.Sprintf("%s?action=DP_CLICK&advertiser=video&req_source=%s", common.get_request_host(None), dspInfo.ReqSource)
|
385
|
385
|
adData.Dp = adslib.GetConf().DpTest
|
386
|
386
|
}
|
387
|
387
|
if dspInfo.SendPhoneType == 0 {
|
388
|
|
- device.SetAdsTagLog(advertiser,dspInfo.ReqSource,"ADS_GET", cityCode) // 广告获取成功
|
389
|
|
- } else if dspInfo.SendPhoneType==1 {
|
390
|
|
- device.SetAdsTagLog(advertiser,dspInfo.ReqSource,"ADS_GET_1", cityCode) // 广告获取成功
|
|
388
|
+ device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET", cityCode) // 广告获取成功
|
|
389
|
+ } else if dspInfo.SendPhoneType == 1 {
|
|
390
|
+ device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET_1", cityCode) // 广告获取成功
|
391
|
391
|
}
|
392
|
|
- device.SetAdsTagLog(advertiser, dspInfo.ReqSource, fmt.Sprintf("ADS_USER_%d", userFlag), cityCode) // 广告类型,缓存,新用户,小米手机
|
|
392
|
+ device.SetAdsTagLog(advertiser, dspInfo.ReqSource, fmt.Sprintf("ADS_USER_%d", userFlag), cityCode) // 广告类型,缓存,新用户,小米手机
|
393
|
393
|
// 判断这个渠道是否要去融合和融合的流量占比
|
394
|
394
|
mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
|
395
|
395
|
if err != nil {
|
|
@@ -402,29 +402,29 @@ func adsHandler(c *gin.Context) {
|
402
|
402
|
if flowRandomNum > mixChannelFlag.Weigth {
|
403
|
403
|
isOverFlow = true
|
404
|
404
|
}
|
405
|
|
- if mixChannelFlag.ChannelFlag !=1 || isOverFlow {
|
|
405
|
+ if mixChannelFlag.ChannelFlag != 1 || isOverFlow {
|
406
|
406
|
//extra_infos = []
|
407
|
407
|
}
|
408
|
408
|
|
409
|
409
|
// 组装返回去的action
|
410
|
|
- serverActionResponse := map[string]int{"server_view":0,"server_click":0,"server_close":0,"server_video_finish":0,"server_video_timer":0}
|
|
410
|
+ serverActionResponse := map[string]int{"server_view": 0, "server_click": 0, "server_close": 0, "server_video_finish": 0, "server_video_timer": 0}
|
411
|
411
|
for _, targetInfo := range adData.TargetAddition {
|
412
|
412
|
if targetInfo.Type == "VIEW" {
|
413
|
|
- serverActionResponse["server_view"]=1
|
414
|
|
- redis_data.SetReqSourceView(advertiser, dspInfo.ReqSource,"xiafa")
|
|
413
|
+ serverActionResponse["server_view"] = 1
|
|
414
|
+ redis_data.SetReqSourceView(advertiser, dspInfo.ReqSource, "xiafa")
|
415
|
415
|
} else if targetInfo.Type == "CLICK" {
|
416
|
|
- serverActionResponse["server_click"]=1
|
417
|
|
- } else if targetInfo.Type=="CLOSE" {
|
418
|
|
- serverActionResponse["server_close"]=1
|
419
|
|
- } else if targetInfo.Type=="VIDEO_FINISH" {
|
420
|
|
- serverActionResponse["server_video_finish"]=1
|
421
|
|
- } else if targetInfo.Type =="VIDEO_TIMER" {
|
422
|
|
- serverActionResponse["server_video_timer"]=1
|
|
416
|
+ serverActionResponse["server_click"] = 1
|
|
417
|
+ } else if targetInfo.Type == "CLOSE" {
|
|
418
|
+ serverActionResponse["server_close"] = 1
|
|
419
|
+ } else if targetInfo.Type == "VIDEO_FINISH" {
|
|
420
|
+ serverActionResponse["server_video_finish"] = 1
|
|
421
|
+ } else if targetInfo.Type == "VIDEO_TIMER" {
|
|
422
|
+ serverActionResponse["server_video_timer"] = 1
|
423
|
423
|
}
|
424
|
424
|
}
|
425
|
425
|
|
426
|
426
|
// 增加跟随订单
|
427
|
|
- if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
|
|
427
|
+ if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
|
428
|
428
|
adData, err = addata.CombineOrderBy(adData, advertiser, &dspInfo)
|
429
|
429
|
if err != nil {
|
430
|
430
|
return err
|
|
@@ -433,14 +433,14 @@ func adsHandler(c *gin.Context) {
|
433
|
433
|
|
434
|
434
|
//# 检查最后是否有click
|
435
|
435
|
//last_target_addition_infos = ads_item_new.get('target_addition',[])
|
436
|
|
- for _, targetAddition := range adData.TargetAddition {
|
437
|
|
- if targetAddition.Type =="CLICK" || targetAddition.Type == "VIDEO_TIMER" {
|
|
436
|
+ for _, targetAddition := range adData.TargetAddition {
|
|
437
|
+ if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
|
438
|
438
|
canMixFlag = 0
|
439
|
439
|
break
|
440
|
440
|
}
|
441
|
441
|
}
|
442
|
442
|
|
443
|
|
- if request.NewAdsFlag==0 {
|
|
443
|
+ if request.NewAdsFlag == 0 {
|
444
|
444
|
//response.update(ads_item_new)
|
445
|
445
|
} else {
|
446
|
446
|
jsonBytes, err := json.Marshal(*adData)
|
|
@@ -452,22 +452,22 @@ func adsHandler(c *gin.Context) {
|
452
|
452
|
}
|
453
|
453
|
|
454
|
454
|
hour, _ := strconv.Atoi(time.Now().Format("01"))
|
455
|
|
- if 0 <= hour && hour <=23 && replaceFlag ==1 {
|
|
455
|
+ if 0 <= hour && hour <= 23 && replaceFlag == 1 {
|
456
|
456
|
randomNum := utils.Hash(imei) % 10000
|
457
|
457
|
if randomNum < 3000 {
|
458
|
458
|
//add_beanstalk_response.BeanstalkHandle().add_ads_response_info(md5_imei,ads_ip,web.utf8(province),web.utf8(city),ads_item_new,dsp_city_code,req_source,real_imei,xiaomi_response,xiaomi_action,server_action_response,dsp_info.request_id,xiaomi_ads_data_num)
|
459
|
459
|
}
|
460
|
460
|
}
|
461
|
461
|
}
|
462
|
|
- if canMixFlag==1 {
|
|
462
|
+ if canMixFlag == 1 {
|
463
|
463
|
response.Result = 2
|
464
|
464
|
response.Msg = "no ads"
|
465
|
|
- if xiaomiResponseFlag==1 {
|
|
465
|
+ if xiaomiResponseFlag == 1 {
|
466
|
466
|
response.Result = 0
|
467
|
467
|
response.Msg = "ok"
|
468
|
468
|
}
|
469
|
469
|
// 增加打底广告
|
470
|
|
- if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needCotrol ==1 && !isBlackImei {
|
|
470
|
+ if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needCotrol == 1 && !isBlackImei {
|
471
|
471
|
shortMessage := "kong"
|
472
|
472
|
// 先跑定投
|
473
|
473
|
customAdData, err := addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 0, xiaomiResponseFlag)
|
|
@@ -481,12 +481,12 @@ func adsHandler(c *gin.Context) {
|
481
|
481
|
return err
|
482
|
482
|
}
|
483
|
483
|
}
|
484
|
|
- device.SetAdsTagLog(advertiser, dspInfo.ReqSource,"ADS_ZIYOU_GET", cityCode) // 广告获取成功
|
|
484
|
+ device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_GET", cityCode) // 广告获取成功
|
485
|
485
|
if customAdData != nil {
|
486
|
486
|
shortMessage = "ads_tt_thirds"
|
487
|
487
|
}
|
488
|
488
|
|
489
|
|
- if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
|
|
489
|
+ if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
|
490
|
490
|
//response_data_report = {}
|
491
|
491
|
//response_data_report['ip'] = ads_ip
|
492
|
492
|
//response_data_report['short_message'] = short_message
|
|
@@ -496,58 +496,120 @@ func adsHandler(c *gin.Context) {
|
496
|
496
|
//response_data_report['advertiser']=advertiser
|
497
|
497
|
//log.send_to_graylog_tornado(gelf_data=response_data_report)
|
498
|
498
|
|
499
|
|
- adDataBytes, err :=
|
|
499
|
+ adDataBytes, err := json.Marshal(*adData)
|
|
500
|
+ if err != nil {
|
|
501
|
+ fmt.Sprintf("marshal addata failed: %s\n", err)
|
|
502
|
+ }
|
500
|
503
|
grayLogData := struct {
|
501
|
|
- Ip string
|
|
504
|
+ Ip string
|
502
|
505
|
ShortMessage string `json:"short_message"`
|
503
|
|
- ReqSource string `json:"req_source"`
|
|
506
|
+ ReqSource string `json:"req_source"`
|
504
|
507
|
ResponseVast string `json:"response_vast"`
|
505
|
|
- OrderName string `json:"order_name"`
|
506
|
|
- Advertiser string `json:"advertiser"`
|
|
508
|
+ OrderName string `json:"order_name"`
|
|
509
|
+ Advertiser string `json:"advertiser"`
|
507
|
510
|
}{
|
508
|
511
|
Ip: ip,
|
509
|
512
|
ShortMessage: "ads_api_log",
|
510
|
513
|
ReqSource: "zhiku",
|
511
|
|
- ResponseVast: ""
|
512
|
|
- OrderName: customAdData.OrderName,
|
513
|
|
- Advertiser: advertiser,
|
|
514
|
+ ResponseVast: string(adDataBytes),
|
|
515
|
+ OrderName: customAdData.OrderName,
|
|
516
|
+ Advertiser: advertiser,
|
|
517
|
+ }
|
|
518
|
+
|
|
519
|
+ graylog.Log(grayLogData)
|
|
520
|
+ }
|
|
521
|
+ if shortMessage == "ads_tt_thirds" {
|
|
522
|
+ // 组装最后的信息
|
|
523
|
+ lastAdData := addata.AdData{}
|
|
524
|
+ rspTargetAddition := make([]addata.AdAction, 0, 50)
|
|
525
|
+ // 当小米有填充的时候
|
|
526
|
+ if len(response.TargetAddition) != 0 && len(customAdData.TargetAddition) != 0 {
|
|
527
|
+ rspTargetAddition = response.TargetAddition
|
|
528
|
+ lastAdData.UserAgent = response.UserAgent
|
|
529
|
+ }
|
|
530
|
+ // 当只有view的时候
|
|
531
|
+ if len(customAdData.TargetAddition) == 1 {
|
|
532
|
+ for _, url := range customAdData.TargetAddition[0].Urls {
|
|
533
|
+ rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
|
|
534
|
+ }
|
|
535
|
+ } else {
|
|
536
|
+ // 当自由订单有view和click的时候
|
|
537
|
+ for _, url := range customAdData.TargetAddition[0].Urls {
|
|
538
|
+ rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
|
|
539
|
+ }
|
|
540
|
+
|
|
541
|
+ for _, url := range customAdData.TargetAddition[1].Urls {
|
|
542
|
+ rspTargetAddition[1].Urls = append(rspTargetAddition[1].Urls, url)
|
|
543
|
+ }
|
|
544
|
+ rspTargetAddition[1].Type = "CLICK"
|
|
545
|
+ }
|
|
546
|
+ lastAdData.Target = customAdData.Target
|
|
547
|
+ lastAdData.JsOrderId = customAdData.JsOrderId
|
|
548
|
+ lastAdData.TargetAddition = rspTargetAddition
|
|
549
|
+ lastAdData.DpReport = response.DpReport
|
|
550
|
+ lastAdData.Dp = response.Dp
|
|
551
|
+
|
|
552
|
+ adDataBytes, err := json.Marshal(lastAdData)
|
|
553
|
+ if err != nil {
|
|
554
|
+ fmt.Sprintf("marshal addata failed: %s\n", err)
|
|
555
|
+ }
|
|
556
|
+ grayLogData := struct {
|
|
557
|
+ ShortMessage string `json:"short_message"`
|
|
558
|
+ ResponseVast string `json:"response_vast"`
|
|
559
|
+ }{
|
|
560
|
+ ShortMessage: "third_mix_xiaomi",
|
|
561
|
+ ResponseVast: string(adDataBytes),
|
514
|
562
|
}
|
515
|
563
|
|
516
|
564
|
graylog.Log(grayLogData)
|
|
565
|
+ customAdData = &lastAdData
|
|
566
|
+ }
|
|
567
|
+ if customAdData != nil {
|
|
568
|
+ device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_HAVE", cityCode) // 广告获取成功
|
|
569
|
+ if dspInfo.ReqSource == "zhiku" {
|
|
570
|
+ response.Result = 0
|
|
571
|
+ response.Msg = "ok"
|
|
572
|
+
|
|
573
|
+ jsonBytes, err := json.Marshal(customAdData)
|
|
574
|
+ if err != nil {
|
|
575
|
+ c.String(404, err.Error())
|
|
576
|
+ return
|
|
577
|
+ }
|
|
578
|
+ encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(SECERET_KEY))
|
|
579
|
+ response.AdsResult = encryptData
|
|
580
|
+ //self.report_graylog(json.dumps(extra_item))
|
|
581
|
+ rspBytes, err := json.Marshal(response)
|
|
582
|
+ if err != nil {
|
|
583
|
+ c.String(404, err.Error())
|
|
584
|
+ return
|
|
585
|
+ }
|
|
586
|
+ c.String(200, string(rspBytes))
|
|
587
|
+ return
|
|
588
|
+ } else {
|
|
589
|
+ customAdData.Result = 0
|
|
590
|
+ customAdData.Msg = "ok"
|
|
591
|
+ //self.report_graylog(json_response)
|
|
592
|
+ rspBytes, err := json.Marshal(customAdData)
|
|
593
|
+ if err != nil {
|
|
594
|
+ c.String(404, err.Error())
|
|
595
|
+ return
|
|
596
|
+ }
|
|
597
|
+ c.String(200, string(rspBytes))
|
|
598
|
+ return
|
|
599
|
+ }
|
517
|
600
|
}
|
518
|
|
- //if short_message=="ads_tt_thirds":
|
519
|
|
- //from thirds import thirds_mix_xiaomi
|
520
|
|
- //extra_item = thirds_mix_xiaomi.mix_last_infos(extra_item,response)
|
521
|
|
- //if (extra_item) != None:
|
522
|
|
- //redis_device.set_ads_tag_log(advertiser,req_source,'ADS_ZIYOU_HAVE',dsp_city_code) # 广告获取成功
|
523
|
|
- //if req_source in ['zhiku']:
|
524
|
|
- //response['result']=0
|
525
|
|
- //response['msg']='ok'
|
526
|
|
- //response['ads_result']= self.prpcrypt_tools.to_encrypt_content(json.dumps(extra_item))
|
527
|
|
- //self.report_graylog(json.dumps(extra_item))
|
528
|
|
- //self.write(json.dumps(response))
|
529
|
|
- //self.finish()
|
530
|
|
- //return
|
531
|
|
- //else:
|
532
|
|
- //extra_item['result']=0
|
533
|
|
- //extra_item['msg']="ok"
|
534
|
|
- //json_response = json.dumps(extra_item)
|
535
|
|
- //self.report_graylog(json_response)
|
536
|
|
- //self.write(json_response)
|
537
|
|
- //self.finish()
|
538
|
|
- //return
|
539
|
601
|
}
|
540
|
602
|
}
|
541
|
|
- //redis_tools.set_ads_real_request_num(advertiser)
|
542
|
|
- //json_response = json.dumps(response)
|
543
|
|
- //try:
|
544
|
|
- //if new_ads_flag==0:
|
545
|
|
- //self.report_graylog(json_response)
|
546
|
|
- //redis_device.set_ads_tag_log(advertiser,req_source,'DS_REQ',dsp_city_code) # 所有请求
|
547
|
|
- //except:
|
548
|
|
- //pass
|
549
|
|
- //self.write(json_response)
|
550
|
|
- //self.finish()
|
551
|
|
-
|
552
|
|
- c.String(200, "hehe")
|
|
603
|
+ redis_data.SetAdsRealRequestNum(advertiser)
|
|
604
|
+ rspBytes, err := json.Marshal(response)
|
|
605
|
+ if err != nil {
|
|
606
|
+ c.String(404, err.Error())
|
|
607
|
+ return
|
|
608
|
+ }
|
|
609
|
+
|
|
610
|
+ if request.NewAdsFlag == 0 {
|
|
611
|
+ //self.report_graylog(json_response)
|
|
612
|
+ }
|
|
613
|
+ device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
|
|
614
|
+ c.String(200, string(rspBytes))
|
553
|
615
|
}
|