refactor(adcenter): /api/app/ads/click 改用 AdsClickInfo,接收并透传 appId
- handler 绑定 proto.AdsClickInfo{appId, adsId, location}
- AsyncAdvertiseClick/AdvertiseClickCenter 新增 appId 参数
- appId<=0 时回落到默认 advertiseAppId=12
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package adsapi
|
package adsapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"videoweb/app/api/proto"
|
"videoweb/app/api/proto"
|
||||||
"videoweb/app/service/configser"
|
"videoweb/app/service/configser"
|
||||||
"videoweb/pub/common"
|
"videoweb/pub/common"
|
||||||
@@ -12,18 +14,18 @@ import (
|
|||||||
// Click 广告点击上报
|
// Click 广告点击上报
|
||||||
// @Tags 广告
|
// @Tags 广告
|
||||||
// @Summary 广告点击上报
|
// @Summary 广告点击上报
|
||||||
// @Description 用户点击广告时异步上报到广告中心
|
// @Description 用户点击广告时异步上报到广告中心。请求可带 appId 覆盖默认,缺省时按本站 appId 上报。
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param param body proto.AdsClickReq true "参数"
|
// @Param param body proto.AdsClickInfo true "参数"
|
||||||
// @Success 200 {string} json
|
// @Success 200 {string} json
|
||||||
// @Router /api/app/ads/click [POST]
|
// @Router /api/app/ads/click [POST]
|
||||||
func Click(c *gin.Context) {
|
func Click(c *gin.Context) {
|
||||||
var req proto.AdsClickReq
|
var req proto.AdsClickInfo
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configser.AsyncAdvertiseClick(req.AdsId)
|
configser.AsyncAdvertiseClick(strconv.FormatInt(req.AdsId, 10), int32(req.AppId))
|
||||||
common.ServerJSON(c, srvdef.Success, nil)
|
common.ServerJSON(c, srvdef.Success, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,23 @@ type advertiseClickResp struct {
|
|||||||
Code int64 `json:"code"`
|
Code int64 `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdvertiseClickCenter 同步上报单条广告点击到广告中心
|
// resolveAdvertiseAppId 请求带了 AppId 用请求的,否则回落到默认 advertiseAppId
|
||||||
func AdvertiseClickCenter(advertiseId int64) error {
|
func resolveAdvertiseAppId(reqAppId int32) int32 {
|
||||||
|
if reqAppId > 0 {
|
||||||
|
return reqAppId
|
||||||
|
}
|
||||||
|
return advertiseAppId
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdvertiseClickCenter 同步上报单条广告点击到广告中心。
|
||||||
|
// appId<=0 时回落到默认 advertiseAppId。
|
||||||
|
func AdvertiseClickCenter(advertiseId int64, appId int32) error {
|
||||||
versionUrl := strings.TrimRight(strings.TrimSpace(appg.Conf.VersionUrl), "/")
|
versionUrl := strings.TrimRight(strings.TrimSpace(appg.Conf.VersionUrl), "/")
|
||||||
if versionUrl == "" {
|
if versionUrl == "" {
|
||||||
return fmt.Errorf("versionUrl 未配置")
|
return fmt.Errorf("versionUrl 未配置")
|
||||||
}
|
}
|
||||||
url := versionUrl + "/api/stat/advitise/v2/click"
|
url := versionUrl + "/api/stat/advitise/v2/click"
|
||||||
body, _ := json.Marshal(advertiseClickReq{Id: advertiseId, AppId: advertiseAppId})
|
body, _ := json.Marshal(advertiseClickReq{Id: advertiseId, AppId: resolveAdvertiseAppId(appId)})
|
||||||
var resp advertiseClickResp
|
var resp advertiseClickResp
|
||||||
code, err := httputil.Client().POSTJsonWithJResp(&resp, url, map[string]string{"Content-Type": "application/json"}, body)
|
code, err := httputil.Client().POSTJsonWithJResp(&resp, url, map[string]string{"Content-Type": "application/json"}, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -43,14 +52,15 @@ func AdvertiseClickCenter(advertiseId int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsyncAdvertiseClick 异步上报广告点击,非数字 id 忽略
|
// AsyncAdvertiseClick 异步上报广告点击,非数字 id 忽略。
|
||||||
func AsyncAdvertiseClick(id string) {
|
// appId<=0 时回落到默认 advertiseAppId。
|
||||||
|
func AsyncAdvertiseClick(id string, appId int32) {
|
||||||
advertiseId, err := strconv.ParseInt(strings.TrimSpace(id), 10, 64)
|
advertiseId, err := strconv.ParseInt(strings.TrimSpace(id), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("AsyncAdvertiseClick invalid id", log.Any("id", id))
|
log.Warn("AsyncAdvertiseClick invalid id", log.Any("id", id))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
godef.Go(func() {
|
godef.Go(func() {
|
||||||
_ = AdvertiseClickCenter(advertiseId)
|
_ = AdvertiseClickCenter(advertiseId, appId)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user