jiantao 4 years ago
parent
commit
091ece388e
4 changed files with 27 additions and 13 deletions
  1. 5 0
      ads_handler.go
  2. 14 11
      adslib/addata/xiaomi.go
  3. 3 1
      adslib/device/device.go
  4. 5 1
      adslib/redis_data/redis_data.go

+ 5 - 0
ads_handler.go

@@ -170,6 +170,11 @@ func adsHandler(c *gin.Context) {
170
 		device.SetIpReqTime(ip, time.Now().Unix())
170
 		device.SetIpReqTime(ip, time.Now().Unix())
171
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
171
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
172
 	}
172
 	}
173
+
174
+	if adslib.GetConf().TestMode {
175
+		needControl = false
176
+	}
177
+
173
 	//### 检查是否是ip黑名单
178
 	//### 检查是否是ip黑名单
174
 	isIpBlack, err := ads_checker.CheckBlackIp(ip)
179
 	isIpBlack, err := ads_checker.CheckBlackIp(ip)
175
 	if err != nil {
180
 	if err != nil {

+ 14 - 11
adslib/addata/xiaomi.go

@@ -66,10 +66,10 @@ type AdData struct {
66
 	TargetAddition []AdAction `json:"target_addition,omitempty"`
66
 	TargetAddition []AdAction `json:"target_addition,omitempty"`
67
 	Target         string     `json:"target,omitempty"`
67
 	Target         string     `json:"target,omitempty"`
68
 	ImageUrl       string     `json:"image_url,omitempty"`
68
 	ImageUrl       string     `json:"image_url,omitempty"`
69
-	Duration       int64      `json:"duration"`
69
+	Duration       int64      `json:"duration,omitempty"`
70
 	VideoUrl       string     `json:"video_url,omitempty"`
70
 	VideoUrl       string     `json:"video_url,omitempty"`
71
 	JsOrderId      int64      `json:"js_order_id,omitempty"`
71
 	JsOrderId      int64      `json:"js_order_id,omitempty"`
72
-	UserAgent      string     `json:"user_agent, omitempty"`
72
+	UserAgent      string     `json:"user_agent,omitempty"`
73
 	DpReport       string     `json:"dp_report,omitempty"`
73
 	DpReport       string     `json:"dp_report,omitempty"`
74
 	Dp             string     `json:"dp,omitempty"`
74
 	Dp             string     `json:"dp,omitempty"`
75
 	OrderName      string     `json:"order_name,omitempty"`
75
 	OrderName      string     `json:"order_name,omitempty"`
@@ -112,19 +112,17 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
112
 	}
112
 	}
113
 
113
 
114
 	client := &http.Client{}
114
 	client := &http.Client{}
115
-	fmt.Printf("req url: %s\n", reqUrl)
115
+	log.WithField("request_id", dsp.RequestId).Infof("req url: %s", reqUrl)
116
 	req, err := http.NewRequest("GET", reqUrl, nil)
116
 	req, err := http.NewRequest("GET", reqUrl, nil)
117
 	if err != nil {
117
 	if err != nil {
118
 		return nil, err
118
 		return nil, err
119
 	}
119
 	}
120
 
120
 
121
-	req.Header.Set(",authority", "m.video.xiaomi.com")
122
-	req.Header.Set(",method", "GET")
123
-	req.Header.Set(",path", reqUrl[26:])
124
-	req.Header.Set(",scheme", "https")
121
+	req.Header.Set("authority", "m.video.xiaomi.com")
122
+	req.Header.Set("method", "GET")
123
+	req.Header.Set("path", reqUrl[26:])
124
+	req.Header.Set("scheme", "https")
125
 	req.Header.Set("content-type", "application/json")
125
 	req.Header.Set("content-type", "application/json")
126
-	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")
127
-	req.Header.Set("accept-encoding", "gzip, deflate, br")
128
 	req.Header.Set("accept-language", "zh-CN,zh;q=0.9")
126
 	req.Header.Set("accept-language", "zh-CN,zh;q=0.9")
129
 	req.Header.Set("cache-control", "max-age=0")
127
 	req.Header.Set("cache-control", "max-age=0")
130
 	req.Header.Set("upgrade-insecure-requests", "1")
128
 	req.Header.Set("upgrade-insecure-requests", "1")
@@ -132,17 +130,22 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
132
 
130
 
133
 	resp, err := client.Do(req)
131
 	resp, err := client.Do(req)
134
 	if err != nil {
132
 	if err != nil {
133
+		log.WithField("request_id", dsp.RequestId).Errorf("http failed: %s", err)
135
 		return nil, err
134
 		return nil, err
136
 	}
135
 	}
137
 	defer resp.Body.Close()
136
 	defer resp.Body.Close()
138
 	body, err := ioutil.ReadAll(resp.Body)
137
 	body, err := ioutil.ReadAll(resp.Body)
139
-	fmt.Printf("rsp body: %s\n", body)
140
 	if err != nil {
138
 	if err != nil {
139
+		log.WithField("request_id", dsp.RequestId).Errorf("read http body failed: %s", err)
141
 		return nil, err
140
 		return nil, err
142
 	}
141
 	}
142
+
143
+	log.WithField("request_id", dsp.RequestId).Infof("rsp: %s", string(body))
144
+
143
 	rsp := XiaoMiAdInfoRsp{}
145
 	rsp := XiaoMiAdInfoRsp{}
144
-	err = json.Unmarshal(body, &rsp)
146
+	err = json.Unmarshal([]byte(string(body)), &rsp)
145
 	if err != nil {
147
 	if err != nil {
148
+		log.WithField("request_id", dsp.RequestId).Errorf("unmarshal http rsp failed: %s, rsp: %s", err, string(body))
146
 		return nil, err
149
 		return nil, err
147
 	}
150
 	}
148
 
151
 

+ 3 - 1
adslib/device/device.go

@@ -110,9 +110,11 @@ func GetMiDeviceConf(ip string, randNum int, specialDeviceNum int) (*DeviceConf,
110
 	}
110
 	}
111
 
111
 
112
 	rspBytes, _ := redis.Bytes(rsp, err)
112
 	rspBytes, _ := redis.Bytes(rsp, err)
113
+	rspStr := strings.ReplaceAll(string(rspBytes), "u", "")
114
+	rspStr = strings.ReplaceAll(string(rspStr), "'", "\"")
113
 
115
 
114
 	d := DeviceConf{}
116
 	d := DeviceConf{}
115
-	err = json.Unmarshal(rspBytes, &d)
117
+	err = json.Unmarshal([]byte(rspStr), &d)
116
 	if err != nil {
118
 	if err != nil {
117
 		return nil, redisKey, err
119
 		return nil, redisKey, err
118
 	}
120
 	}

+ 5 - 1
adslib/redis_data/redis_data.go

@@ -8,6 +8,7 @@ import (
8
 	"miads/adslib"
8
 	"miads/adslib"
9
 	"miads/adslib/ads_redis"
9
 	"miads/adslib/ads_redis"
10
 	"strconv"
10
 	"strconv"
11
+	"strings"
11
 	"time"
12
 	"time"
12
 )
13
 )
13
 
14
 
@@ -54,9 +55,12 @@ func GetChannelFlag(reqSource string, business string) (ChannelFlag, error) {
54
 	}
55
 	}
55
 
56
 
56
 	rspBytes, _ := redis.Bytes(rsp, err)
57
 	rspBytes, _ := redis.Bytes(rsp, err)
58
+	rspStr := strings.ReplaceAll(string(rspBytes), "'", "\"")
59
+	rspStr = strings.ReplaceAll(rspStr, "L", "")
60
+	log.Info(rspStr)
57
 
61
 
58
 	channelFlag := ChannelFlag{}
62
 	channelFlag := ChannelFlag{}
59
-	err = json.Unmarshal(rspBytes, &channelFlag)
63
+	err = json.Unmarshal([]byte(rspStr), &channelFlag)
60
 	if err != nil {
64
 	if err != nil {
61
 		return ChannelFlag{}, err
65
 		return ChannelFlag{}, err
62
 	}
66
 	}