|
|
|
@ -98,7 +98,6 @@ func sendMsgHugeAmount(ctx context.Context, url string, data map[string]interfac
|
|
|
|
|
if err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
g.Log().Info(ctx, "sendMsgHugeAmount - res: ", bytes) |
|
|
|
|
src := string(bytes.ReadAll()) |
|
|
|
|
tmp, err := gcharset.ToUTF8("UTF-8", src) |
|
|
|
|
if err != nil { |
|
|
|
@ -109,7 +108,7 @@ func sendMsgHugeAmount(ctx context.Context, url string, data map[string]interfac
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.ATHARes, err error) { |
|
|
|
|
log.Printf("AttributionHugeAmount: %s", gjson.MustEncodeString(req)) |
|
|
|
|
//log.Printf("AttributionHugeAmount: %s", gjson.MustEncodeString(req))
|
|
|
|
|
data := map[string]interface{}{ |
|
|
|
|
"platform": req.Platform, // ios或android
|
|
|
|
|
"package_name": req.PackageName, |
|
|
|
@ -118,19 +117,37 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
var adData []entity.AdvertisementOceanegine |
|
|
|
|
model := dao.AdvertisementOceanegine.Ctx(ctx).Order("last_touch_time desc") |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
_ = model.Where("adv_android_id=?", req.AndroidId).Scan(&adData) |
|
|
|
|
if req.AndroidId != "" { |
|
|
|
|
_ = model.Where("adv_android_id=?", req.AndroidId).Scan(&adData) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("AttributionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
data["android_id"] = req.AndroidId |
|
|
|
|
} else if req.Platform == "ios" { |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Scan(&adData) |
|
|
|
|
if req.Idfa != "" { |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Scan(&adData) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("AttributionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
return |
|
|
|
|
if req.Idfv != "" { |
|
|
|
|
_ = model.Where("adv_idfv=?", req.Idfv).Scan(&adData) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("AttributionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
data["idfv"] = req.Idfv |
|
|
|
|
} else { |
|
|
|
|
err = errors.New("platform is error " + req.Platform) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 || adData[0].CallbackParam == "" { |
|
|
|
|
err = errors.New("无广告!") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
url := "https://analytics.oceanengine.com/sdk/app/attribution" |
|
|
|
@ -146,48 +163,79 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
if json != nil && json.Get("code").Int() == 0 { |
|
|
|
|
callbackUrl := json.Get("callback_url").String() |
|
|
|
|
callbackParam := json.Get("callback_param").String() |
|
|
|
|
androidId := json.Get("adv_android_id").String() |
|
|
|
|
if androidId == "" { |
|
|
|
|
androidId = req.AndroidId |
|
|
|
|
} |
|
|
|
|
idfa := json.Get("idfa").String() |
|
|
|
|
if idfa == "" { |
|
|
|
|
idfa = req.Idfa |
|
|
|
|
} |
|
|
|
|
advIdfv := json.Get("adv_idfv").String() |
|
|
|
|
if advIdfv == "" { |
|
|
|
|
advIdfv = req.Idfv |
|
|
|
|
} |
|
|
|
|
lastTouchTime := json.Get("last_touch_time").Int64() |
|
|
|
|
advertiseData := do.AdvertisementOceanegine{AdvAndroidId: req.AndroidId, Idfa: req.Idfa, AdvIdfv: req.Idfv, |
|
|
|
|
advertiseData := do.AdvertisementOceanegine{AdvAndroidId: androidId, Idfa: idfa, AdvIdfv: advIdfv, |
|
|
|
|
CallbackUrl: callbackUrl, CallbackParam: callbackParam, LastTouchTime: lastTouchTime * 1000} |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
advertiseData.Os = 0 |
|
|
|
|
} else if req.Platform == "ios" { |
|
|
|
|
advertiseData.Os = 1 |
|
|
|
|
} |
|
|
|
|
_, _ = dao.AdvertisementOceanegine.Ctx(ctx).Insert(advertiseData) |
|
|
|
|
if callbackParam == "" { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
_, err = dao.AdvertisementOceanegine.Ctx(ctx).Insert(advertiseData) |
|
|
|
|
} else { |
|
|
|
|
return nil, errors.New("获取失败") |
|
|
|
|
err = errors.New("获取失败") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ConversionHugeAmount(ctx context.Context, req *game.CSHAReq) (res *game.CSHARes, err error) { |
|
|
|
|
log.Printf("ConversionHugeAmount: %s", gjson.MustEncodeString(req)) |
|
|
|
|
//log.Printf("ConversionHugeAmount: %s", gjson.MustEncodeString(req))
|
|
|
|
|
var adData []entity.AdvertisementOceanegine |
|
|
|
|
device := map[string]interface{}{ |
|
|
|
|
"platform": req.Platform, |
|
|
|
|
} |
|
|
|
|
model := dao.AdvertisementOceanegine.Ctx(ctx).Order("last_touch_time desc") |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
_ = model.Where("adv_android_id=?", req.Id).Scan(&adData) |
|
|
|
|
if req.Id != "" { |
|
|
|
|
_ = model.Where("adv_android_id=?", req.Id).Scan(&adData) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("ConversionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
device["android_id"] = req.Id |
|
|
|
|
} else if req.Platform == "ios" && req.Idfa != "" { |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Scan(&adData) |
|
|
|
|
} else if req.Platform == "ios" { |
|
|
|
|
if req.Idfa != "" { |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Scan(&adData) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("ConversionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
return |
|
|
|
|
if req.Id != "" { |
|
|
|
|
_ = model.Where("adv_idfv=?", req.Id).Scan(&adData) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("ConversionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
device["idfv"] = req.Id |
|
|
|
|
} else { |
|
|
|
|
return nil, errors.New("") |
|
|
|
|
err = errors.New("platform is error " + req.Platform) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if adData[0].CallbackParam == "" { |
|
|
|
|
err = errors.New("callbackParam is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// log.Printf("ConversionHugeAmount: adData: %s", gjson.MustEncodeString(adData))
|
|
|
|
|
ad := map[string]interface{}{ |
|
|
|
|
"callback": adData[0].CallbackParam, |
|
|
|
|
} |
|
|
|
@ -213,21 +261,32 @@ func ConversionHugeAmount(ctx context.Context, req *game.CSHAReq) (res *game.CSH
|
|
|
|
|
} |
|
|
|
|
data["properties"] = properties |
|
|
|
|
} |
|
|
|
|
// log.Printf("ConversionHugeAmount: json.Unmarshal([]byte(req.Properties), &properties): %s", gjson.MustEncodeString(properties))
|
|
|
|
|
//log.Printf("ConversionHugeAmount: %s", gjson.MustEncodeString(data))
|
|
|
|
|
url := "https://analytics.oceanengine.com/api/v2/conversion" |
|
|
|
|
_, _ = sendMsgHugeAmount(ctx, url, data) |
|
|
|
|
tmp, err := sendMsgHugeAmount(ctx, url, data) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
json, err := gjson.DecodeToJson(tmp) |
|
|
|
|
if json != nil && json.Get("code").Int() != 0 { |
|
|
|
|
err = errors.New(json.Get("message").String()) |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func AdvertiseHugeAmount(ctx context.Context, req *game.AdvertiseHAReq) (res *game.AdvertiseHARes, err error) { |
|
|
|
|
req.Platform = strings.ToLower(req.Platform) |
|
|
|
|
log.Printf("AdvertiseHugeAmount: %s", gjson.MustEncodeString(req)) |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if req.Platform == "iphoneplayer" { |
|
|
|
|
req.Platform = "ios" |
|
|
|
|
} |
|
|
|
|
go HugeAmount(ctx, req) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func HugeAmount(ctx context.Context, req *game.AdvertiseHAReq) { |
|
|
|
|
req2 := game.CSHAReq{ |
|
|
|
|
Platform: req.Platform, |
|
|
|
|
Id: req.Id, |
|
|
|
@ -236,8 +295,11 @@ func AdvertiseHugeAmount(ctx context.Context, req *game.AdvertiseHAReq) (res *ga
|
|
|
|
|
Properties: req.Properties, |
|
|
|
|
} |
|
|
|
|
req2.Id = req.Id |
|
|
|
|
_, err = ConversionHugeAmount(ctx, &req2) |
|
|
|
|
|
|
|
|
|
_, err := ConversionHugeAmount(ctx, &req2) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("AdvertiseHugeAmount: ConversionHugeAmount err- %s, req: %s", err.Error(), gjson.MustEncodeString(req2)) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
req1 := game.ATHAReq{ |
|
|
|
|
Platform: req.Platform, |
|
|
|
|
PackageName: req.PackageName, |
|
|
|
@ -248,10 +310,12 @@ func AdvertiseHugeAmount(ctx context.Context, req *game.AdvertiseHAReq) (res *ga
|
|
|
|
|
} else if req.Platform == "ios" { |
|
|
|
|
req1.Idfv = req.Id |
|
|
|
|
} else { |
|
|
|
|
log.Printf("AdvertiseHugeAmount: plarform err- %s, req.Platform: %s", err.Error(), req.Platform) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
_, err = AttributionHugeAmount(ctx, &req1) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("AdvertiseHugeAmount: AttributionHugeAmount err- %s, req: %s", err.Error(), gjson.MustEncodeString(req1)) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|