feat(adcenter): 切到 versionUrl /api/stat/advitise/v2/get 接口拉取,appId=12
- 替换原来通过媒资中心 QueryAdvitiseList 的拉取逻辑 - locId 映射:1→DialogList, 2→NineGridList, 3→VideoTopList+VideoDownList, 12→AppInfoAList, 13→AppInfoBList Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,7 @@ listenAddr: "20021"
|
|||||||
origDomain: "https://yuan.bbaazz.me/"
|
origDomain: "https://yuan.bbaazz.me/"
|
||||||
trustedProxies: ""
|
trustedProxies: ""
|
||||||
bucketVideoAddressV2: "http://139.162.27.29:19996"
|
bucketVideoAddressV2: "http://139.162.27.29:19996"
|
||||||
|
versionUrl: "http://139.162.47.194:8089"
|
||||||
upAppId: 8
|
upAppId: 8
|
||||||
lsjMediaConf:
|
lsjMediaConf:
|
||||||
appId: "430696"
|
appId: "430696"
|
||||||
|
|||||||
@@ -2,60 +2,112 @@ package configser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"videoweb/app/appg"
|
||||||
|
"videoweb/pub/common/httputil"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/netutil"
|
"videoweb/pub/common/netutil"
|
||||||
"videoweb/pub/pubdef"
|
|
||||||
"videoweb/pub/storage"
|
|
||||||
"videoweb/pub/storage/proxy"
|
"videoweb/pub/storage/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateAdvitiseData 从媒资中心按 AppId 拉取广告,图片拼接 CDN 后写入缓存
|
// 广告中心应用ID(本站专用)
|
||||||
func UpdateAdvitiseData(ctx context.Context) {
|
const advertiseAppId int32 = 12
|
||||||
config := GetConfigInfo()
|
|
||||||
queryAdvitiseReq := &proxy.AppAdvitiseInfoReq{
|
// advertiseInfo 广告中心 /api/stat/advitise/v2/get 的广告条目
|
||||||
Id: pubdef.AppId,
|
type advertiseInfo struct {
|
||||||
}
|
Id int64 `json:"id"` // 广告id
|
||||||
advitiseResult, err := storage.QueryAdvitiseList(ctx, queryAdvitiseReq, "")
|
Title string `json:"title"` // 广告标题
|
||||||
if err != nil || advitiseResult.Code != http.StatusOK {
|
CoverImg string `json:"coverImg"` // 封面
|
||||||
if advitiseResult != nil {
|
LocId int32 `json:"locId"` // 位置id
|
||||||
log.Warn("UpdateAdvitiseData.QueryAdvitiseList failed", log.Any("filter", queryAdvitiseReq), log.E(err), log.Any("respCode", advitiseResult.Code))
|
JumpType int32 `json:"jumpType"` // 跳转方式
|
||||||
} else {
|
Link string `json:"link"` // 链接地址
|
||||||
log.Warn("UpdateAdvitiseData.QueryAdvitiseList failed", log.Any("filter", queryAdvitiseReq), log.E(err))
|
Sort int64 `json:"sort"` // 排序
|
||||||
}
|
Tags string `json:"tags"` // 标签
|
||||||
return
|
Remark string `json:"remark"` // 备注描述
|
||||||
}
|
}
|
||||||
|
|
||||||
data := advitiseResult.Data
|
type advertiseReq struct {
|
||||||
for _, list := range []*[]proxy.AdvitiseInfo{
|
AppId int32 `json:"appId"`
|
||||||
&data.DialogList,
|
}
|
||||||
&data.HomeList,
|
|
||||||
&data.VideoTopList,
|
type advertiseRes struct {
|
||||||
&data.VideoDownList,
|
AdvertiseList []advertiseInfo `json:"advertiseList"`
|
||||||
&data.HotAppList,
|
}
|
||||||
&data.NewAppList,
|
|
||||||
&data.MustAppList,
|
// fetchAdvertiseList 请求广告中心 /api/stat/advitise/v2/get
|
||||||
&data.TitleAppList,
|
func fetchAdvertiseList() (*advertiseRes, error) {
|
||||||
&data.FriendList,
|
versionUrl := strings.TrimRight(strings.TrimSpace(appg.Conf.VersionUrl), "/")
|
||||||
&data.NineGridList,
|
if versionUrl == "" {
|
||||||
&data.VideoList,
|
return nil, fmt.Errorf("versionUrl 未配置")
|
||||||
&data.StopList,
|
}
|
||||||
&data.ForcedJumpList,
|
url := versionUrl + "/api/stat/advitise/v2/get"
|
||||||
&data.AppInfoAList,
|
body, _ := json.Marshal(advertiseReq{AppId: advertiseAppId})
|
||||||
&data.AppInfoBList,
|
var resp advertiseRes
|
||||||
} {
|
code, err := httputil.Client().POSTJsonWithJResp(&resp, url, map[string]string{"Content-Type": "application/json"}, body)
|
||||||
mergeAdvitiseImages(*list, config.ImgCdn)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if code != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("response status %d", code)
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdvitiseData 从广告中心拉取广告并更新内存缓存,列表为空时重试一次
|
||||||
|
func UpdateAdvitiseData(ctx context.Context) {
|
||||||
|
resp, err := fetchAdvertiseList()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("UpdateAdvitiseData fetchAdvertiseList fail", log.E(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(resp.AdvertiseList) == 0 {
|
||||||
|
resp, err = fetchAdvertiseList()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("UpdateAdvitiseData fetchAdvertiseList retry fail", log.E(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list := resp.AdvertiseList
|
||||||
|
sort.SliceStable(list, func(i, j int) bool {
|
||||||
|
if list[i].LocId != list[j].LocId {
|
||||||
|
return list[i].LocId < list[j].LocId
|
||||||
|
}
|
||||||
|
return list[i].Sort < list[j].Sort
|
||||||
|
})
|
||||||
|
|
||||||
|
config := GetConfigInfo()
|
||||||
|
data := proxy.AdvitiseData{}
|
||||||
|
|
||||||
|
for _, v := range list {
|
||||||
|
pos := int64(v.LocId)
|
||||||
|
info := proxy.AdvitiseInfo{
|
||||||
|
Id: strconv.FormatInt(v.Id, 10),
|
||||||
|
Location: pos,
|
||||||
|
Title: v.Title,
|
||||||
|
Images: netutil.MergeURL(config.ImgCdn, strings.TrimLeft(v.CoverImg, "/")),
|
||||||
|
Link: strings.ReplaceAll(v.Link, "inner://yinseinner/", "yinseinner://"),
|
||||||
|
}
|
||||||
|
switch pos {
|
||||||
|
case 1:
|
||||||
|
data.DialogList = append(data.DialogList, info)
|
||||||
|
case 2:
|
||||||
|
data.NineGridList = append(data.NineGridList, info)
|
||||||
|
case 3:
|
||||||
|
data.VideoTopList = append(data.VideoTopList, info)
|
||||||
|
data.VideoDownList = append(data.VideoDownList, info)
|
||||||
|
case 12:
|
||||||
|
data.AppInfoAList = append(data.AppInfoAList, info)
|
||||||
|
case 13:
|
||||||
|
data.AppInfoBList = append(data.AppInfoBList, info)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheMgr.Lock.Lock()
|
CacheMgr.Lock.Lock()
|
||||||
defer CacheMgr.Lock.Unlock()
|
defer CacheMgr.Lock.Unlock()
|
||||||
CacheMgr.Advitise = data
|
CacheMgr.Advitise = data
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeAdvitiseImages(list []proxy.AdvitiseInfo, cdn string) {
|
|
||||||
for i := range list {
|
|
||||||
if len(list[i].Images) > 0 {
|
|
||||||
list[i].Images = netutil.MergeURL(cdn, list[i].Images)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user