Compare commits
6
Commits
67ef19aa82
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a21a5d393 | ||
|
|
7392098364 | ||
|
|
ad2ad35574 | ||
|
|
f63a5148f5 | ||
|
|
5c5f5908aa | ||
|
|
75a0d00258 |
@@ -0,0 +1,31 @@
|
||||
package adsapi
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"videoweb/app/api/proto"
|
||||
"videoweb/app/service/configser"
|
||||
"videoweb/pub/common"
|
||||
"videoweb/pub/common/srvdef"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Click 广告点击上报
|
||||
// @Tags 广告
|
||||
// @Summary 广告点击上报
|
||||
// @Description 用户点击广告时异步上报到广告中心。请求可带 appId 覆盖默认,缺省时按本站 appId 上报。
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body proto.AdsClickInfo true "参数"
|
||||
// @Success 200 {string} json
|
||||
// @Router /api/app/ads/click [POST]
|
||||
func Click(c *gin.Context) {
|
||||
var req proto.AdsClickInfo
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
configser.AsyncAdvertiseClick(strconv.FormatInt(req.AdsId, 10), int32(req.AppId))
|
||||
common.ServerJSON(c, srvdef.Success, nil)
|
||||
}
|
||||
+3
-2
@@ -4,8 +4,8 @@ redis:
|
||||
passwd: "Redis@fish2026!"
|
||||
subscribe: true
|
||||
mongodb:
|
||||
addr: "mongodb://web_wzhgdj:AvefivXVdsmMHbfda13af@172.104.56.78:47018,172.104.56.119:47018,172.104.56.146:47018/web_wzhgdj?replicaSet=web_jiqun3&maxPoolSize=200&connectTimeout=30&authSource=admin"
|
||||
logaddr: "mongodb://web_wzhgdj:AvefivXVdsmMHbfda13af@172.104.56.78:47018,172.104.56.119:47018,172.104.56.146:47018/web_wzhgdj_log?replicaSet=web_jiqun3&maxPoolSize=200&connectTimeout=30&authSource=admin"
|
||||
addr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2"
|
||||
logaddr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2_log?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2"
|
||||
es:
|
||||
addr: "http://139.162.47.194:9200"
|
||||
user: "elastic"
|
||||
@@ -29,6 +29,7 @@ listenAddr: "20021"
|
||||
origDomain: "https://yuan.bbaazz.me/"
|
||||
trustedProxies: ""
|
||||
bucketVideoAddressV2: "http://139.162.27.29:19996"
|
||||
versionUrl: "http://139.162.47.194:8089"
|
||||
upAppId: 8
|
||||
lsjMediaConf:
|
||||
appId: "430696"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -122,6 +122,7 @@ func registeRouter(r *gin.Engine) {
|
||||
translationRouter(r)
|
||||
navigationRouter(r)
|
||||
statcenterRouter(r)
|
||||
adsRouter(r)
|
||||
r.GET("/notpage", templatecache.WithCache(time.Minute*1), home.PageNotFound)
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -2,60 +2,112 @@ package configser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"videoweb/app/appg"
|
||||
"videoweb/pub/common/httputil"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/netutil"
|
||||
"videoweb/pub/pubdef"
|
||||
"videoweb/pub/storage"
|
||||
"videoweb/pub/storage/proxy"
|
||||
)
|
||||
|
||||
// UpdateAdvitiseData 从媒资中心按 AppId 拉取广告,图片拼接 CDN 后写入缓存
|
||||
func UpdateAdvitiseData(ctx context.Context) {
|
||||
config := GetConfigInfo()
|
||||
queryAdvitiseReq := &proxy.AppAdvitiseInfoReq{
|
||||
Id: pubdef.AppId,
|
||||
}
|
||||
advitiseResult, err := storage.QueryAdvitiseList(ctx, queryAdvitiseReq, "")
|
||||
if err != nil || advitiseResult.Code != http.StatusOK {
|
||||
if advitiseResult != nil {
|
||||
log.Warn("UpdateAdvitiseData.QueryAdvitiseList failed", log.Any("filter", queryAdvitiseReq), log.E(err), log.Any("respCode", advitiseResult.Code))
|
||||
} else {
|
||||
log.Warn("UpdateAdvitiseData.QueryAdvitiseList failed", log.Any("filter", queryAdvitiseReq), log.E(err))
|
||||
}
|
||||
return
|
||||
// 广告中心应用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"` // 备注描述
|
||||
}
|
||||
|
||||
data := advitiseResult.Data
|
||||
for _, list := range []*[]proxy.AdvitiseInfo{
|
||||
&data.DialogList,
|
||||
&data.HomeList,
|
||||
&data.VideoTopList,
|
||||
&data.VideoDownList,
|
||||
&data.HotAppList,
|
||||
&data.NewAppList,
|
||||
&data.MustAppList,
|
||||
&data.TitleAppList,
|
||||
&data.FriendList,
|
||||
&data.NineGridList,
|
||||
&data.VideoList,
|
||||
&data.StopList,
|
||||
&data.ForcedJumpList,
|
||||
&data.AppInfoAList,
|
||||
&data.AppInfoBList,
|
||||
} {
|
||||
mergeAdvitiseImages(*list, config.ImgCdn)
|
||||
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 {
|
||||
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()
|
||||
defer CacheMgr.Lock.Unlock()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,14 +123,14 @@ func GetM3U8Ex(ctx *gin.Context) {
|
||||
mediaID, expireAt, origM3u8Name, ip, ticket,
|
||||
)
|
||||
|
||||
if !ticketOK {
|
||||
m3u8Name = H5M3U8FallbackPath
|
||||
log.Warn("【GetM3U8Ex】H5播放票据无效",
|
||||
log.Any("mediaId", mediaID),
|
||||
log.Any("expireAt", expireAt),
|
||||
log.Any("ip", ip),
|
||||
log.Any("hasTicket", ticket != ""))
|
||||
}
|
||||
// if !ticketOK {
|
||||
// m3u8Name = H5M3U8FallbackPath
|
||||
// log.Warn("【GetM3U8Ex】H5播放票据无效",
|
||||
// log.Any("mediaId", mediaID),
|
||||
// log.Any("expireAt", expireAt),
|
||||
// log.Any("ip", ip),
|
||||
// log.Any("hasTicket", ticket != ""))
|
||||
// }
|
||||
|
||||
countTowardDailyLimit := ticketOK && ticketInfo.Playable && !ticketInfo.Preview
|
||||
if countTowardDailyLimit && appg.Conf.RunMod == string(consts.RunModeProd) {
|
||||
@@ -152,7 +152,7 @@ func GetM3U8Ex(ctx *gin.Context) {
|
||||
log.Any("vipValid", vipValid),
|
||||
log.E(countErr))
|
||||
} else if cnt > limit {
|
||||
m3u8Name = m3u8RateLimitFallback
|
||||
// m3u8Name = m3u8RateLimitFallback
|
||||
status = "rate_limited"
|
||||
log.Warn("GetM3U8Ex daily rate limit, use fallback m3u8",
|
||||
log.Any("ip", ip),
|
||||
|
||||
@@ -79,6 +79,16 @@ func GetRandomLetters(n int) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// GetRandomAlphanumeric 生成 n 位大小写字母 + 数字随机串
|
||||
func GetRandomAlphanumeric(n int) string {
|
||||
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = chars[rand.IntN(len(chars))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func GetSlugInfo(text string) string {
|
||||
return SanitizeSlug(slug.Make(text))
|
||||
}
|
||||
@@ -114,12 +124,12 @@ func IsSlugAllDigits(s string) bool {
|
||||
}
|
||||
|
||||
// RandomSlugLength 随机 slug 长度
|
||||
const RandomSlugLength = 8
|
||||
const RandomSlugLength = 10
|
||||
|
||||
// MakeRandomSlug 生成唯一的随机 slug(8 位小写字母);exists 返回 true 表示已被占用。
|
||||
// MakeRandomSlug 生成唯一的随机 slug(10 位大小写字母+数字混合);exists 返回 true 表示已被占用。
|
||||
func MakeRandomSlug(exists func(string) bool) string {
|
||||
for {
|
||||
s := strings.ToLower(GetRandomLetters(RandomSlugLength))
|
||||
s := GetRandomAlphanumeric(RandomSlugLength)
|
||||
if !exists(s) {
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
// DefaultKey IndexNow 默认密钥,与站点根目录下的 {key}.txt 验证文件对应
|
||||
const DefaultKey = "6d41643810d540ce924edb982c3d3171"
|
||||
const DefaultKey = "9d16a6eb0062bfcaa98e1238e7c436e0"
|
||||
|
||||
// DefaultSearchEngine 官方入口,会自动分发给 Bing、Yandex 等搜索引擎
|
||||
const DefaultSearchEngine = "https://api.indexnow.org"
|
||||
|
||||
+24
-23
@@ -1,30 +1,35 @@
|
||||
redis:
|
||||
addr: 172.104.181.99:16789
|
||||
addr: 139.162.47.194:6379
|
||||
db: 2
|
||||
passwd: "B6vJHlYiTseLj77z"
|
||||
passwd: "Redis@fish2026!"
|
||||
subscribe: true
|
||||
mongodb:
|
||||
addr: "mongodb://admin:TESTwfeZYP0kjBdy8DAUdwU@172.104.181.99:57017,172.104.181.99:57018,172.104.181.99:57019/web_91ys?replicaSet=yctest&maxPoolSize=200&connectTimeout=30&authSource=admin"
|
||||
logaddr: "mongodb://admin:TESTwfeZYP0kjBdy8DAUdwU@172.104.181.99:57017,172.104.181.99:57018,172.104.181.99:57019/web_91ys_log?replicaSet=yctest&maxPoolSize=200&connectTimeout=30&authSource=admin"
|
||||
addr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2"
|
||||
logaddr: "mongodb://web_huangguo2:xDdEkf6m0HDpkEpxpphi@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/web_huangguo2_log?replicaSet=fish0&maxPoolSize=200&connectTimeout=30&authSource=web_huangguo2"
|
||||
es:
|
||||
addr: "http://172.104.181.99:9200"
|
||||
addr: "http://139.162.47.194:9200"
|
||||
user: "elastic"
|
||||
pass: "admin123456"
|
||||
pass: "Es@fish2026!"
|
||||
httpOptions:
|
||||
dcCtxTimeOut: 10
|
||||
jwtKey: "2311b15a4da1c80dc541b99abb622233"
|
||||
tgToken: ""
|
||||
runMod: "dev"
|
||||
runMod: "prod"
|
||||
resKey: "vEukA&w15z4VAD3kAY#fkL#rBnU!WDhN"
|
||||
cdnKey: "vEukAw15z4VAD3kAYfkLrBnUWDhN123"
|
||||
tsAuthKey: "fT5xSg4hltHpzVy6aV9rVECDJ1J1pN"
|
||||
tgToken: ""
|
||||
attack:
|
||||
enable: false
|
||||
appkey: "kaFtkDJRcchRMTI9"
|
||||
h5key: "kaFttDJRcahRMTI7"
|
||||
windowDurationSeconds: 60
|
||||
pprof: false
|
||||
host: "172.104.181.99"
|
||||
listenAddr: "25120"
|
||||
prefetchSubmitUrl: "http://172.104.171.80:9067/master/submit"
|
||||
aiCenterAppId: 25311
|
||||
aiUndressingCallbackUrl: "https://web_mdcomtest-ht.80sygtm.com/api/web/aiorder/strip/callback"
|
||||
host: "172.104.166.87"
|
||||
listenAddr: "20022"
|
||||
origDomain: "https://yuan.bbaazz.me/"
|
||||
trustedProxies: ""
|
||||
bucketVideoAddressV2: "http://139.162.27.29:19996"
|
||||
upAppId: 8
|
||||
swagger:
|
||||
host: "172.104.181.99"
|
||||
user: "mdc"
|
||||
pass: "2@6A1#9e%9c2"
|
||||
bucketVideoAddressV2: "http://139.162.22.207:24996"
|
||||
lsjMediaConf:
|
||||
appId: "430696"
|
||||
apiKey: "ed48e96ce490bc94bd5eb5133dd542d0"
|
||||
@@ -34,12 +39,8 @@ lsjMediaConf:
|
||||
m3u8Yuan: "https://zhlsaj.zrr4ij4.site"
|
||||
tsYuan: "https://tssdaa.hlvwcn.cn"
|
||||
|
||||
# 媒资配置
|
||||
mediaResourceDBCfg:
|
||||
baseUrl: "https://mediav2-api.htycpc.com"
|
||||
merchat: "91porn"
|
||||
secret: "08f1c3ab5e11e9b6c18aa24c06d1eb77"
|
||||
|
||||
playletMediaResourceDBCfg:
|
||||
baseUrl: "https://mediav2-api.htycpc.com"
|
||||
merchat: "91porn"
|
||||
secret: "08f1c3ab5e11e9b6c18aa24c06d1eb77"
|
||||
Reference in New Issue
Block a user