-
Notifications
You must be signed in to change notification settings - Fork 40
/
active.go
68 lines (65 loc) · 1.63 KB
/
active.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package track
import (
"encoding/json"
"net/http"
"strconv"
"github.com/bububa/oceanengine/marketing-api/enum"
"github.com/bububa/oceanengine/marketing-api/model/track"
"github.com/bububa/oceanengine/marketing-api/util"
)
// Active API上报数据(new)
func Active(req *track.ActiveRequest) (string, error) {
values := util.GetUrlValues()
if req.Callback != "" {
values.Set("callback", req.Callback)
values.Set("os", strconv.Itoa(req.Os))
if req.Os == enum.Track_ANDROID {
values.Set("imei", req.Imei)
values.Set("muid", req.Muid)
values.Set("oaid", req.Oaid)
if req.OaidMd5 != "" {
values.Set("oaid_md5", req.OaidMd5)
}
} else {
values.Set("idfa", req.Idfa)
}
if req.Caid1 != "" {
values.Set("caid1", req.Caid1)
}
if req.Caid2 != "" {
values.Set("caid2", req.Caid2)
}
} else {
values.Set("link", req.Link)
}
values.Set("event_type", strconv.Itoa(req.EventType))
if req.ConvTime > 0 {
values.Set("conv_time", strconv.FormatInt(req.ConvTime, 10))
}
if req.Source != "" {
values.Set("source", req.Source)
}
for k, v := range req.Ext {
values.Set(k, v)
}
rawQuery := values.Encode()
util.PutUrlValues(values)
builder := util.GetStringsBuilder()
builder.WriteString("https://ad.oceanengine.com/track/activate/?")
builder.WriteString(rawQuery)
reqUrl := builder.String()
util.PutStringsBuilder(builder)
resp, err := http.DefaultClient.Get(reqUrl)
if err != nil {
return reqUrl, err
}
defer resp.Body.Close()
var ret track.Response
if err := json.NewDecoder(resp.Body).Decode(&ret); err != nil {
return reqUrl, err
}
if ret.IsError() {
return reqUrl, ret
}
return reqUrl, nil
}