Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+222
View File
@@ -0,0 +1,222 @@
package adser
import (
"errors"
"fmt"
"net/http"
"strconv"
"time"
"91porn-server/app/appg"
"91porn-server/common"
"91porn-server/common/constant/redisconst"
"91porn-server/common/httputil"
"91porn-server/common/log"
"91porn-server/models/commod"
"github.com/vmihailenco/msgpack/v5"
)
/*
福利-游戏广告 100001 GameAppList
福利-直播广告 100002 ZbAppList
福利-炮台广告 100003 YpAppList
福利-棋牌广告 100004 QpAppList
福利-视频广告 100005
福利-横版广告 100006 HengAppList
福利-横一广告 100007
福利-竖版广告 100008 ShuAppList
福利-文字广告 100009
福利-Banner广告 100099 AdvList
*/
const (
AdPosGame = 100001 // 游戏
AdPosZhiBo = 100002 // 直播
AdPosPaoTai = 100003 // 约炮
AdPosQiPai = 100004 // 棋牌
AdPosShiPin = 100005 // 视频
AdPosHeng = 100006 // 横
AdPosHeng1 = 100007 // 横1
AdPosShu = 100008 // 竖
AdPosWenZi = 100009 // 文字
AdPosAds = 100099 // BANNER广告
)
// RecreationListRes 娱乐广告列表请求返回
type RecreationListRes struct {
HengAppList []AppInfo `json:"hengApp" bson:"hengApp"`
ShuAppList []AppInfo `json:"shuApp" bson:"shuApp"`
AdvList []AdvInfo `json:"adv" bson:"adv"`
GameAppList []AppInfo `json:"gameApp" bson:"gameApp"` // 游戏
YpAppList []AppInfo `json:"ypApp" bson:"ypApp"` // 约炮
QpAppList []AppInfo `json:"qpApp" bson:"qpApp"` // 棋牌
ZbAppList []AppInfo `json:"zbApp" bson:"zbApp"` // 直播
}
type CommonListRes struct {
Code int64 `json:"code"`
Data RecreationListRes `json:"data"`
Msg string `json:"msg"`
Time string `json:"time"`
Tip string `json:"tip"`
}
// AppInfo 娱乐app实体信息
type AppInfo struct {
Id string `json:"id"` // ID
Name string `json:"name"` // 应用名称
Desc string `json:"desc"` // 应用描述
Icon string `json:"icon"` // 应用图标
Url string `json:"url"` // 应用链接
Type string `json:"type"` // 应用类型
DownloadNum int64 `json:"downloadNum"` // 应用下载次数
//广告-集团上报数据
Position int `json:"position"` // 集团广告code
PositionName string `json:"positionName"` // 集团广告名称
}
// AdvInfo 娱乐广告实体信息
type AdvInfo struct {
Id string `json:"id"` // ID
Name string `json:"name"` // 广告名称
Image string `json:"image"` // 广告图片
Url string `json:"url"` // 广告链接
Location string `json:"location"` // 位置 1:顶部 2:底部
ModuleType int `json:"moduleType"` // 广告模块 1:应用 2:游戏 3:约炮 4:棋牌 5:直播
//广告-集团上报数据
Position int `json:"position"` // 集团广告code
PositionName string `json:"positionName"` // 集团广告名称
}
// RecreationClickInfo 娱乐广告点击参数信息
type RecreationClickInfo struct {
Id string `form:"id" json:"id" binding:"required"` // 数据id
Type string `form:"type" json:"type" binding:"required"` // 数据类型,app or adv
SysType string `form:"sysType" json:"sysType" binding:"required"` // 用户设备类型. ios or android
}
// RecreationThreeServer 娱乐广告列表,数据来源于导航站(navigate)
func RecreationThreeServer() (RecreationListRes, error) {
str, err := appg.Redis.Get(redisconst.NavigateRecreationCache)
if err != nil {
log.Warn(fmt.Sprintf("缓存获取娱乐广告信息异常:%v", err))
return RecreationListRes{}, err
}
var resp CommonListRes
if str != nil && *str != "" {
if err = msgpack.Unmarshal([]byte(*str), &resp); err == nil {
return resp.Data, nil
}
log.Warn(fmt.Sprintf("娱乐广告解析缓存数据异常:%v", err))
}
//请求url
url := appg.Conf.URL.NavigateUrl + "/api/application/list/" + strconv.FormatInt(int64(commod.KFK_APPID), 10)
//请求
code, err := httputil.DefaultClientPostJsonWithResp(&resp, url, nil, nil)
if err != nil {
log.Error("RecreationThreeServer POSTWithJResp", log.Any("url", url), log.E(err))
return resp.Data, err
}
if code != http.StatusOK {
log.Error("RecreationThreeServer response status", log.Any("code", code))
return resp.Data, errors.New("response status err")
}
if len(resp.Data.AdvList) > 0 || len(resp.Data.HengAppList) > 0 || len(resp.Data.ShuAppList) > 0 ||
len(resp.Data.GameAppList) > 0 || len(resp.Data.YpAppList) > 0 || len(resp.Data.QpAppList) > 0 || len(resp.Data.ZbAppList) > 0 {
common.Go(func() {
data, err := msgpack.Marshal(resp)
if err != nil {
log.Warn(fmt.Sprintf("娱乐广告json序列化缓存数据异常:%v", err))
return
}
if err = appg.Redis.Set(redisconst.NavigateRecreationCache, data, 6*time.Minute); err != nil {
log.Warn(fmt.Sprintf("娱乐广告保存缓存数据异常:%v", err))
return
}
})
}
return resp.Data, nil
}
// RecreationClick 娱乐广告点击记录,请求第三方(navigate)
func RecreationClick(p RecreationClickInfo) {
//请求url
url := appg.Conf.URL.NavigateUrl + "/api/application/click"
//请求
res, err := httputil.DefaultClientPostJson(url, nil, p)
if err != nil {
log.Error("RecreationClick POSTWithJResp", log.Any("url", url), log.E(err))
return
}
if res.StatusCode != http.StatusOK {
log.Error("RecreationClick response status", log.Any("code", res.StatusCode))
return
}
}
// RecreationFromJt 从广告中心拉取福利页广告
func RecreationFromJt() (RecreationListRes, error) {
var resp RecreationListRes
jtAds, err := JtAdvertiseThreeServer()
if err != nil {
log.Error("JtAdvertiseThreeServer error occur", log.E(err))
return resp, err
}
for _, loc := range jtAds {
pos, err := strconv.Atoi(loc.AdvertiseLocationCode)
if err != nil {
log.Error("广告位置代码错误,必须为数字", log.Any("code", loc.AdvertiseLocationCode))
continue
}
if pos < AdPosGame {
continue
}
for _, ad := range loc.AdDetailInfoList {
extra := ad.GetExtraData()
if pos == AdPosAds {
resp.AdvList = append(resp.AdvList, AdvInfo{
Id: ad.AdvertiseCode,
Name: ad.AdvertiseName,
Image: ad.GetCoverLsj(),
Url: ad.GetRealLink(nil, nil),
Location: extra.Location,
ModuleType: ad.GetAdvertiseType(),
Position: pos,
PositionName: loc.AdvertiseLocationName,
})
continue
}
appInfo := AppInfo{
Id: ad.AdvertiseCode,
Name: ad.AdvertiseName,
Desc: ad.AdvertiseDesc,
Icon: ad.GetCoverLsj(),
Url: ad.GetRealLink(nil, nil),
Type: extra.Type,
DownloadNum: extra.DownloadCount,
Position: pos,
PositionName: loc.AdvertiseLocationName,
}
switch pos {
case AdPosGame:
resp.GameAppList = append(resp.GameAppList, appInfo)
case AdPosZhiBo:
resp.ZbAppList = append(resp.ZbAppList, appInfo)
case AdPosPaoTai:
resp.YpAppList = append(resp.YpAppList, appInfo)
case AdPosQiPai:
resp.QpAppList = append(resp.QpAppList, appInfo)
case AdPosHeng:
resp.HengAppList = append(resp.HengAppList, appInfo)
case AdPosShu:
resp.ShuAppList = append(resp.ShuAppList, appInfo)
}
}
}
return resp, nil
}