同步 web_hga 的五项改造
- 移除 买点 (user acquisition tracking) 子系统:dataReport SDK、eventmod 事件模型、reportdata 定时上报 job、reportser/srv_report 包装层,以及业务 侧的 ~20 处 Report* 调用点;去掉 proto.ConfigInfo 的 ReportSDKConfig 字段、DataReport yaml 配置块和 pubdef.TrackerAppId。 - 广告获取改走 versionUrl /api/stat/advitise/v2/get(appId=12),移除 adcenter(Jt) 调用;新增 POST /api/app/ads/click 异步上报; proto.AdvitiseData 别名 proxy.AdvitiseData,AList/BList 改名 AppInfoAList/AppInfoBList。 - web 后台登录取消谷歌验证码(srv_mwacc.AccLogin 去掉 code 参数),密码 正确即发放 token。 - app 端取消注册/登录/找回密码/游客登录接口及密码、token 相关代码;鉴权 中间件按 X-User-Agent 中的 devID 识别用户,首次访问自动建号,Redis 缓存 10 分钟;修改资料不再支持改密码。 - app m3u8 ticket 校验失败不再降级到 fallback 路径,仍按原 m3u8Name 返回。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
// resolveAdvertiseAppId 请求带了 AppId 用请求的,否则回落到默认 advertiseAppId
|
||||
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), "/")
|
||||
if versionUrl == "" {
|
||||
return fmt.Errorf("versionUrl 未配置")
|
||||
}
|
||||
url := versionUrl + "/api/stat/advitise/v2/click"
|
||||
body, _ := json.Marshal(advertiseClickReq{Id: advertiseId, AppId: resolveAdvertiseAppId(appId)})
|
||||
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 忽略。
|
||||
// appId<=0 时回落到默认 advertiseAppId。
|
||||
func AsyncAdvertiseClick(id string, appId int32) {
|
||||
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, appId)
|
||||
})
|
||||
}
|
||||
@@ -1,97 +1,113 @@
|
||||
package configser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"videoweb/app/api/proto"
|
||||
"strings"
|
||||
"videoweb/app/appg"
|
||||
"videoweb/pub/adcenter"
|
||||
"videoweb/pub/common/httputil"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/netutil"
|
||||
"videoweb/pub/storage/proxy"
|
||||
)
|
||||
|
||||
// UpdateAdvitiseDataFromJt 从广告中心拉取福利页广告
|
||||
func UpdateAdvitiseDataFromJt() {
|
||||
config := GetConfigInfo()
|
||||
var resp proto.AdvitiseData
|
||||
jtAds, err := adcenter.JtAdvertiseThreeServer(appg.Conf.AdCenter.ApiDomain, appg.Conf.AdCenter.MerchantCode, appg.Conf.AdCenter.AppCode, appg.Conf.AdCenter.AesKey)
|
||||
// 广告中心应用ID(本站专用)
|
||||
const advertiseAppId int32 = 12
|
||||
|
||||
// advertiseInfo 广告中心 /api/stat/advitise/v2/get 的广告条目
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
// UpdateAdvitiseData 从广告中心拉取广告并更新内存缓存,列表为空时重试一次
|
||||
func UpdateAdvitiseData(ctx context.Context) {
|
||||
resp, err := fetchAdvertiseList()
|
||||
if err != nil {
|
||||
log.Error("UpdateAdvitiseData fetchAdvertiseList fail", log.E(err))
|
||||
return
|
||||
}
|
||||
adMap := make(map[string]adcenter.AdCacheInfo)
|
||||
for _, loc := range jtAds {
|
||||
pos, err := strconv.Atoi(loc.AdvertiseLocationCode)
|
||||
if len(resp.AdvertiseList) == 0 {
|
||||
resp, err = fetchAdvertiseList()
|
||||
if err != nil {
|
||||
log.Error("广告位置代码错误,必须为数字", log.Any("code", loc.AdvertiseLocationCode))
|
||||
continue
|
||||
log.Error("UpdateAdvitiseData fetchAdvertiseList retry fail", log.E(err))
|
||||
return
|
||||
}
|
||||
//if pos < 100001 {
|
||||
// continue
|
||||
//}
|
||||
ads := make([]proxy.AdvitiseInfo, 0)
|
||||
for _, ad := range loc.AdDetailInfoList {
|
||||
//extra := ad.GetExtraData()
|
||||
ads = append(ads, proxy.AdvitiseInfo{
|
||||
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,
|
||||
CustomerCode: ad.CustomerCode,
|
||||
AdvertiseName: ad.AdvertiseName,
|
||||
AdvertiseUrl: ad.AdvertiseUrl,
|
||||
AdvertiseIcon: ad.AdvertiseIcon,
|
||||
AdvertiseType: ad.AdvertiseType,
|
||||
AdMode: ad.AdMode,
|
||||
AppCode: ad.AppCode,
|
||||
LocationType: ad.LocationType,
|
||||
AdvertiseDesc: ad.AdvertiseDesc,
|
||||
PageType: ad.PageType,
|
||||
StartTimeStamp: ad.StartTimeStamp,
|
||||
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,
|
||||
}
|
||||
}
|
||||
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: //弹窗
|
||||
resp.DialogList = ads
|
||||
case 2: // 应用
|
||||
|
||||
resp.NineGridList = ads
|
||||
case 3: // 横幅
|
||||
resp.DetailbannerList = ads
|
||||
|
||||
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:
|
||||
resp.AList = ads
|
||||
data.AppInfoAList = append(data.AppInfoAList, info)
|
||||
case 13:
|
||||
resp.BList = ads
|
||||
data.AppInfoBList = append(data.AppInfoBList, info)
|
||||
}
|
||||
}
|
||||
|
||||
CacheMgr.Lock.Lock()
|
||||
defer CacheMgr.Lock.Unlock()
|
||||
CacheMgr.Advitise = resp
|
||||
CacheMgr.AdvitiseMap = adMap
|
||||
}
|
||||
|
||||
func GetAdvertiseLocation(adverId string) (res adcenter.AdCacheInfo) {
|
||||
CacheMgr.Lock.RLock()
|
||||
defer CacheMgr.Lock.RUnlock()
|
||||
if ad, ok := CacheMgr.AdvitiseMap[adverId]; ok {
|
||||
res = ad
|
||||
}
|
||||
return
|
||||
CacheMgr.Advitise = data
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/netutil"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/dataReport"
|
||||
"videoweb/pub/models/announcementmod"
|
||||
"videoweb/pub/models/cfg"
|
||||
"videoweb/pub/models/ipblackmod"
|
||||
@@ -61,16 +60,15 @@ func init() {
|
||||
|
||||
func Start() {
|
||||
ctx := context.Background()
|
||||
dataReport.StartSDKConfigCron()
|
||||
UpdateConfigInfo(ctx)
|
||||
UpdateAdvitiseDataFromJt()
|
||||
UpdateAdvitiseData(ctx)
|
||||
updateIpBlack()
|
||||
updateTagsCache()
|
||||
updateAppRichTexts()
|
||||
updateAnnouncements()
|
||||
_, _ = skdCron.AddFunc("0 */5 * * * ?", func() {
|
||||
UpdateConfigInfo(ctx)
|
||||
UpdateAdvitiseDataFromJt()
|
||||
UpdateAdvitiseData(ctx)
|
||||
updateIpBlack()
|
||||
updateTagsCache()
|
||||
updateAppRichTexts()
|
||||
@@ -155,7 +153,6 @@ func UpdateConfigInfo(ctx context.Context) {
|
||||
config.DHSiteName = sysCfg.DHSiteName
|
||||
config.DHTitle = sysCfg.DHTitle
|
||||
config.ActressBackGround = netutil.MergeURL(sysCfg.ImgAppCdn, sysCfg.ActressBackGround)
|
||||
config.ReportSDKConfig = dataReport.GetSDKDomainConfig()
|
||||
config.WatermarkImage = sysCfg.WatermarkImage
|
||||
config.CustomerServiceHost = sysCfg.CustomerServiceHost
|
||||
config.ChannelCode = sysCfg.ChannelCode
|
||||
@@ -563,7 +560,6 @@ func GetVideoTagCategoryDataList() []proto.VideoTagCategoryData {
|
||||
return rsl
|
||||
}
|
||||
func Stop() {
|
||||
dataReport.StopSDKConfigCron()
|
||||
skdCron.Stop()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user