jiantaoli 4 anni fa
parent
commit
39fb5699dd
1 ha cambiato i file con 77 aggiunte e 51 eliminazioni
  1. 77 51
      adslib/addata/custom.go

+ 77 - 51
adslib/addata/custom.go

@@ -3,8 +3,10 @@ package addata
3 3
 import (
4 4
 	"fmt"
5 5
 	"math/rand"
6
+	"miads/adslib"
6 7
 	"miads/adslib/redis_data"
7 8
 	"miads/adslib/utils"
9
+	"net/url"
8 10
 	"strconv"
9 11
 	"strings"
10 12
 	"time"
@@ -18,7 +20,7 @@ type CustomAdData struct {
18 20
 	OrderName      string        `json:"order_name"`
19 21
 	Result         int64         `json:"result"`
20 22
 	Target         string        `json:"target"`
21
-	TargetAddition []interface{} `json:"target_addition"`
23
+	TargetAddition []AdAction `json:"target_addition"`
22 24
 	UserAgent      string        `json:"user_agent"`
23 25
 	VideoURL       string        `json:"video_url"`
24 26
 }
@@ -157,12 +159,9 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
157 159
 		return nil
158 160
 	}
159 161
 
160
-	r = rand.Intn( 100)
161 162
 	if xiaomiHasFlag == 1 {
162 163
 		if strings.Index(order.Title, "_ios") > 0 {
163 164
 			return nil
164
-		} else {
165
-			r = rand.Intn(50)
166 165
 		}
167 166
 	}
168 167
 
@@ -270,55 +269,59 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
270 269
 				clickUrl = strings.ReplaceAll(clickUrl, "__OS__", "0")
271 270
 				targetUrl = strings.ReplaceAll(targetUrl, "__OS__", "0")
272 271
 			}
273
-			if ads_item.get('imei_replace_flag', 0) == 1:
274
-			show_url = show_url.replace('__IMEI__', dsp.real_md5_imei)
275
-			click_url = click_url.replace('__IMEI__', dsp.real_md5_imei)
276
-			target = target.replace('__IMEI__', dsp.real_md5_imei)
277
-
278
-			if order_name.find("__OS__") > 0:
279
-			show_url = show_url.replace('__OS__', '0')
280
-			click_url = click_url.replace('__OS__', '0')
281
-			target = target.replace('__OS__', '0')
272
+		} else {
273
+			r := rand.Intn(100)
274
+			if r < 40 && xiaomiHasFlag == 0 {
275
+				iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
276
+				if err != nil {
277
+					return err
278
+				}
279
+				if iosUa != "" {
280
+					data.UserAgent = iosUa
281
+				}
282
+				if order.ImeiReplaceFlag == 1 && iosImei != "" {
283
+					showUrl = strings.ReplaceAll(showUrl, "__IDFA__", iosImei)
284
+					clickUrl = strings.ReplaceAll(clickUrl, "__IDFA__", iosImei)
285
+					targetUrl = strings.ReplaceAll(targetUrl, "__IDFA__", iosImei)
286
+				}
287
+
288
+				if strings.Index(order.Title, "__OS__") != -1 {
289
+					showUrl = strings.ReplaceAll(showUrl, "__OS__", "1")
290
+					clickUrl = strings.ReplaceAll(clickUrl, "__OS__", "1")
291
+					targetUrl = strings.ReplaceAll(targetUrl, "__OS__", "1")
292
+				}
293
+		} else {
294
+				// 判断是否需要替换imei
295
+				if order.ImeiReplaceFlag == 1 {
296
+					showUrl = strings.ReplaceAll(showUrl, "__IMEI__", dsp.RealMd5Imei)
297
+					clickUrl = strings.ReplaceAll(clickUrl, "__IMEI__", dsp.RealMd5Imei)
298
+					targetUrl = strings.ReplaceAll(targetUrl, "__IMEI__", dsp.RealMd5Imei)
299
+				}
300
+
301
+				if strings.Index(order.Title, "__OS__") != -1 {
302
+					showUrl = strings.ReplaceAll(showUrl, "__OS__", "0")
303
+					clickUrl = strings.ReplaceAll(clickUrl, "__OS__", "0")
304
+					targetUrl = strings.ReplaceAll(targetUrl, "__OS__", "0")
305
+				}
282 306
 		}
283 307
 
284
-		else:
285
-		if r < 40:
286
-		ios_imei, ios_ua = get_ios_ua_imei(dsp)
287
-		if ios_ua:
288
-		data['user_agent'] = ios_ua
289
-		if ads_item.get('imei_replace_flag', 0) == 1 and
290
-	ios_imei:
291
-		show_url = show_url.replace('__IDFA__', ios_imei)
292
-		click_url = click_url.replace('__IDFA__', ios_imei)
293
-		target = target.replace('__IDFA__', ios_imei)
294
-		if order_name.find("__OS__") > 0:
295
-		show_url = show_url.replace('__OS__', '1')
296
-		click_url = click_url.replace('__OS__', '1')
297
-		target = target.replace('__OS__', '1')
298
-		else:
299
-		if ads_item.get('imei_replace_flag', 0) == 1:
300
-		show_url = show_url.replace('__IMEI__', dsp.real_md5_imei)
301
-		click_url = click_url.replace('__IMEI__', dsp.real_md5_imei)
302
-		target = target.replace('__IMEI__', dsp.real_md5_imei)
303
-		if order_name.find("__OS__") > 0:
304
-		show_url = show_url.replace('__OS__', '0')
305
-		click_url = click_url.replace('__OS__', '0')
306
-		target = target.replace('__OS__', '0')
307
-
308
-		if order_name.find("__IP__") > 0:
309
-		show_url = show_url.replace('__IP__', dsp.ip)
310
-		click_url = click_url.replace('__IP__', dsp.ip)
311
-		target = target.replace('__IP__', dsp.ip)
312
-		if order_type == 0:
313
-		addi = get_monitor_url('VIEW', 5, order_name, req_source, show_url)
314
-		else:
315
-		addi = get_monitor_url('VIEW', 5, order_name, 'follow', show_url)
316
-
317
-		#addi['urls'].append(show_url)
318
-		data['target_addition'].append(addi)
308
+		if strings.Index(order.Title, "__IP__") != -1 {
309
+			showUrl = strings.ReplaceAll(showUrl, "__IP__", dsp.Ip)
310
+			clickUrl = strings.ReplaceAll(clickUrl, "__IP__", dsp.Ip)
311
+			targetUrl = strings.ReplaceAll(targetUrl, "__IP__", dsp.Ip)
312
+		}
313
+
314
+		var addi *AdAction
315
+		if orderType == 0 {
316
+			addi = genMonitorAction("VIEW", 5, order.Title, dsp.ReqSource, showUrl)
317
+		} else {
318
+			addi = genMonitorAction("VIEW", 5, order.Title, "follow", showUrl)
319
+		}
320
+
321
+		data.TargetAddition = append(data.TargetAddition, *addi)
319 322
 
320
-		r = random.randint(0, 1000)
321
-		c_rate = click_kpi * 1.0 / (ads_item['show_kpi']) * 1000
323
+		r = rand.Intn(0, 1000)
324
+		c_rate = float32(order.ClickKpi) / order * 1000
322 325
 		if r < c_rate:
323 326
 		#下发点击
324 327
 		addi = get_monitor_url('CLICK', 1, order_name, req_source, click_url)
@@ -336,4 +339,27 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
336 339
 	}
337 340
 	#获取当前已经放出去的次数
338 341
 	raise gen.Return((None, None))
339
-}~
342
+}
343
+
344
+
345
+func genMonitorAction(action string, title string, reqSource string, url string) *AdAction {
346
+		duration := 5
347
+		if action =="VIDEO_TIMER" {
348
+			duration = 7
349
+		}
350
+
351
+		urlArr := make([]string,0, 50)
352
+		if url != "" {
353
+			urlArr = strings.Split(url, "||")
354
+		}
355
+		adAction := AdAction{
356
+			Type:     action,
357
+			Duration: duration,
358
+			Urls:     urlArr,
359
+		}
360
+		urlHost := adslib.GetConf().HostIos
361
+		actionUrl := fmt.Sprintf("%s?action=%s&advertiser=%s&req_source=%s",
362
+			urlHost, action, reqSource, title)
363
+		adAction.Urls = append(adAction.Urls, actionUrl)
364
+		return &adAction
365
+}