|
@@ -17,60 +17,60 @@ import (
|
17
|
17
|
)
|
18
|
18
|
|
19
|
19
|
type XiaomiAdData struct {
|
20
|
|
-DetailURL string `json:"detail_url"`
|
21
|
|
-DisplayType struct {
|
22
|
|
-Delay int64 `json:"delay"`
|
23
|
|
-Name string `json:"name"`
|
24
|
|
-RowCount int64 `json:"row_count"`
|
25
|
|
-} `json:"display_type"`
|
26
|
|
-Duration int64 `json:"duration"`
|
27
|
|
-EmcType string `json:"emc_type"`
|
28
|
|
-ID string `json:"id"`
|
29
|
|
-ImageURL string `json:"image_url"`
|
30
|
|
-Proportion string `json:"proportion"`
|
31
|
|
-Settings struct {
|
32
|
|
-ClickType string `json:"click_type"`
|
33
|
|
-HideCloseAt int64 `json:"hide_close_at"`
|
34
|
|
-LogTime string `json:"log_time"`
|
35
|
|
-ShowCloseAt int64 `json:"show_close_at"`
|
36
|
|
-} `json:"settings"`
|
37
|
|
-SkipTime int64 `json:"skip_time"`
|
38
|
|
-TagID string `json:"tag_id"`
|
39
|
|
-Target string `json:"target"`
|
40
|
|
-TargetAddition []string `json:"target_addition"`
|
41
|
|
-TargetAddition1 string `json:"target_addition1"`
|
42
|
|
-Title string `json:"title"`
|
43
|
|
-VideoURL string `json:"video_url"`
|
|
20
|
+ DetailURL string `json:"detail_url"`
|
|
21
|
+ DisplayType struct {
|
|
22
|
+ Delay int64 `json:"delay"`
|
|
23
|
+ Name string `json:"name"`
|
|
24
|
+ RowCount int64 `json:"row_count"`
|
|
25
|
+ } `json:"display_type"`
|
|
26
|
+ Duration int64 `json:"duration"`
|
|
27
|
+ EmcType string `json:"emc_type"`
|
|
28
|
+ ID string `json:"id"`
|
|
29
|
+ ImageURL string `json:"image_url"`
|
|
30
|
+ Proportion string `json:"proportion"`
|
|
31
|
+ Settings struct {
|
|
32
|
+ ClickType string `json:"click_type"`
|
|
33
|
+ HideCloseAt int64 `json:"hide_close_at"`
|
|
34
|
+ LogTime string `json:"log_time"`
|
|
35
|
+ ShowCloseAt int64 `json:"show_close_at"`
|
|
36
|
+ } `json:"settings"`
|
|
37
|
+ SkipTime int64 `json:"skip_time"`
|
|
38
|
+ TagID string `json:"tag_id"`
|
|
39
|
+ Target string `json:"target"`
|
|
40
|
+ TargetAddition []string `json:"target_addition"`
|
|
41
|
+ TargetAddition1 string `json:"target_addition1"`
|
|
42
|
+ Title string `json:"title"`
|
|
43
|
+ VideoURL string `json:"video_url"`
|
44
|
44
|
}
|
45
|
45
|
|
46
|
46
|
type XiaoMiAdInfoRsp struct {
|
47
|
|
- Data []XiaomiAdData `json:"data"`
|
48
|
|
- Msg string `json:"msg"`
|
49
|
|
- Result int64 `json:"result"`
|
|
47
|
+ Data []XiaomiAdData `json:"data"`
|
|
48
|
+ Msg string `json:"msg"`
|
|
49
|
+ Result int64 `json:"result"`
|
50
|
50
|
}
|
51
|
51
|
|
52
|
52
|
type AdAction struct {
|
53
|
|
- Type string `json:"type"`
|
54
|
|
- Duration int `json:"duration"`
|
55
|
|
- Urls []string `json:"urls"`
|
|
53
|
+ Type string `json:"type"`
|
|
54
|
+ Duration int `json:"duration"`
|
|
55
|
+ Urls []string `json:"urls"`
|
56
|
56
|
}
|
57
|
57
|
|
58
|
58
|
type AdInfo struct {
|
59
|
|
- AdActions []AdAction `json:"ads_infos"`
|
60
|
|
- PercentBegin int`json:"percent_begin"`
|
61
|
|
- PercentEnd int`json:"percent_end"`
|
|
59
|
+ AdActions []AdAction `json:"ads_infos"`
|
|
60
|
+ PercentBegin int `json:"percent_begin"`
|
|
61
|
+ PercentEnd int `json:"percent_end"`
|
62
|
62
|
}
|
63
|
63
|
|
64
|
64
|
type AdData struct {
|
65
|
65
|
TargetAddition []AdAction `json:"target_addition"`
|
66
|
|
- Target string
|
67
|
|
- ImageUrl string`json:"image_url"`
|
68
|
|
- Duration int64
|
69
|
|
- VideoUrl string`json:"video_url"`
|
70
|
|
- JsOrderId string `json:"js_order_id"`
|
71
|
|
- UserAgent string `json:"user_agent"`
|
72
|
|
- DpReport string `json:"dp_report"`
|
73
|
|
- Dp string `json:"dp"`
|
|
66
|
+ Target string
|
|
67
|
+ ImageUrl string `json:"image_url"`
|
|
68
|
+ Duration int64
|
|
69
|
+ VideoUrl string `json:"video_url"`
|
|
70
|
+ JsOrderId string `json:"js_order_id"`
|
|
71
|
+ UserAgent string `json:"user_agent"`
|
|
72
|
+ DpReport string `json:"dp_report"`
|
|
73
|
+ Dp string `json:"dp"`
|
74
|
74
|
}
|
75
|
75
|
|
76
|
76
|
func getAdsReqUrl(dsp *utils.DspParam) string {
|
|
@@ -80,7 +80,7 @@ func getAdsReqUrl(dsp *utils.DspParam) string {
|
80
|
80
|
|
81
|
81
|
reqUrl = reqUrl + "_emcp=pre_play"
|
82
|
82
|
|
83
|
|
- reqUrl = reqUrl + "&_devid="+ dsp.RealMd5Imei
|
|
83
|
+ reqUrl = reqUrl + "&_devid=" + dsp.RealMd5Imei
|
84
|
84
|
|
85
|
85
|
reqUrl = reqUrl + "&ref=" + ref
|
86
|
86
|
|
|
@@ -96,34 +96,35 @@ func getAdsReqUrl(dsp *utils.DspParam) string {
|
96
|
96
|
reqUrl = reqUrl + fmt.Sprintf("&_phonetype=%d", dsp.SendPhoneType)
|
97
|
97
|
return reqUrl
|
98
|
98
|
}
|
|
99
|
+
|
99
|
100
|
|
100
|
101
|
func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, []XiaomiAdData, map[string]int, int, error) {
|
101
|
102
|
reqUrl := getAdsReqUrl(dsp)
|
102
|
103
|
|
103
|
104
|
if dsp.SendPhoneType == 0 {
|
104
|
105
|
device.SetAdsTagLog("xiaomi", dsp.ReqSource, "ADS_XIAOMI", dsp.DspCityCode)
|
105
|
|
- } else if dsp.SendPhoneType == 1{
|
|
106
|
+ } else if dsp.SendPhoneType == 1 {
|
106
|
107
|
device.SetAdsTagLog("xiaomi", dsp.ReqSource, "ADS_XIAOMI_1", dsp.DspCityCode)
|
107
|
108
|
}
|
108
|
109
|
|
109
|
110
|
client := &http.Client{}
|
110
|
111
|
fmt.Printf("req url: %s\n", reqUrl)
|
111
|
|
- req, err := http.NewRequest("GET", reqUrl, nil)
|
|
112
|
+ req, err := http.NewRequest("GET", reqUrl, nil)
|
112
|
113
|
if err != nil {
|
113
|
114
|
return nil, nil, nil, 0, err
|
114
|
115
|
}
|
115
|
116
|
|
116
|
|
- req.Header.Set(",authority","m.video.xiaomi.com")
|
117
|
|
- req.Header.Set(",method","GET")
|
|
117
|
+ req.Header.Set(",authority", "m.video.xiaomi.com")
|
|
118
|
+ req.Header.Set(",method", "GET")
|
118
|
119
|
req.Header.Set(",path", reqUrl[26:])
|
119
|
|
- req.Header.Set(",scheme","https")
|
120
|
|
- req.Header.Set("content-type","application/json")
|
121
|
|
- req.Header.Set("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
|
122
|
|
- req.Header.Set("accept-encoding","gzip, deflate, br")
|
123
|
|
- req.Header.Set("accept-language","zh-CN,zh;q=0.9")
|
124
|
|
- req.Header.Set("cache-control","max-age=0")
|
125
|
|
- req.Header.Set("upgrade-insecure-requests","1")
|
126
|
|
- req.Header.Set("user-agent",dsp.Ua)
|
|
120
|
+ req.Header.Set(",scheme", "https")
|
|
121
|
+ req.Header.Set("content-type", "application/json")
|
|
122
|
+ req.Header.Set("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
|
|
123
|
+ req.Header.Set("accept-encoding", "gzip, deflate, br")
|
|
124
|
+ req.Header.Set("accept-language", "zh-CN,zh;q=0.9")
|
|
125
|
+ req.Header.Set("cache-control", "max-age=0")
|
|
126
|
+ req.Header.Set("upgrade-insecure-requests", "1")
|
|
127
|
+ req.Header.Set("user-agent", dsp.Ua)
|
127
|
128
|
|
128
|
129
|
resp, err := client.Do(req)
|
129
|
130
|
if err != nil {
|
|
@@ -142,8 +143,8 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, []XiaomiAdDat
|
142
|
143
|
}
|
143
|
144
|
|
144
|
145
|
adsDataNum := len(rsp.Data)
|
145
|
|
- xiaomiResponseAction := map[string]int {
|
146
|
|
- "xiaomi_view":0, "xiaomi_click":0, "xiaomi_close":0, "xiaomi_video_finish":0, "xiaomi_video_timer":0,
|
|
146
|
+ xiaomiResponseAction := map[string]int{
|
|
147
|
+ "xiaomi_view": 0, "xiaomi_click": 0, "xiaomi_close": 0, "xiaomi_video_finish": 0, "xiaomi_video_timer": 0,
|
147
|
148
|
}
|
148
|
149
|
|
149
|
150
|
if rsp.Result != 1 {
|
|
@@ -196,20 +197,20 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, []XiaomiAdDat
|
196
|
197
|
|
197
|
198
|
if targetUrl != "" {
|
198
|
199
|
switch event {
|
199
|
|
- case "VIEW":
|
200
|
|
- showUrls = append(showUrls, targetUrl)
|
201
|
|
- xiaomiResponseAction["xiaomi_view"] = 1
|
|
200
|
+ case "VIEW":
|
|
201
|
+ showUrls = append(showUrls, targetUrl)
|
|
202
|
+ xiaomiResponseAction["xiaomi_view"] = 1
|
202
|
203
|
case "CLICK":
|
203
|
|
- clickUrls = append(clickUrls, targetUrl)
|
204
|
|
- xiaomiResponseAction["xiaomi_click"] = 1
|
|
204
|
+ clickUrls = append(clickUrls, targetUrl)
|
|
205
|
+ xiaomiResponseAction["xiaomi_click"] = 1
|
205
|
206
|
case "CLOSE":
|
206
|
|
- closeUrls = append(closeUrls, targetUrl)
|
207
|
|
- xiaomiResponseAction["xiaomi_close"] = 1
|
|
207
|
+ closeUrls = append(closeUrls, targetUrl)
|
|
208
|
+ xiaomiResponseAction["xiaomi_close"] = 1
|
208
|
209
|
case "VIDEO_FINISH":
|
209
|
|
- videoFinishUrls = append(videoFinishUrls, targetUrl)
|
210
|
|
- xiaomiResponseAction["xiaomi_video_finish"] = 1
|
|
210
|
+ videoFinishUrls = append(videoFinishUrls, targetUrl)
|
|
211
|
+ xiaomiResponseAction["xiaomi_video_finish"] = 1
|
211
|
212
|
case "VIDEO_TIMER":
|
212
|
|
- videoTimerUrls = append(videoTimerUrls, targetUrl)
|
|
213
|
+ videoTimerUrls = append(videoTimerUrls, targetUrl)
|
213
|
214
|
}
|
214
|
215
|
}
|
215
|
216
|
|
|
@@ -238,7 +239,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, []XiaomiAdDat
|
238
|
239
|
gotoUrls = append(gotoUrls, targetUrl)
|
239
|
240
|
}
|
240
|
241
|
}
|
241
|
|
- if dsp.ReqSource == "mh" {
|
|
242
|
+ if dsp.ReqSource == "mh" {
|
242
|
243
|
closeUrls = videoFinishUrls
|
243
|
244
|
}
|
244
|
245
|
|
|
@@ -256,7 +257,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, []XiaomiAdDat
|
256
|
257
|
|
257
|
258
|
fmt.Printf("%+v, addata_num: %d\n", xiaomiResponseAction, adsDataNum)
|
258
|
259
|
if len(gotoUrls) == 0 {
|
259
|
|
- return nil, rsp.Data, xiaomiResponseAction, adsDataNum, nil
|
|
260
|
+ return nil, rsp.Data, xiaomiResponseAction, adsDataNum, nil
|
260
|
261
|
}
|
261
|
262
|
|
262
|
263
|
fmt.Printf("goto urls: %+v\nshow urls: %+v\nclick_urls: %+v\nclose urls: %+v\nvideo finish urls: %+v\nimagurls: %+v\nvideo urls:%+v\n",
|
|
@@ -271,7 +272,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, []XiaomiAdDat
|
271
|
272
|
|
272
|
273
|
if dsp.SendPhoneType == 0 {
|
273
|
274
|
redis_data.SetAdsRequestNum(advertiser, 0)
|
274
|
|
- } else if dsp.SendPhoneType == 1{
|
|
275
|
+ } else if dsp.SendPhoneType == 1 {
|
275
|
276
|
redis_data.SetAdsRequestNum(advertiser, 1)
|
276
|
277
|
}
|
277
|
278
|
return adsData, rsp.Data, xiaomiResponseAction, adsDataNum, nil
|
|
@@ -309,7 +310,7 @@ func getCombinationActionsConf(advertiser string) []adslib.CombinationActionsCon
|
309
|
310
|
|
310
|
311
|
func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []string, showUrls []string,
|
311
|
312
|
clickUrls []string, closeUrls []string, videoFinishUrls []string,
|
312
|
|
- videoTimerUrls []string, imageUrls []string, videoUrls []string) (*AdData, error){
|
|
313
|
+ videoTimerUrls []string, imageUrls []string, videoUrls []string) (*AdData, error) {
|
313
|
314
|
|
314
|
315
|
|
315
|
316
|
actions := getActionsConf(advertiser)
|
|
@@ -317,7 +318,7 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
|
317
|
318
|
return nil, nil
|
318
|
319
|
}
|
319
|
320
|
|
320
|
|
- clickChannelFlag, err := redis_data.GetChannelFlag(dsp.ReqSource,"ads_click")
|
|
321
|
+ clickChannelFlag, err := redis_data.GetChannelFlag(dsp.ReqSource, "ads_click")
|
321
|
322
|
if err != nil {
|
322
|
323
|
return nil, err
|
323
|
324
|
}
|
|
@@ -333,7 +334,7 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
|
333
|
334
|
lastInfos := make([]AdInfo, 0, 50)
|
334
|
335
|
combinationActions := getCombinationActionsConf(advertiser)
|
335
|
336
|
for _, combAction := range combinationActions {
|
336
|
|
- adActionDatas := make([]AdAction, 0 ,20)
|
|
337
|
+ adActionDatas := make([]AdAction, 0, 20)
|
337
|
338
|
percentBegin := combAction.PercentBegin
|
338
|
339
|
percentEnd := combAction.PercentEnd
|
339
|
340
|
actionGroup := combAction.GroupValue
|
|
@@ -360,18 +361,18 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
|
360
|
361
|
}
|
361
|
362
|
|
362
|
363
|
|
363
|
|
- if action =="CLICK" && dsp.RealReqSource=="bom" && dsp.SupClickFlag==0{
|
|
364
|
+ if action == "CLICK" && dsp.RealReqSource == "bom" && dsp.SupClickFlag == 0 {
|
364
|
365
|
continue
|
365
|
366
|
}
|
366
|
367
|
|
367
|
|
- if action=="VIEW" && dsp.RealReqSource=="bom" && dsp.SupShowFlag==0 {
|
|
368
|
+ if action == "VIEW" && dsp.RealReqSource == "bom" && dsp.SupShowFlag == 0 {
|
368
|
369
|
continue
|
369
|
370
|
}
|
370
|
|
- if action=="CLICK" && !needClick {
|
|
371
|
+ if action == "CLICK" && !needClick {
|
371
|
372
|
continue
|
372
|
373
|
}
|
373
|
374
|
|
374
|
|
- if len(urls)==0 && action=="VIDEO_TIMER" {
|
|
375
|
+ if len(urls) == 0 && action == "VIDEO_TIMER" {
|
375
|
376
|
continue
|
376
|
377
|
}
|
377
|
378
|
|
|
@@ -414,7 +415,7 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
|
414
|
415
|
videoUrl = videoUrls[0]
|
415
|
416
|
}
|
416
|
417
|
|
417
|
|
- randAdData := make([]AdAction,0, 50)
|
|
418
|
+ randAdData := make([]AdAction, 0, 50)
|
418
|
419
|
if len(lastInfos) != 0 {
|
419
|
420
|
randIdx := rand.Intn(len(lastInfos))
|
420
|
421
|
randAdData = lastInfos[randIdx].AdActions
|
|
@@ -434,7 +435,7 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
|
434
|
435
|
|
435
|
436
|
|
436
|
437
|
videoTimerUrls = make([]string, 0, 100)
|
437
|
|
- if len(randAdData)>=3 {
|
|
438
|
+ if len(randAdData) >= 3 {
|
438
|
439
|
if randAdData[1].Type == "VIDEO_TIMER" {
|
439
|
440
|
videoTimerUrls = randAdData[1].Urls
|
440
|
441
|
}
|
|
@@ -446,20 +447,19 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
|
446
|
447
|
continue
|
447
|
448
|
}
|
448
|
449
|
|
449
|
|
-
|
450
|
450
|
if adData.Type == "VIDEO_TIMER" && len(videoTimerUrls) > 0 {
|
451
|
451
|
adData.Duration = int(dsp.AllDuration) - dsp.VideoTimeDuration
|
452
|
|
- } else if adData.Type == "VIDEO_TIMER" && len(videoTimerUrls) == 0{
|
|
452
|
+ } else if adData.Type == "VIDEO_TIMER" && len(videoTimerUrls) == 0 {
|
453
|
453
|
adData.Duration = dsp.VideoTimeDuration
|
454
|
454
|
} else if adData.Type == "VIEW" {
|
455
|
|
- if len(videoTimerUrls) > 0 {
|
|
455
|
+ if len(videoTimerUrls) > 0 {
|
456
|
456
|
adData.Duration = dsp.VideoTimeDuration
|
457
|
457
|
} else {
|
458
|
458
|
adData.Duration = int(dsp.AllDuration)
|
459
|
459
|
}
|
460
|
460
|
}
|
461
|
461
|
|
462
|
|
- if adData.Type != "VIEW"{
|
|
462
|
+ if adData.Type != "VIEW" {
|
463
|
463
|
redis_data.SetDistributeActionNum(advertiser, adData.Type, dsp.SendPhoneType)
|
464
|
464
|
}
|
465
|
465
|
|
|
@@ -504,7 +504,7 @@ func genAdsAction(urls []string, advertiser string,
|
504
|
504
|
}
|
505
|
505
|
allShowNum, err := redis_data.GetAdsFeedbackNum(advertiser, action, dsp.SendPhoneType)
|
506
|
506
|
if err != nil {
|
507
|
|
- return nil ,err
|
|
507
|
+ return nil, err
|
508
|
508
|
}
|
509
|
509
|
|
510
|
510
|
flowControlConf := redis_data.GetFlowPercentDuration(advertiser, action)
|
|
@@ -517,7 +517,7 @@ func genAdsAction(urls []string, advertiser string,
|
517
|
517
|
duration = flowControlConf.Duration
|
518
|
518
|
}
|
519
|
519
|
|
520
|
|
- lastUrls := make([]string, 0,20)
|
|
520
|
+ lastUrls := make([]string, 0, 20)
|
521
|
521
|
if !needControl || allSendNum == 0 || int(
|
522
|
522
|
float32(allShowNum)/float32(allSendNum)*100) < flowPercent {
|
523
|
523
|
reportUrl := getReportUrl(action, advertiser, dsp)
|