jiantaoli před 4 roky
rodič
revize
50f7244c0c

+ 1 - 0
.idea/dictionaries/jiantaoli.xml

@@ -19,6 +19,7 @@
19 19
       <w>videofinish</w>
20 20
       <w>videoopen</w>
21 21
       <w>videotimer</w>
22
+      <w>xiafa</w>
22 23
       <w>zhiku</w>
23 24
       <w>ziyou</w>
24 25
     </words>

+ 11 - 18
ads_handler.go

@@ -33,11 +33,8 @@ func adsHandler(c *gin.Context) {
33 33
 
34 34
 	request := adslib.Request{}
35 35
 	request.Parse(c)
36
-	//uaClientOrigin := utils.GetArgument(c, "ua","")
37
-	//originMac := utils.GetArgument(c, "mac","")
38
-	//clientImei := request.Imei
39 36
 
40
-	fmt.Printf("%+v", request)
37
+	fmt.Printf("%+v\n", request)
41 38
 	advertiser := "xiaomi"
42 39
 	uaClient := request.UaClient
43 40
 	// 获取ua
@@ -51,7 +48,7 @@ func adsHandler(c *gin.Context) {
51 48
 	// 获取ip
52 49
 	checkReqSourceFlag, err := ads_checker.CheckReqSource(request.ReqSource)
53 50
 	if err != nil {
54
-		c.String(404, "check req source failed")
51
+		c.String(404, "check req source failed: %s", err)
55 52
 		return
56 53
 	}
57 54
 
@@ -76,9 +73,10 @@ func adsHandler(c *gin.Context) {
76 73
 
77 74
 	ipInfo, err := ip2region.Ip2Region(ip)
78 75
 	if err != nil {
79
-		c.String(404, "ip 2 region failed")
76
+		c.String(404, "ip 2 region failed: %s", err)
80 77
 		return
81 78
 	}
79
+	fmt.Printf("ip 2 region: %s, %+v\n", ip, ipInfo)
82 80
 
83 81
 	// 上報
84 82
 	if request.NewAdsFlag == 1 {
@@ -115,7 +113,7 @@ func adsHandler(c *gin.Context) {
115 113
 
116 114
 	cityCode, err := city.GetCityCode(ipInfo.City)
117 115
 	if err != nil {
118
-		c.String(404, "get city code failed")
116
+		c.String(404, "get city code failed: %s", err)
119 117
 		return
120 118
 	}
121 119
 
@@ -422,7 +420,7 @@ func adsHandler(c *gin.Context) {
422 420
 		if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
423 421
 			adData, err = addata.CombineOrderBy(adData, advertiser, &dspInfo)
424 422
 			if err != nil {
425
-				c.String(404, err.Error())
423
+				c.String(404, "combine order failed: %s", err.Error())
426 424
 				return
427 425
 			}
428 426
 		}
@@ -441,7 +439,7 @@ func adsHandler(c *gin.Context) {
441 439
 		} else {
442 440
 			jsonBytes, err := json.Marshal(*adData)
443 441
 			if err != nil {
444
-				c.String(404, err.Error())
442
+				c.String(404, "marshal AdData failed: %s", err.Error())
445 443
 				return
446 444
 			}
447 445
 			encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
@@ -458,14 +456,9 @@ func adsHandler(c *gin.Context) {
458 456
 		// 增加打底广告
459 457
 		if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needControl && !isBlackImei {
460 458
 			shortMessage := "kong"
461
-			if err != nil {
462
-				c.String(404, err.Error())
463
-				return
464
-			}
465
-
466 459
 			customAdData, err := addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 0, xiaomiResponseFlag)
467 460
 			if err != nil {
468
-				c.String(404, err.Error())
461
+				c.String(404, "get custom ads info failed: %s", err.Error())
469 462
 				return
470 463
 			}
471 464
 
@@ -473,7 +466,7 @@ func adsHandler(c *gin.Context) {
473 466
 			if customAdData == nil {
474 467
 				customAdData, err = addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 1, xiaomiResponseFlag)
475 468
 				if err != nil {
476
-					c.String(404, err.Error())
469
+					c.String(404, "get fix custom ads info failed: %s", err.Error())
477 470
 					return
478 471
 				}
479 472
 			}
@@ -559,7 +552,7 @@ func adsHandler(c *gin.Context) {
559 552
 
560 553
 					jsonBytes, err := json.Marshal(customAdData)
561 554
 					if err != nil {
562
-						c.String(404, err.Error())
555
+						c.String(404, "marsha custom addata failed: %s", err.Error())
563 556
 						return
564 557
 					}
565 558
 					encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
@@ -567,7 +560,7 @@ func adsHandler(c *gin.Context) {
567 560
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
568 561
 					rspBytes, err := json.Marshal(response)
569 562
 					if err != nil {
570
-						c.String(404, err.Error())
563
+						c.String(404, "marshal Response failed: %s", err.Error())
571 564
 						return
572 565
 					}
573 566
 					c.String(200, string(rspBytes))

+ 2 - 2
adslib/addata/xiaomi_test.go

@@ -93,7 +93,7 @@ func TestGetAdsInfos(t *testing.T) {
93 93
 	adslib.GetConf()
94 94
 
95 95
 	fmt.Printf("dsp: %+v", dsp)
96
-	addata, d, d1, num, err := GetAdsInfos(&dsp, advertiser)
97
-	fmt.Printf("%+v %+v %+v %+v %s", addata, d, d1, num, err)
96
+	addata, err := GetAdsInfos(&dsp, advertiser)
97
+	fmt.Printf("%+v %s", addata, err)
98 98
 }
99 99
 

+ 1 - 1
adslib/device/device.go

@@ -29,7 +29,7 @@ func setTagLog(key string) {
29 29
 	defer conn.Close()
30 30
 
31 31
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
32
-	k := fmt.Sprint("{%s}___{%d}",key, dateInt)
32
+	k := fmt.Sprintf("{%s}___{%d}",key, dateInt)
33 33
 	conn.Do("INCR", k)
34 34
 	conn.Do("SADD", "fresh_all_keys", k)
35 35
 }

+ 5 - 3
adslib/ip2region/ip2region.go

@@ -6,9 +6,11 @@ import (
6 6
 )
7 7
 
8 8
 func Ip2Region(ip string) (*ip2region.IpInfo, error) {
9
-	fmt.Println("err")
10
-	region, err := ip2region.New("./ip2region.db")
11
-	defer region.Close()
9
+	region, err := ip2region.New("./conf/ip2region.db")
10
+	if region != nil {
11
+		defer region.Close()
12
+	}
13
+
12 14
 	if err != nil {
13 15
 		fmt.Println(err)
14 16
 		return nil, err

+ 23 - 0
adslib/ip2region/ip2region_test.go

@@ -0,0 +1,23 @@
1
+package ip2region
2
+
3
+import (
4
+	"fmt"
5
+	"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
6
+	"testing"
7
+)
8
+
9
+var r *ip2region.Ip2Region
10
+func init() {
11
+	var err error
12
+	r, err = ip2region.New("../../conf/ip2region.db")
13
+	if err != nil {
14
+		fmt.Printf("%s", err)
15
+	}
16
+}
17
+
18
+func BenchmarkIp2Region(b *testing.B) {
19
+	ip := "36.161.36.225"
20
+	for i := 0; i < b.N; i++ {
21
+		r.MemorySearch(ip)
22
+	}
23
+}

+ 3 - 3
adslib/request.go

@@ -19,9 +19,9 @@ type Request struct {
19 19
 	Model       string
20 20
 	Brand       string
21 21
 	ScreenSize  string `json:"screen_size"`
22
-	NetworkType int `json:"network_type"`
22
+	NetworkType int `json:"network_type,string"`
23 23
 	Androidid   string `json:"android_id"`
24
-	Platform    int `json:"platform"`
24
+	Platform    int `json:"platform,string"`
25 25
 	OsVersion   string `json:"os_version"`
26 26
 	UaClient    string `json:"ua"`
27 27
 	ReqSource   string `json:"req_source"`
@@ -77,7 +77,7 @@ func (self *Request) Parse(c *gin.Context) {
77 77
 		err = json.Unmarshal([]byte(contentDecode), self)
78 78
 		if err != nil {
79 79
 			fmt.Println(err)
80
-			c.String(404, "decode json body failed")
80
+			c.String(404, "decode json body failed: %s", err)
81 81
 			return
82 82
 		}
83 83
 

adslib/ip2region/ip2region.db → conf/ip2region.db


Diff nebyl zobrazen, protože je příliš veliký
+ 44 - 0
main_test.go