feat(adcenter): 新增 POST /api/app/ads/click 广告点击上报到广告中心
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
package adsapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"videoweb/app/api/proto"
|
||||||
|
"videoweb/app/service/configser"
|
||||||
|
"videoweb/pub/common"
|
||||||
|
"videoweb/pub/common/srvdef"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Click 广告点击上报
|
||||||
|
// @Tags 广告
|
||||||
|
// @Summary 广告点击上报
|
||||||
|
// @Description 用户点击广告时异步上报到广告中心
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param param body proto.AdsClickReq true "参数"
|
||||||
|
// @Success 200 {string} json
|
||||||
|
// @Router /api/app/ads/click [POST]
|
||||||
|
func Click(c *gin.Context) {
|
||||||
|
var req proto.AdsClickReq
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
configser.AsyncAdvertiseClick(req.AdsId)
|
||||||
|
common.ServerJSON(c, srvdef.Success, nil)
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ var (
|
|||||||
"/api/app/upload/image",
|
"/api/app/upload/image",
|
||||||
"/search",
|
"/search",
|
||||||
"/api/app/applist",
|
"/api/app/applist",
|
||||||
|
"/api/app/ads/click",
|
||||||
"/h5/m3u8",
|
"/h5/m3u8",
|
||||||
"/enkey",
|
"/enkey",
|
||||||
"/newenkey",
|
"/newenkey",
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"videoweb/app/api/adsapi"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func adsRouter(r *gin.Engine) {
|
||||||
|
r.POST("/api/app/ads/click", adsapi.Click)
|
||||||
|
}
|
||||||
@@ -114,6 +114,7 @@ func registeRouter(r *gin.Engine) {
|
|||||||
appInfoRouter(r)
|
appInfoRouter(r)
|
||||||
healthRouter(r)
|
healthRouter(r)
|
||||||
richTextRouter(r)
|
richTextRouter(r)
|
||||||
|
adsRouter(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置swag 接口信息
|
// 设置swag 接口信息
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package configser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"videoweb/app/appg"
|
||||||
|
"videoweb/pub/common/godef"
|
||||||
|
"videoweb/pub/common/httputil"
|
||||||
|
"videoweb/pub/common/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type advertiseClickReq struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
AppId int32 `json:"appId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type advertiseClickResp struct {
|
||||||
|
Code int64 `json:"code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdvertiseClickCenter 同步上报单条广告点击到广告中心
|
||||||
|
func AdvertiseClickCenter(advertiseId int64) error {
|
||||||
|
versionUrl := strings.TrimRight(strings.TrimSpace(appg.Conf.VersionUrl), "/")
|
||||||
|
if versionUrl == "" {
|
||||||
|
return fmt.Errorf("versionUrl 未配置")
|
||||||
|
}
|
||||||
|
url := versionUrl + "/api/stat/advitise/v2/click"
|
||||||
|
body, _ := json.Marshal(advertiseClickReq{Id: advertiseId, AppId: advertiseAppId})
|
||||||
|
var resp advertiseClickResp
|
||||||
|
code, err := httputil.Client().POSTJsonWithJResp(&resp, url, map[string]string{"Content-Type": "application/json"}, body)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("AdvertiseClickCenter POST fail", log.Any("url", url), log.Any("id", advertiseId), log.E(err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if code != http.StatusOK {
|
||||||
|
log.Error("AdvertiseClickCenter response status", log.Any("code", code), log.Any("id", advertiseId))
|
||||||
|
return fmt.Errorf("response status %d", code)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AsyncAdvertiseClick 异步上报广告点击,非数字 id 忽略
|
||||||
|
func AsyncAdvertiseClick(id string) {
|
||||||
|
advertiseId, err := strconv.ParseInt(strings.TrimSpace(id), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn("AsyncAdvertiseClick invalid id", log.Any("id", id))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
godef.Go(func() {
|
||||||
|
_ = AdvertiseClickCenter(advertiseId)
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user