feat(adcenter): 切到 versionUrl /api/stat/advitise/v2/get 接口拉取,appId=12
- 替换原来通过加密集团广告中心的拉取逻辑 - 恢复启动时与 cron 每 5 分钟刷新 - 位置 1/2/3/12/13 映射到 DialogList/NineGridList/DetailbannerList/AList/BList Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,7 @@ listenAddr: "25119"
|
|||||||
origDomain: "https://yuan.bbaazz.me/"
|
origDomain: "https://yuan.bbaazz.me/"
|
||||||
trustedProxies: ""
|
trustedProxies: ""
|
||||||
bucketVideoAddressV2: "http://139.162.22.207:24996"
|
bucketVideoAddressV2: "http://139.162.22.207:24996"
|
||||||
|
versionUrl: "http://139.162.47.194:8089"
|
||||||
transactionUrl: "https://bill.ruishengces.com"
|
transactionUrl: "https://bill.ruishengces.com"
|
||||||
newPayCenter:
|
newPayCenter:
|
||||||
appName: ""
|
appName: ""
|
||||||
|
|||||||
@@ -1,92 +1,130 @@
|
|||||||
package configser
|
package configser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"videoweb/app/api/proto"
|
"videoweb/app/api/proto"
|
||||||
"videoweb/app/appg"
|
"videoweb/app/appg"
|
||||||
"videoweb/pub/adcenter"
|
"videoweb/pub/adcenter"
|
||||||
|
"videoweb/pub/common/httputil"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/netutil"
|
"videoweb/pub/common/netutil"
|
||||||
"videoweb/pub/storage/proxy"
|
"videoweb/pub/storage/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateAdvitiseDataFromJt 从广告中心拉取福利页广告
|
// 广告中心应用ID(本站专用)
|
||||||
func UpdateAdvitiseDataFromJt() {
|
const advertiseAppId int32 = 12
|
||||||
config := GetConfigInfo()
|
|
||||||
var resp proto.AdvitiseData
|
// advertiseInfo 广告中心 /api/stat/advitise/v2/get 的广告条目
|
||||||
jtAds, err := adcenter.JtAdvertiseThreeServer(appg.Conf.AdCenter.ApiDomain, appg.Conf.AdCenter.MerchantCode, appg.Conf.AdCenter.AppCode, appg.Conf.AdCenter.AesKey)
|
type advertiseInfo struct {
|
||||||
|
Id int64 `json:"id"` // 广告id
|
||||||
|
Title string `json:"title"` // 广告标题
|
||||||
|
CoverImg string `json:"coverImg"` // 封面
|
||||||
|
LocId int32 `json:"locId"` // 位置id
|
||||||
|
JumpType int32 `json:"jumpType"` // 跳转方式
|
||||||
|
Link string `json:"link"` // 链接地址
|
||||||
|
Sort int64 `json:"sort"` // 排序
|
||||||
|
Tags string `json:"tags"` // 标签
|
||||||
|
Remark string `json:"remark"` // 备注描述
|
||||||
|
}
|
||||||
|
|
||||||
|
type advertiseReq struct {
|
||||||
|
AppId int32 `json:"appId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type advertiseRes struct {
|
||||||
|
AdvertiseList []advertiseInfo `json:"advertiseList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetchAdvertiseList 请求广告中心 /api/stat/advitise/v2/get
|
||||||
|
func fetchAdvertiseList() (*advertiseRes, error) {
|
||||||
|
versionUrl := strings.TrimRight(strings.TrimSpace(appg.Conf.VersionUrl), "/")
|
||||||
|
if versionUrl == "" {
|
||||||
|
return nil, fmt.Errorf("versionUrl 未配置")
|
||||||
|
}
|
||||||
|
url := versionUrl + "/api/stat/advitise/v2/get"
|
||||||
|
body, _ := json.Marshal(advertiseReq{AppId: advertiseAppId})
|
||||||
|
var resp advertiseRes
|
||||||
|
code, err := httputil.Client().POSTJsonWithJResp(&resp, url, map[string]string{"Content-Type": "application/json"}, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("JtAdvertiseThreeServer error occur", log.E(err))
|
return nil, err
|
||||||
|
}
|
||||||
|
if code != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("response status %d", code)
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdvitiseDataFromJt 从广告中心拉取广告并更新内存缓存,列表为空时重试一次
|
||||||
|
func UpdateAdvitiseDataFromJt() {
|
||||||
|
resp, err := fetchAdvertiseList()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("UpdateAdvitiseDataFromJt fetchAdvertiseList fail", log.E(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
adMap := make(map[string]adcenter.AdCacheInfo)
|
if len(resp.AdvertiseList) == 0 {
|
||||||
for _, loc := range jtAds {
|
resp, err = fetchAdvertiseList()
|
||||||
pos, err := strconv.Atoi(loc.AdvertiseLocationCode)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("广告位置代码错误,必须为数字", log.Any("code", loc.AdvertiseLocationCode))
|
log.Error("UpdateAdvitiseDataFromJt fetchAdvertiseList retry fail", log.E(err))
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
//if pos < 100001 {
|
}
|
||||||
// continue
|
list := resp.AdvertiseList
|
||||||
//}
|
sort.SliceStable(list, func(i, j int) bool {
|
||||||
ads := make([]proxy.AdvitiseInfo, 0)
|
if list[i].LocId != list[j].LocId {
|
||||||
for _, ad := range loc.AdDetailInfoList {
|
return list[i].LocId < list[j].LocId
|
||||||
//extra := ad.GetExtraData()
|
}
|
||||||
ads = append(ads, proxy.AdvitiseInfo{
|
return list[i].Sort < list[j].Sort
|
||||||
Id: ad.AdvertiseCode,
|
|
||||||
Location: int64(pos),
|
|
||||||
Title: ad.AdvertiseName,
|
|
||||||
Images: netutil.MergeURL(config.ImgCdn, ad.GetCoverLsj()),
|
|
||||||
Link: ad.GetRealLink(),
|
|
||||||
})
|
})
|
||||||
adMap[ad.AdvertiseCode] = adcenter.AdCacheInfo{
|
|
||||||
AdvertiseCode: ad.AdvertiseCode,
|
config := GetConfigInfo()
|
||||||
CustomerCode: ad.CustomerCode,
|
data := proto.AdvitiseData{}
|
||||||
AdvertiseName: ad.AdvertiseName,
|
adMap := make(map[string]adcenter.AdCacheInfo, len(list))
|
||||||
AdvertiseUrl: ad.AdvertiseUrl,
|
|
||||||
AdvertiseIcon: ad.AdvertiseIcon,
|
for _, v := range list {
|
||||||
AdvertiseType: ad.AdvertiseType,
|
pos := int64(v.LocId)
|
||||||
AdMode: ad.AdMode,
|
info := proxy.AdvitiseInfo{
|
||||||
AppCode: ad.AppCode,
|
Id: strconv.FormatInt(v.Id, 10),
|
||||||
LocationType: ad.LocationType,
|
Location: pos,
|
||||||
AdvertiseDesc: ad.AdvertiseDesc,
|
Title: v.Title,
|
||||||
PageType: ad.PageType,
|
Images: netutil.MergeURL(config.ImgCdn, strings.TrimLeft(v.CoverImg, "/")),
|
||||||
StartTimeStamp: ad.StartTimeStamp,
|
Link: strings.ReplaceAll(v.Link, "inner://yinseinner/", "yinseinner://"),
|
||||||
EndTimeStamp: ad.EndTimeStamp,
|
|
||||||
Sort: ad.Sort,
|
|
||||||
AdExtData: ad.AdExtData,
|
|
||||||
DeptCode: loc.DeptCode,
|
|
||||||
MerchantCode: loc.MerchantCode,
|
|
||||||
AdvertiseLocationCode: loc.AdvertiseLocationCode,
|
|
||||||
AdvertiseLocationName: loc.AdvertiseLocationName,
|
|
||||||
DisplayMode: loc.DisplayMode,
|
|
||||||
AdvertiseHeight: loc.AdvertiseHeight,
|
|
||||||
AdvertiseWidth: loc.AdvertiseWidth,
|
|
||||||
MaterialType: loc.MaterialType,
|
|
||||||
AdLimit: loc.AdLimit,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch pos {
|
switch pos {
|
||||||
case 1: //弹窗
|
case 1:
|
||||||
resp.DialogList = ads
|
data.DialogList = append(data.DialogList, info)
|
||||||
case 2: // 应用
|
case 2:
|
||||||
|
data.NineGridList = append(data.NineGridList, info)
|
||||||
resp.NineGridList = ads
|
case 3:
|
||||||
case 3: // 横幅
|
data.DetailbannerList = append(data.DetailbannerList, info)
|
||||||
resp.DetailbannerList = ads
|
|
||||||
|
|
||||||
case 12:
|
case 12:
|
||||||
resp.AList = ads
|
data.AList = append(data.AList, info)
|
||||||
case 13:
|
case 13:
|
||||||
resp.BList = ads
|
data.BList = append(data.BList, info)
|
||||||
|
}
|
||||||
|
adMap[info.Id] = adcenter.AdCacheInfo{
|
||||||
|
AdvertiseCode: info.Id,
|
||||||
|
AdvertiseName: v.Title,
|
||||||
|
AdvertiseUrl: v.Link,
|
||||||
|
AdvertiseIcon: v.CoverImg,
|
||||||
|
AdvertiseDesc: v.Remark,
|
||||||
|
Sort: int(v.Sort),
|
||||||
|
AdvertiseLocationCode: strconv.FormatInt(pos, 10),
|
||||||
|
AdvertiseLocationName: v.Title,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheMgr.Lock.Lock()
|
CacheMgr.Lock.Lock()
|
||||||
defer CacheMgr.Lock.Unlock()
|
defer CacheMgr.Lock.Unlock()
|
||||||
CacheMgr.Advitise = resp
|
CacheMgr.Advitise = data
|
||||||
CacheMgr.AdvitiseMap = adMap
|
CacheMgr.AdvitiseMap = adMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAdvertiseLocation 按广告ID反查广告详情
|
||||||
func GetAdvertiseLocation(adverId string) (res adcenter.AdCacheInfo) {
|
func GetAdvertiseLocation(adverId string) (res adcenter.AdCacheInfo) {
|
||||||
CacheMgr.Lock.RLock()
|
CacheMgr.Lock.RLock()
|
||||||
defer CacheMgr.Lock.RUnlock()
|
defer CacheMgr.Lock.RUnlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user