Compare commits
4
Commits
71a4f4e175
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c40daf9c5 | ||
|
|
eb8840a3af | ||
|
|
addf0691b3 | ||
|
|
b2ff6ac8ff |
@@ -9,3 +9,9 @@ tool
|
|||||||
*.tar.xz
|
*.tar.xz
|
||||||
# Google 服务账号私钥(Indexing API),只能随部署单独投放,禁止入库。
|
# Google 服务账号私钥(Indexing API),只能随部署单独投放,禁止入库。
|
||||||
composed-anvil-*.json
|
composed-anvil-*.json
|
||||||
|
|
||||||
|
# 生产配置与密钥文件(含凭证,仅本地保留,禁止入库)
|
||||||
|
app/conf/app.yaml
|
||||||
|
web/conf/web.yaml
|
||||||
|
app/conf/*.key
|
||||||
|
web/conf/*.key
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
+4
-147
@@ -1,11 +1,9 @@
|
|||||||
package authapi
|
package authapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"videoweb/app/service/authser"
|
"videoweb/app/service/authser"
|
||||||
"videoweb/app/service/wordsfilterser"
|
"videoweb/app/service/wordsfilterser"
|
||||||
"videoweb/pub/common"
|
"videoweb/pub/common"
|
||||||
"videoweb/pub/common/ipaddr"
|
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/common/useragent"
|
"videoweb/pub/common/useragent"
|
||||||
"videoweb/pub/pubdef"
|
"videoweb/pub/pubdef"
|
||||||
@@ -18,132 +16,17 @@ func requestUA(ctx *gin.Context) useragent.UA {
|
|||||||
return ua
|
return ua
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyRequestDevID(ua useragent.UA, devID string) useragent.UA {
|
|
||||||
if v := strings.TrimSpace(devID); v != "" {
|
|
||||||
ua.DevID = v
|
|
||||||
}
|
|
||||||
return ua
|
|
||||||
}
|
|
||||||
|
|
||||||
type registerReq struct {
|
|
||||||
AccountNo string `json:"accountNo" binding:"required"` // 账号
|
|
||||||
Email string `json:"email"` // 邮箱(可选)
|
|
||||||
Password string `json:"password" binding:"required"` // 明文密码
|
|
||||||
AgentInviteCode string `json:"agentInviteCode"` // 邀请人的邀请码(可选)
|
|
||||||
DevID string `json:"devID"` // 设备唯一标示(可选)
|
|
||||||
Channel string `json:"channel"` // 渠道码(可选,用户无商区码时写入)
|
|
||||||
}
|
|
||||||
|
|
||||||
type loginReq struct {
|
|
||||||
Account string `json:"account" binding:"required"` // 账号或邮箱
|
|
||||||
Password string `json:"password" binding:"required"` // 明文密码
|
|
||||||
DevID string `json:"devID"` // 设备唯一标示(可选)
|
|
||||||
Channel string `json:"channel"` // 渠道码(可选,用户无商区码时写入)
|
|
||||||
}
|
|
||||||
|
|
||||||
type resetPasswordReq struct {
|
|
||||||
AccountNo string `json:"accountNo" binding:"required"` // 账号
|
|
||||||
Email string `json:"email" binding:"required"` // 邮箱
|
|
||||||
NewPassword string `json:"newPassword" binding:"required"` // 新密码
|
|
||||||
}
|
|
||||||
|
|
||||||
type updateProfileReq struct {
|
type updateProfileReq struct {
|
||||||
NickName *string `json:"nickName"` // 新昵称(可选)
|
NickName *string `json:"nickName"` // 新昵称(可选)
|
||||||
Avatar *string `json:"avatar"` // 新头像 URL(可选)
|
Avatar *string `json:"avatar"` // 新头像 URL(可选)
|
||||||
Introduction *string `json:"introduction"` // 简介(可选)
|
Introduction *string `json:"introduction"` // 简介(可选)
|
||||||
PrivacyMode *bool `json:"privacyMode"` // 隐私模式:true-开启,false-关闭(可选)
|
PrivacyMode *bool `json:"privacyMode"` // 隐私模式:true-开启,false-关闭(可选)
|
||||||
OldPassword *string `json:"oldPassword"` // 旧密码明文(已设置密码时修改必填)
|
|
||||||
NewPassword *string `json:"newPassword"` // 新密码明文(设置或修改密码时必填)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GuestLogin 游客登录
|
|
||||||
// @Tags 用户认证
|
|
||||||
// @Summary 游客登录
|
|
||||||
// @Description 按设备ID创建或找回游客账号;请求头可带 Authorization 复用已有游客会话。需传 X-User-Agent
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param param body authser.GuestLoginReq true "游客登录参数"
|
|
||||||
// @Success 200 {object} authser.LoginResp "成功"
|
|
||||||
// @Failure 400 {string} string "失败"
|
|
||||||
// @Router /api/app/auth/guest [POST]
|
|
||||||
func GuestLogin(ctx *gin.Context) {
|
|
||||||
var req authser.GuestLoginReq
|
|
||||||
if err := ctx.ShouldBind(&req); err != nil {
|
|
||||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua, err := common.GetUA(ctx)
|
|
||||||
if err != nil {
|
|
||||||
common.ServerJSON(ctx, srvdef.NoUA, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.DevID == "" {
|
|
||||||
common.ServerJSON(ctx, srvdef.ErrParamError, "devID不能为空")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua.DevID = req.DevID
|
|
||||||
resp, serr := authser.GuestLogin(ctx, common.GetUserId(ctx), ipaddr.ResolveClientIP(ctx), &req, ua)
|
|
||||||
if serr != nil {
|
|
||||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register 用户注册
|
|
||||||
// @Tags 用户认证
|
|
||||||
// @Summary 注册
|
|
||||||
// @Description 传入账号和明文密码,邮箱可选,请求头带游客 Authorization 时升级该游客为普通用户,否则新建用户
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param param body registerReq true "注册参数"
|
|
||||||
// @Success 200 {object} authser.LoginResp "注册成功,返回 token 及用户基本信息"
|
|
||||||
// @Failure 400 {string} string "失败"
|
|
||||||
// @Router /api/app/auth/register [POST]
|
|
||||||
func Register(ctx *gin.Context) {
|
|
||||||
var req registerReq
|
|
||||||
if err := ctx.ShouldBind(&req); err != nil {
|
|
||||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua := applyRequestDevID(requestUA(ctx), req.DevID)
|
|
||||||
resp, serr := authser.Register(ctx, common.GetUserId(ctx), req.AccountNo, req.Email, req.Password, req.AgentInviteCode, ua, ipaddr.ResolveClientIP(ctx), req.Channel)
|
|
||||||
if serr != nil {
|
|
||||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Login 用户登录
|
|
||||||
// @Tags 用户认证
|
|
||||||
// @Summary 登录
|
|
||||||
// @Description 账号或邮箱均可作为登录凭证
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param param body loginReq true "登录参数"
|
|
||||||
// @Success 200 {object} authser.LoginResp "登录成功,返回 token 及用户基本信息"
|
|
||||||
// @Failure 400 {string} string "失败"
|
|
||||||
// @Router /api/app/auth/login [POST]
|
|
||||||
func Login(ctx *gin.Context) {
|
|
||||||
var req loginReq
|
|
||||||
if err := ctx.ShouldBind(&req); err != nil {
|
|
||||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua := applyRequestDevID(requestUA(ctx), req.DevID)
|
|
||||||
resp, serr := authser.Login(ctx, req.Account, req.Password, ua, ipaddr.ResolveClientIP(ctx), req.Channel)
|
|
||||||
if serr != nil {
|
|
||||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateProfile 修改用户资料
|
// UpdateProfile 修改用户资料
|
||||||
// @Tags 用户认证
|
// @Tags 用户认证
|
||||||
// @Summary 修改用户资料(头像 / 简介 / 密码,可任意组合)
|
// @Summary 修改用户资料(昵称 / 头像 / 简介 / 隐私模式,可任意组合)
|
||||||
// @Description 用户信息通过 token 获取,无需传账号;nickName、avatar、introduction、oldPassword+newPassword 均为可选,至少提供一项。未设置密码时传 newPassword 可设置密码,已设置密码时修改需传 oldPassword+newPassword
|
// @Description 按请求头 X-User-Agent 中的 devID 识别用户;nickName、avatar、introduction、privacyMode 均为可选,至少提供一项。
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param param body updateProfileReq true "修改资料参数"
|
// @Param param body updateProfileReq true "修改资料参数"
|
||||||
@@ -171,8 +54,6 @@ func UpdateProfile(ctx *gin.Context) {
|
|||||||
Avatar: req.Avatar,
|
Avatar: req.Avatar,
|
||||||
Introduction: req.Introduction,
|
Introduction: req.Introduction,
|
||||||
PrivacyMode: req.PrivacyMode,
|
PrivacyMode: req.PrivacyMode,
|
||||||
OldPassword: req.OldPassword,
|
|
||||||
NewPassword: req.NewPassword,
|
|
||||||
})
|
})
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
||||||
@@ -184,7 +65,7 @@ func UpdateProfile(ctx *gin.Context) {
|
|||||||
// GetInfo 获取当前用户信息
|
// GetInfo 获取当前用户信息
|
||||||
// @Tags 用户认证
|
// @Tags 用户认证
|
||||||
// @Summary 获取当前用户信息
|
// @Summary 获取当前用户信息
|
||||||
// @Description 通过 token 获取最新用户信息,包含金币余额、VIP状态等
|
// @Description 按请求头 X-User-Agent 中的 devID 识别用户,返回最新用户信息,包含金币余额、VIP状态等
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} authser.LoginResp "用户信息"
|
// @Success 200 {object} authser.LoginResp "用户信息"
|
||||||
// @Failure 400 {string} string "失败"
|
// @Failure 400 {string} string "失败"
|
||||||
@@ -192,7 +73,7 @@ func UpdateProfile(ctx *gin.Context) {
|
|||||||
func GetInfo(ctx *gin.Context) {
|
func GetInfo(ctx *gin.Context) {
|
||||||
userId := common.GetUserId(ctx)
|
userId := common.GetUserId(ctx)
|
||||||
if pubdef.IsCrawlerUser(userId) {
|
if pubdef.IsCrawlerUser(userId) {
|
||||||
common.ServerJSON(ctx, srvdef.Success, authser.CrawlerLoginResp(""))
|
common.ServerJSON(ctx, srvdef.Success, authser.CrawlerLoginResp())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
@@ -206,27 +87,3 @@ func GetInfo(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetPassword 找回密码
|
|
||||||
// @Tags 用户认证
|
|
||||||
// @Summary 找回密码
|
|
||||||
// @Description 通过账号和邮箱双重校验后重置密码,两者必须同时匹配同一用户
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param param body resetPasswordReq true "找回密码参数"
|
|
||||||
// @Success 200 {string} string "成功"
|
|
||||||
// @Failure 400 {string} string "失败"
|
|
||||||
// @Router /api/app/auth/resetPassword [POST]
|
|
||||||
func ResetPassword(ctx *gin.Context) {
|
|
||||||
var req resetPasswordReq
|
|
||||||
if err := ctx.ShouldBind(&req); err != nil {
|
|
||||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
serr := authser.ResetPassword(ctx, req.AccountNo, req.Email, req.NewPassword)
|
|
||||||
if serr != nil {
|
|
||||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
common.ServerJSON(ctx, srvdef.Success, "")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ func Info(ctx *gin.Context) {
|
|||||||
SeoInfo: configser.GetSiteSeoInfo(),
|
SeoInfo: configser.GetSiteSeoInfo(),
|
||||||
SeoNavInfo: configser.GetNavSeoInfo(),
|
SeoNavInfo: configser.GetNavSeoInfo(),
|
||||||
NavPageList: configser.GetNavPageList(),
|
NavPageList: configser.GetNavPageList(),
|
||||||
ReportSDKConfig: configInfo.ReportSDKConfig,
|
|
||||||
}
|
}
|
||||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-19
@@ -13,22 +13,5 @@ type AdsClickInfo struct {
|
|||||||
Location int64 `json:"location,omitempty" binding:"required"` // 位置ID
|
Location int64 `json:"location,omitempty" binding:"required"` // 位置ID
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdvitiseData struct {
|
// AdvitiseData 广告数据,直接使用媒资中心返回的结构
|
||||||
HomeList []proxy.AdvitiseInfo `json:"homeList" bson:"homeList"` // 首页列表
|
type AdvitiseData = proxy.AdvitiseData
|
||||||
DetailTopList []proxy.AdvitiseInfo `json:"detailTopList" bson:"detailTopList"` // 详情页顶部广告
|
|
||||||
NineGridList []proxy.AdvitiseInfo `json:"nineGridList" bson:"nineGridList"` // 9宫格
|
|
||||||
DetailbannerList []proxy.AdvitiseInfo `json:"detailbannerList" bson:"detailbannerList"` // 详情banner
|
|
||||||
LaunchScreenList []proxy.AdvitiseInfo `json:"launchScreenList"` // 启动页广告
|
|
||||||
FloatingList []proxy.AdvitiseInfo `json:"floatingList" bson:"floatingList"` // 悬浮小方块
|
|
||||||
AList []proxy.AdvitiseInfo `json:"AList"` // 固定12广告位
|
|
||||||
BList []proxy.AdvitiseInfo `json:"BList"` // 固定13广告位
|
|
||||||
DialogList []proxy.AdvitiseInfo `json:"dialogList" bson:"dialogList"` // 弹窗广告
|
|
||||||
BottomBanner []proxy.AdvitiseInfo `json:"bottomBanner" bson:"bottomBanner"` // 底部banner
|
|
||||||
|
|
||||||
VideoInfoList []proxy.AdvitiseInfo `json:"videoInfoList" bson:"videoInfoList"` // 视频详情
|
|
||||||
DownList []proxy.AdvitiseInfo `json:"downList" bson:"downList"` // 底部广告
|
|
||||||
FriendList []proxy.AdvitiseInfo `json:"friendList" bson:"friendList"` // 友链
|
|
||||||
TitleList []proxy.AdvitiseInfo `json:"titleList" bson:"titleList"` // 标题广告
|
|
||||||
PlayList []proxy.AdvitiseInfo `json:"playList" bson:"playList"` // 播放强制跳转
|
|
||||||
PauseyList []proxy.AdvitiseInfo `json:"pauseyList" bson:"pauseyList"` // 暂停广告
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ type ConfigInfo struct {
|
|||||||
DHDescription string `json:"dhDescription" bson:"dhDescription"` // 导航SEO描述
|
DHDescription string `json:"dhDescription" bson:"dhDescription"` // 导航SEO描述
|
||||||
DHSiteName string `json:"dhSiteName" bson:"dhSiteName"` // 导航SEO网站名称
|
DHSiteName string `json:"dhSiteName" bson:"dhSiteName"` // 导航SEO网站名称
|
||||||
ActressBackGround string `json:"actressBackGround" bson:"actressBackGround"` // 女优通用背景图
|
ActressBackGround string `json:"actressBackGround" bson:"actressBackGround"` // 女优通用背景图
|
||||||
ReportSDKConfig string `json:"reportSdkConfig"` // 数据上报SDK域名配置
|
|
||||||
WatermarkImage string `json:"watermarkImage"` // 图片水印文件
|
WatermarkImage string `json:"watermarkImage"` // 图片水印文件
|
||||||
CustomerServiceHost string `json:"customerServiceHost"` // 在线客服
|
CustomerServiceHost string `json:"customerServiceHost"` // 在线客服
|
||||||
ChannelCode string `json:"channelCode"` // 渠道码
|
ChannelCode string `json:"channelCode"` // 渠道码
|
||||||
@@ -66,8 +65,6 @@ type ConfigInfoResp struct {
|
|||||||
SeoNavInfo SeoNavInfo `json:"seoNavInfo"`
|
SeoNavInfo SeoNavInfo `json:"seoNavInfo"`
|
||||||
// 导航页线路集合
|
// 导航页线路集合
|
||||||
NavPageList []NavPageItem `json:"navPageList"`
|
NavPageList []NavPageItem `json:"navPageList"`
|
||||||
// 数据上报SDK域名配置
|
|
||||||
ReportSDKConfig string `json:"reportSdkConfig"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SeoNavInfo 导航SEO信息
|
// SeoNavInfo 导航SEO信息
|
||||||
|
|||||||
@@ -109,9 +109,6 @@ type GlobalCfgEx struct {
|
|||||||
AppCode string `yaml:"appCode"` // 应用 code
|
AppCode string `yaml:"appCode"` // 应用 code
|
||||||
AesKey string `yaml:"aesKey"` // 数据解密KEY
|
AesKey string `yaml:"aesKey"` // 数据解密KEY
|
||||||
} `yaml:"adCenter"`
|
} `yaml:"adCenter"`
|
||||||
DataReport struct {
|
|
||||||
Url string `yaml:"url"`
|
|
||||||
} `yaml:"dataReport"`
|
|
||||||
LsjMediaConf struct {
|
LsjMediaConf struct {
|
||||||
AppId string `yaml:"appId"`
|
AppId string `yaml:"appId"`
|
||||||
ApiKey string `yaml:"apiKey"`
|
ApiKey string `yaml:"apiKey"`
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
redis:
|
|
||||||
addr: "172.104.181.99:16789"
|
|
||||||
db: 2
|
|
||||||
passwd: "B6vJHlYiTseLj77z"
|
|
||||||
subscribe: true
|
|
||||||
mongodb:
|
|
||||||
addr: "mongodb://admin:TESTwfeZYP0kjBdy8DAUdwU@172.104.181.99:57017,172.104.181.99:57018,172.104.181.99:57019/web_qmdj?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_qmdj_log?replicaSet=yctest&maxPoolSize=200&connectTimeout=30&authSource=admin"
|
|
||||||
es:
|
|
||||||
addr: "http://172.104.181.99:9200"
|
|
||||||
user: "elastic"
|
|
||||||
pass: "admin123456"
|
|
||||||
httpOptions:
|
|
||||||
dcCtxTimeOut: 10
|
|
||||||
jwtKey: "2311b15a4da1c80dc541b99abb622233"
|
|
||||||
runMod: "debug"
|
|
||||||
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: "25119"
|
|
||||||
origDomain: "https://yuan.bbaazz.me/"
|
|
||||||
trustedProxies: ""
|
|
||||||
bucketVideoAddressV2: "http://139.162.22.207:24996"
|
|
||||||
transactionUrl: "https://bill.ruishengces.com"
|
|
||||||
newPayCenter:
|
|
||||||
appName: ""
|
|
||||||
callbackUrl: ""
|
|
||||||
apiUrl: ""
|
|
||||||
mercID: ""
|
|
||||||
mercSecret: ""
|
|
||||||
adCenter:
|
|
||||||
apiDomain: "https://adopenapi.adcs01.top"
|
|
||||||
merchantCode: "1991129808640122880"
|
|
||||||
appCode: "JHA-1009"
|
|
||||||
aesKey: "gD4+rmbX5TS5cLbb3wAN5uEAYp/1j4hkQrS9SzuSjc8"
|
|
||||||
dataReport:
|
|
||||||
url: "https://api.shuifeng.cc"
|
|
||||||
lsjMediaConf:
|
|
||||||
appId: "430696"
|
|
||||||
apiKey: "ed48e96ce490bc94bd5eb5133dd542d0"
|
|
||||||
apiUrl: "https://zhlsaj.zrr4ij4.site"
|
|
||||||
imageYuan: "https://d1kh52pvweq1c0.cloudfront.net"
|
|
||||||
keyHex: "525202f9149e061d"
|
|
||||||
m3u8Yuan: "https://zhlsaj.zrr4ij4.site"
|
|
||||||
tsYuan: "https://tssdaa.hlvwcn.cn"
|
|
||||||
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
—Џ€И’љБCЏ„
|
|
||||||
+9
-26
@@ -1,28 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
FILE_NAME="web_mdcom_app"
|
|
||||||
REMOTE_FILE_PATH="/home/server2/web_mdcom/app/"
|
|
||||||
TAG_NAME="web_mdcom_app.tar.gz"
|
|
||||||
|
|
||||||
set -e
|
|
||||||
set -o
|
|
||||||
function send_msg() {
|
|
||||||
msg="@jscdsndj @xiuyuan_Lee @steven0yu %0A服务:SERVER2 站点-91spz.com管理服务APP%0A更新内容:$content%0A创建时间: $(date +%F_%X)%0A操作人:$(git config user.name)"
|
|
||||||
curl -X POST "https://api.telegram.org/bot6357085965:AAEmXfjZnZwnDTicL7Wjbd7cXvYv_G98w8A/sendMessage" -d "chat_id=$1&text=$msg" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
read -p "输入yes, 开始上传: " word
|
|
||||||
if [[ ! "yes" =~ $word ]]; then
|
|
||||||
echo "终止"
|
|
||||||
else
|
|
||||||
read -e -p "本次更新内容(输入q退出编辑): " -r content
|
|
||||||
echo "开始"
|
echo "开始"
|
||||||
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
|
rm -rf ./web_hgc_app ./web_hgc_app.tar.gz
|
||||||
GOOS=linux GOARCH=amd64 go build -o $FILE_NAME
|
GOOS=linux GOARCH=amd64 go build -o web_hgc_app
|
||||||
md5sum $FILE_NAME | cut -d ' ' -f1 >yinsemd5.txt
|
tar zvcf web_hgc_app.tar.gz web_hgc_app
|
||||||
tar zvcf $TAG_NAME ./$FILE_NAME yinsemd5.txt
|
|
||||||
md5sum $TAG_NAME | cut -d ' ' -f1 >yinsemd5.txt
|
|
||||||
scp -i ~/.ssh/id_rsa -P 22889 ./yinsemd5.txt server2@116.212.120.2:$REMOTE_FILE_PATH
|
scp web_hgc_app.tar.gz root@172.104.166.87:/data/uzip
|
||||||
scp -i ~/.ssh/id_rsa -P 22889 ./$TAG_NAME server2@116.212.120.2:$REMOTE_FILE_PATH
|
ssh root@172.104.166.87 "/server/web_hgc/app/up_app.sh"
|
||||||
send_msg -4791758991 #服务器小组
|
|
||||||
fi
|
rm -rf ./web_hgc_app ./web_hgc_app.tar.gz
|
||||||
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
sudo make test
|
|
||||||
|
|
||||||
scp -P 22889 web_91av_app.tar.gz root@172.104.181.99:/server/web_91av/app/
|
|
||||||
ssh root@172.104.181.99 -p 22889 "cd /server/web_91av/app/ && /bin/tar -xf /server/web_91av/app/web_91av_app.tar.gz && /usr/bin/supervisorctl restart web_91av_app"
|
|
||||||
if [ $? -eq 0 ];then
|
|
||||||
echo -e "\033[32m 91spz.com H5更新成功 \033[0m"
|
|
||||||
else
|
|
||||||
echo -e "\033[31m 91spz.com H5更新失败 \033[0m"
|
|
||||||
fi
|
|
||||||
rm -f web_91av_app.tar.gz
|
|
||||||
+23
-118
@@ -3,138 +3,43 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"videoweb/app/appg"
|
"videoweb/app/middleware/reptilerecord"
|
||||||
|
"videoweb/app/service/authser"
|
||||||
|
"videoweb/pub/common"
|
||||||
"videoweb/pub/common/enum/consts"
|
"videoweb/pub/common/enum/consts"
|
||||||
|
"videoweb/pub/common/ipaddr"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/common/utils"
|
|
||||||
"videoweb/pub/pubdef"
|
"videoweb/pub/pubdef"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// gin 验证中间件
|
// gin 用户识别中间件:不再校验 token,按 X-User-Agent 中的 devID 识别用户,
|
||||||
|
// 该设备首次访问时自动创建用户。没有 devID 的请求按匿名处理,
|
||||||
var (
|
// 需要用户身份的接口自行返回"请先登录"。
|
||||||
// 白名单,不需要验证token的api
|
|
||||||
whiteList = []string{
|
|
||||||
"/swagger",
|
|
||||||
"/api/app/auth/guest",
|
|
||||||
"/api/app/auth/register",
|
|
||||||
"/api/app/auth/login",
|
|
||||||
"/api/app/auth/resetPassword",
|
|
||||||
"/api/app/video/all/list",
|
|
||||||
"/api/app/video/topic/list",
|
|
||||||
"/api/app/video/list",
|
|
||||||
"/api/app/video/detail",
|
|
||||||
"/api/app/playlet/home",
|
|
||||||
"/api/app/playlet/all/list",
|
|
||||||
"/api/app/playlet/topic/list",
|
|
||||||
"/api/app/playlet/topic/detail",
|
|
||||||
"/api/app/playlet/operate/list",
|
|
||||||
"/api/app/playlet/rank",
|
|
||||||
"/api/app/playlet/hot/rank/list",
|
|
||||||
"/api/app/playlet/today-update",
|
|
||||||
"/api/app/playlet/tag/options",
|
|
||||||
"/api/app/playlet/tag/list",
|
|
||||||
"/api/app/playlet/guess-like/list",
|
|
||||||
"/api/app/playlet/search",
|
|
||||||
"/api/app/playlet/hot-like",
|
|
||||||
"/api/app/playlet/detail",
|
|
||||||
"/api/app/playlet/chapter/detail",
|
|
||||||
"/api/app/recharge/package/list",
|
|
||||||
"/api/app/comment/list",
|
|
||||||
"/api/app/theme/list",
|
|
||||||
"/api/app/config/info",
|
|
||||||
"/api/app/config/footer/info",
|
|
||||||
"/api/app/config/richtext/list",
|
|
||||||
"/api/app/applist",
|
|
||||||
"/api/app/translation/category/list",
|
|
||||||
"/api/app/navigation/header",
|
|
||||||
"/api/app/health/ping",
|
|
||||||
"/api/app/statcenter/sync",
|
|
||||||
"/h5/m3u8",
|
|
||||||
"/enkey",
|
|
||||||
"/newenkey",
|
|
||||||
"/sitemap.xml",
|
|
||||||
"/sitemaps",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
tokener = utils.NewTokenRedis()
|
|
||||||
)
|
|
||||||
|
|
||||||
func Auth(ctx *gin.Context) {
|
func Auth(ctx *gin.Context) {
|
||||||
dotoken := func() srvdef.CodeType {
|
if reptilerecord.IsBot(ctx) {
|
||||||
token := ctx.Request.Header.Get("Authorization")
|
ctx.Set(consts.CtxUserID, pubdef.CrawlerUserId)
|
||||||
// 去掉Bearer,如果有
|
return
|
||||||
token = utils.StripBearerPrefixFromTokenString(token)
|
|
||||||
|
|
||||||
if token == "" {
|
|
||||||
for _, w := range whiteList {
|
|
||||||
if strings.Contains(ctx.Request.URL.Path, w) {
|
|
||||||
return srvdef.Success
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Error("Auth:token is empty", log.Any("sysType", ctx.GetString(consts.CtxSysType)))
|
ua, err := common.GetUA(ctx)
|
||||||
return srvdef.InvalidToken
|
if err != nil || strings.TrimSpace(ua.DevID) == "" {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, newToken, err := utils.ParseUserToken(token, appg.Conf.JwtKey)
|
userId, serr := authser.ResolveDeviceUser(ctx, ua, ipaddr.ResolveClientIP(ctx), ctx.GetHeader("channel"))
|
||||||
if err != nil {
|
if serr != nil {
|
||||||
for _, w := range whiteList {
|
if serr.Code == srvdef.AccountErrAccessForbid {
|
||||||
if strings.Contains(ctx.Request.URL.Path, w) {
|
|
||||||
return srvdef.Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("Auth:ParseUserToken", log.Any("token", token), log.E(err))
|
|
||||||
return srvdef.InvalidToken
|
|
||||||
}
|
|
||||||
|
|
||||||
if pubdef.IsCrawlerUser(userId) {
|
|
||||||
if len(newToken) > 0 {
|
|
||||||
ctx.Writer.Header().Set("Refresh-Authorization", newToken)
|
|
||||||
}
|
|
||||||
ctx.Set(consts.CtxUserID, userId)
|
|
||||||
ctx.Set(consts.CtxToken, token)
|
|
||||||
return srvdef.Success
|
|
||||||
}
|
|
||||||
|
|
||||||
has, err := tokener.Exists(userId, token)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Auth:Exists", log.Any("userId", userId), log.Any("token", token), log.E(err))
|
|
||||||
return srvdef.InvalidToken
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
log.Error("Auth:Exists:token not exists", log.Any("userId", userId), log.Any("token", token), log.E(err))
|
|
||||||
return srvdef.InvalidToken
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(newToken) > 0 {
|
|
||||||
err = tokener.Save(userId, newToken)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Auth:Save", log.Any("userId", userId), log.Any("token", newToken), log.E(err))
|
|
||||||
return srvdef.StoreLevel
|
|
||||||
}
|
|
||||||
ctx.Writer.Header().Set("Refresh-Authorization", newToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set(consts.CtxUserID, userId)
|
|
||||||
ctx.Set(consts.CtxToken, token)
|
|
||||||
|
|
||||||
return srvdef.Success
|
|
||||||
}
|
|
||||||
|
|
||||||
errType := dotoken()
|
|
||||||
if errType != srvdef.Success {
|
|
||||||
// log.Info("Auth bad request", log.Any("Path", ctx.Request.URL.Path), log.Any("ip", ctx.ClientIP()))
|
|
||||||
ctx.AbortWithStatusJSON(http.StatusOK, gin.H{
|
ctx.AbortWithStatusJSON(http.StatusOK, gin.H{
|
||||||
"code": errType,
|
"code": serr.Code,
|
||||||
"msg": errType.Msg(),
|
"msg": serr.Code.Msg(),
|
||||||
})
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
log.Error("Auth:ResolveDeviceUser", log.Any("devID", ua.DevID), log.Any("path", ctx.Request.URL.Path), log.E(serr))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Set(consts.CtxUserID, userId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -9,11 +9,7 @@ import (
|
|||||||
func authRouter(r *gin.Engine) {
|
func authRouter(r *gin.Engine) {
|
||||||
auth := r.Group("/api/app/auth")
|
auth := r.Group("/api/app/auth")
|
||||||
{
|
{
|
||||||
auth.POST("/guest", authapi.GuestLogin)
|
|
||||||
auth.POST("/register", authapi.Register)
|
|
||||||
auth.POST("/login", authapi.Login)
|
|
||||||
auth.GET("/getInfo", authapi.GetInfo)
|
auth.GET("/getInfo", authapi.GetInfo)
|
||||||
auth.POST("/profile", authapi.UpdateProfile)
|
auth.POST("/profile", authapi.UpdateProfile)
|
||||||
auth.POST("/resetPassword", authapi.ResetPassword)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ func registeRouter(r *gin.Engine) {
|
|||||||
navigationRouter(r)
|
navigationRouter(r)
|
||||||
statcenterRouter(r)
|
statcenterRouter(r)
|
||||||
sitemapRouter(r)
|
sitemapRouter(r)
|
||||||
|
adsRouter(r)
|
||||||
r.GET("/notpage", templatecache.WithCache(time.Minute*1), home.PageNotFound)
|
r.GET("/notpage", templatecache.WithCache(time.Minute*1), home.PageNotFound)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import (
|
|||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvversion"
|
"videoweb/pub/common/srvversion"
|
||||||
"videoweb/pub/common/tgbot"
|
"videoweb/pub/common/tgbot"
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/esmanager"
|
"videoweb/pub/esmanager"
|
||||||
"videoweb/pub/models"
|
"videoweb/pub/models"
|
||||||
"videoweb/pub/mongos"
|
"videoweb/pub/mongos"
|
||||||
@@ -73,10 +72,6 @@ func Run(args []string) {
|
|||||||
}
|
}
|
||||||
initData()
|
initData()
|
||||||
ipstatsync.StartSync()
|
ipstatsync.StartSync()
|
||||||
dataReport.Init(dataReport.Config{
|
|
||||||
ApiUrl: appg.Conf.DataReport.Url,
|
|
||||||
RunMod: appg.Conf.RunMod,
|
|
||||||
})
|
|
||||||
|
|
||||||
initHttpServer()
|
initHttpServer()
|
||||||
//tgbot.SendToProgram("启动", "app启动完毕")
|
//tgbot.SendToProgram("启动", "app启动完毕")
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func UpdateAppListCache(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
// 广告位 A(code=12)
|
// 广告位 A(code=12)
|
||||||
if category.Code == 12 {
|
if category.Code == 12 {
|
||||||
for _, ad := range advitise.AList {
|
for _, ad := range advitise.AppInfoAList {
|
||||||
apps = append(apps, proto.AppInfoData{
|
apps = append(apps, proto.AppInfoData{
|
||||||
AdvitiseId: ad.Id,
|
AdvitiseId: ad.Id,
|
||||||
CategoryId: category.Id,
|
CategoryId: category.Id,
|
||||||
@@ -137,7 +137,7 @@ func UpdateAppListCache(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
// 广告位 B(code=13)
|
// 广告位 B(code=13)
|
||||||
if category.Code == 13 {
|
if category.Code == 13 {
|
||||||
for _, ad := range advitise.BList {
|
for _, ad := range advitise.AppInfoBList {
|
||||||
apps = append(apps, proto.AppInfoData{
|
apps = append(apps, proto.AppInfoData{
|
||||||
AdvitiseId: ad.Id,
|
AdvitiseId: ad.Id,
|
||||||
CategoryId: category.Id,
|
CategoryId: category.Id,
|
||||||
|
|||||||
+7
-316
@@ -4,23 +4,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"videoweb/app/appg"
|
|
||||||
"videoweb/app/service/reportser"
|
|
||||||
"videoweb/pub/common/enum/consts"
|
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/common/useragent"
|
"videoweb/pub/common/useragent"
|
||||||
"videoweb/pub/common/utils"
|
"videoweb/pub/common/utils"
|
||||||
"videoweb/pub/models/usermod"
|
"videoweb/pub/models/usermod"
|
||||||
"videoweb/pub/mongos"
|
|
||||||
"videoweb/pub/pubdef"
|
"videoweb/pub/pubdef"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var tokener = utils.NewTokenRedis()
|
|
||||||
|
|
||||||
var defaultAvatars = []string{
|
var defaultAvatars = []string{
|
||||||
"v3/image/bo/ty/1016/girl1.jpeg",
|
"v3/image/bo/ty/1016/girl1.jpeg",
|
||||||
"v3/image/re/9y/1016/girl2.jpeg",
|
"v3/image/re/9y/1016/girl2.jpeg",
|
||||||
@@ -48,9 +41,8 @@ func generateUniqueInviteCode(ctx context.Context) string {
|
|||||||
return strings.ToUpper(utils.GetRandomLetters(12))
|
return strings.ToUpper(utils.GetRandomLetters(12))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginResp 登录/注册成功后的响应数据
|
// LoginResp 用户信息
|
||||||
type LoginResp struct {
|
type LoginResp struct {
|
||||||
Token string `json:"token"`
|
|
||||||
UserId int64 `json:"userId"`
|
UserId int64 `json:"userId"`
|
||||||
AccountNo string `json:"accountNo"`
|
AccountNo string `json:"accountNo"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
@@ -66,281 +58,28 @@ type LoginResp struct {
|
|||||||
Type pubdef.UserType `json:"type"` // 身份类型:0游客 1普通用户
|
Type pubdef.UserType `json:"type"` // 身份类型:0游客 1普通用户
|
||||||
LoginType pubdef.LoginType `json:"loginType"` // 登陆方式
|
LoginType pubdef.LoginType `json:"loginType"` // 登陆方式
|
||||||
IsRegister bool `json:"isRegister"` // 是否已注册
|
IsRegister bool `json:"isRegister"` // 是否已注册
|
||||||
IsNewUser bool `json:"isNewUser"` // 本次是否新建游客
|
|
||||||
PrivacyMode bool `json:"privacyMode"` // 隐私模式
|
PrivacyMode bool `json:"privacyMode"` // 隐私模式
|
||||||
HasPassword bool `json:"hasPassword"` // 是否已设置密码
|
HasPassword bool `json:"hasPassword"` // 是否已设置密码
|
||||||
Score int64 `json:"score"` // 积分
|
Score int64 `json:"score"` // 积分
|
||||||
Recharge int64 `json:"recharge"` // 金币余额
|
Recharge int64 `json:"recharge"` // 金币余额
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashPassword 使用 bcrypt 对明文密码进行哈希
|
|
||||||
func hashPassword(plain string) (string, error) {
|
|
||||||
hash, err := bcrypt.GenerateFromPassword([]byte(plain), bcrypt.DefaultCost)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(hash), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkPassword 验证明文密码与 bcrypt 哈希是否匹配
|
|
||||||
func checkPassword(plain, hash string) bool {
|
|
||||||
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(plain)) == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// generateAndSaveToken 生成 JWT 并存入 Redis
|
|
||||||
func generateAndSaveToken(userId int64) (string, *srvdef.SrvErr) {
|
|
||||||
token, err := utils.GenerateUserToken(utils.UserClaims{
|
|
||||||
UserID: userId,
|
|
||||||
Expire: consts.UserJwtTokenExpire,
|
|
||||||
}, appg.Conf.JwtKey)
|
|
||||||
if err != nil {
|
|
||||||
return "", srvdef.New(srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg(), "")
|
|
||||||
}
|
|
||||||
if err = tokener.Save(userId, token); err != nil {
|
|
||||||
return "", srvdef.New(srvdef.StoreLevel, "token存储失败", "")
|
|
||||||
}
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// generateCrawlerToken 签发爬虫观看 JWT,不写入 Redis,避免占用真实用户槽位。
|
|
||||||
func generateCrawlerToken() (string, *srvdef.SrvErr) {
|
|
||||||
token, err := utils.GenerateUserToken(utils.UserClaims{
|
|
||||||
UserID: pubdef.CrawlerUserId,
|
|
||||||
Expire: consts.UserJwtTokenExpire,
|
|
||||||
}, appg.Conf.JwtKey)
|
|
||||||
if err != nil {
|
|
||||||
return "", srvdef.New(srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg(), "")
|
|
||||||
}
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CrawlerLoginResp 爬虫虚拟游客资料,不对应任何数据库用户。
|
// CrawlerLoginResp 爬虫虚拟游客资料,不对应任何数据库用户。
|
||||||
func CrawlerLoginResp(token string) *LoginResp {
|
func CrawlerLoginResp() *LoginResp {
|
||||||
return &LoginResp{
|
return &LoginResp{
|
||||||
Token: token,
|
|
||||||
UserId: pubdef.CrawlerUserId,
|
UserId: pubdef.CrawlerUserId,
|
||||||
NickName: "游客",
|
NickName: "游客",
|
||||||
Status: pubdef.UserStatusNormal,
|
Status: pubdef.UserStatusNormal,
|
||||||
Type: pubdef.UserTypeGuest,
|
Type: pubdef.UserTypeGuest,
|
||||||
LoginType: pubdef.LoginTypeDevice,
|
LoginType: pubdef.LoginTypeDevice,
|
||||||
IsRegister: false,
|
IsRegister: false,
|
||||||
IsNewUser: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register 用户注册
|
// GetInfo 获取当前用户的最新信息
|
||||||
// guestUserId:请求头 Authorization 解析出的用户ID;若为游客则升级该用户,否则新建
|
|
||||||
// agentInviteCode:邀请人的邀请码,可为空
|
|
||||||
func Register(ctx context.Context, guestUserId int64, accountNo, email, password, agentInviteCode string, ua useragent.UA, ip, channel string) (*LoginResp, *srvdef.SrvErr) {
|
|
||||||
accountNo = strings.TrimSpace(accountNo)
|
|
||||||
email = strings.TrimSpace(email)
|
|
||||||
password = strings.TrimSpace(password)
|
|
||||||
|
|
||||||
// 检查账号是否已存在
|
|
||||||
exist, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.AccountNo: accountNo})
|
|
||||||
if exist != nil {
|
|
||||||
return nil, srvdef.New(srvdef.ErrDbInputExist, "账号已存在", "")
|
|
||||||
}
|
|
||||||
// 填写邮箱时检查是否已存在
|
|
||||||
if email != "" {
|
|
||||||
exist, _ = usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Email: email})
|
|
||||||
if exist != nil {
|
|
||||||
return nil, srvdef.New(srvdef.ErrDbInputExist, "邮箱已被注册", "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hashed, err := hashPassword(password)
|
|
||||||
if err != nil {
|
|
||||||
return nil, srvdef.New(srvdef.Failure, "密码处理失败", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
// 请求头带游客 token:升级当前游客为普通用户
|
|
||||||
if guestUserId > 0 {
|
|
||||||
guest, serr := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: guestUserId})
|
|
||||||
if serr == nil && isGuestUser(guest) {
|
|
||||||
setDoc := bson.M{
|
|
||||||
usermod.FN.User.AccountNo: accountNo,
|
|
||||||
usermod.FN.User.Email: email,
|
|
||||||
usermod.FN.User.Password: hashed,
|
|
||||||
usermod.FN.User.Type: pubdef.UserTypeNormal,
|
|
||||||
usermod.FN.User.IsRegister: true,
|
|
||||||
usermod.FN.User.LoginType: pubdef.LoginTypeAccount,
|
|
||||||
usermod.FN.User.RegisterTime: now,
|
|
||||||
usermod.FN.User.LastLoginAt: now,
|
|
||||||
usermod.FN.User.UpdatedAt: now,
|
|
||||||
usermod.FN.User.LastIp: ip,
|
|
||||||
}
|
|
||||||
if agentInviteCode != "" && guest.AgentInviteCode == "" {
|
|
||||||
setDoc[usermod.FN.User.AgentInviteCode] = agentInviteCode
|
|
||||||
setDoc[usermod.FN.User.IsDirect] = false
|
|
||||||
guest.IsDirect = false
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.DevID); v != "" {
|
|
||||||
setDoc[usermod.FN.User.DevID] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.DevType); v != "" {
|
|
||||||
setDoc[usermod.FN.User.Device] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.SysType); v != "" {
|
|
||||||
setDoc[usermod.FN.User.SysType] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.Ver); v != "" {
|
|
||||||
setDoc[usermod.FN.User.AppVer] = v
|
|
||||||
}
|
|
||||||
mergeUAExtFieldsToSet(setDoc, guest, ua)
|
|
||||||
if serr = usermod.UpdateOneUser(ctx, bson.M{usermod.FN.User.Id: guest.Id}, bson.M{"$set": setDoc}); serr != nil {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
if agentInviteCode != "" && guest.AgentInviteCode == "" {
|
|
||||||
_ = usermod.UpdateOneUser(ctx,
|
|
||||||
bson.M{usermod.FN.User.InviteCode: agentInviteCode},
|
|
||||||
bson.M{
|
|
||||||
"$inc": bson.M{usermod.FN.User.Invites: 1},
|
|
||||||
"$set": bson.M{usermod.FN.User.UpdatedAt: now},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
guest.AccountNo = accountNo
|
|
||||||
guest.Email = email
|
|
||||||
guest.Type = pubdef.UserTypeNormal
|
|
||||||
guest.IsRegister = true
|
|
||||||
guest.LoginType = pubdef.LoginTypeAccount
|
|
||||||
guest.RegisterTime = now
|
|
||||||
token, serr := generateAndSaveToken(guest.Id)
|
|
||||||
if serr != nil {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
reportser.ReportUserRegister(guest, ua, ip, "username")
|
|
||||||
reportser.ReportUserLogin(guest, ua, ip, pubdef.LoginTypeAccount)
|
|
||||||
return toLoginResp(ctx, guest, token, true), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
user := &usermod.User{
|
|
||||||
Id: mongos.Lid.User.Get(),
|
|
||||||
AccountNo: accountNo,
|
|
||||||
Email: email,
|
|
||||||
Password: hashed,
|
|
||||||
NickName: appg.GenerateNickname(),
|
|
||||||
Avatar: randomAvatar(),
|
|
||||||
InviteCode: generateUniqueInviteCode(ctx),
|
|
||||||
AgentInviteCode: agentInviteCode,
|
|
||||||
Type: pubdef.UserTypeNormal,
|
|
||||||
Status: pubdef.UserStatusNormal,
|
|
||||||
IsRegister: true,
|
|
||||||
LoginType: pubdef.LoginTypeAccount,
|
|
||||||
RegIp: ip,
|
|
||||||
LastIp: ip,
|
|
||||||
DevID: ua.DevID,
|
|
||||||
Device: ua.DevType,
|
|
||||||
SysType: ua.SysType,
|
|
||||||
AppVer: ua.Ver,
|
|
||||||
OriVer: ua.Ver,
|
|
||||||
SessionID: ua.SessionID,
|
|
||||||
DeviceBrand: ua.DeviceBrand,
|
|
||||||
DeviceModel: ua.DeviceModel,
|
|
||||||
SystemName: ua.SystemName,
|
|
||||||
SystemVersion: ua.SystemVersion,
|
|
||||||
DistrictCode: normalizeChannel(channel),
|
|
||||||
IsDirect: resolveUserDistrict(channel, agentInviteCode, ip, ua.SysType).IsDirect,
|
|
||||||
LastLoginAt: now,
|
|
||||||
RegisterTime: now,
|
|
||||||
CreatedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
}
|
|
||||||
|
|
||||||
if serr := usermod.InsertOneUser(ctx, user); serr != nil {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
|
|
||||||
// 若填写了邀请码,给对应用户的 invites +1
|
|
||||||
if agentInviteCode != "" {
|
|
||||||
_ = usermod.UpdateOneUser(ctx,
|
|
||||||
bson.M{usermod.FN.User.InviteCode: agentInviteCode},
|
|
||||||
bson.M{
|
|
||||||
"$inc": bson.M{usermod.FN.User.Invites: 1},
|
|
||||||
"$set": bson.M{usermod.FN.User.UpdatedAt: time.Now()},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
token, serr := generateAndSaveToken(user.Id)
|
|
||||||
if serr != nil {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
reportser.ReportUserRegister(user, ua, ip, "username")
|
|
||||||
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeAccount)
|
|
||||||
return toLoginResp(ctx, user, token, false), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Login 用户登录(账号或邮箱均可)
|
|
||||||
func Login(ctx context.Context, account, password string, ua useragent.UA, ip, channel string) (*LoginResp, *srvdef.SrvErr) {
|
|
||||||
// 账号或邮箱均可登录
|
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{
|
|
||||||
"$or": []bson.M{
|
|
||||||
{usermod.FN.User.AccountNo: account},
|
|
||||||
{usermod.FN.User.Email: account},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if user == nil {
|
|
||||||
return nil, srvdef.New(srvdef.AccountIsNotExists, srvdef.AccountIsNotExists.Msg(), "")
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.Status == pubdef.UserStatusDisable {
|
|
||||||
return nil, srvdef.New(srvdef.AccountErrAccessForbid, srvdef.AccountErrAccessForbid.Msg(), "")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !checkPassword(password, user.Password) {
|
|
||||||
return nil, srvdef.New(srvdef.AccountErrPasswordError, srvdef.AccountErrPasswordError.Msg(), "")
|
|
||||||
}
|
|
||||||
|
|
||||||
token, serr := generateAndSaveToken(user.Id)
|
|
||||||
if serr != nil {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
setDoc := bson.M{
|
|
||||||
usermod.FN.User.LastLoginAt: now,
|
|
||||||
usermod.FN.User.UpdatedAt: now,
|
|
||||||
}
|
|
||||||
if ip != "" {
|
|
||||||
setDoc[usermod.FN.User.LastIp] = ip
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.DevID); v != "" {
|
|
||||||
setDoc[usermod.FN.User.DevID] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.DevType); v != "" {
|
|
||||||
setDoc[usermod.FN.User.Device] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.SysType); v != "" {
|
|
||||||
setDoc[usermod.FN.User.SysType] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.Ver); v != "" {
|
|
||||||
setDoc[usermod.FN.User.AppVer] = v
|
|
||||||
}
|
|
||||||
// 已有账号的历史用户统一修正为普通用户
|
|
||||||
if strings.TrimSpace(user.AccountNo) != "" && user.Type != pubdef.UserTypeNormal {
|
|
||||||
setDoc[usermod.FN.User.Type] = pubdef.UserTypeNormal
|
|
||||||
setDoc[usermod.FN.User.IsRegister] = true
|
|
||||||
user.Type = pubdef.UserTypeNormal
|
|
||||||
user.IsRegister = true
|
|
||||||
}
|
|
||||||
mergeUAExtFieldsToSet(setDoc, user, ua)
|
|
||||||
_ = usermod.UpdateOneUser(ctx,
|
|
||||||
bson.M{usermod.FN.User.Id: user.Id},
|
|
||||||
bson.M{"$set": setDoc},
|
|
||||||
)
|
|
||||||
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeAccount)
|
|
||||||
return toLoginResp(ctx, user, token, true), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInfo 获取当前登录用户的最新信息(不刷新 token)
|
|
||||||
func GetInfo(ctx context.Context, userId int64, ua useragent.UA) (*LoginResp, *srvdef.SrvErr) {
|
func GetInfo(ctx context.Context, userId int64, ua useragent.UA) (*LoginResp, *srvdef.SrvErr) {
|
||||||
if pubdef.IsCrawlerUser(userId) {
|
if pubdef.IsCrawlerUser(userId) {
|
||||||
return CrawlerLoginResp(""), nil
|
return CrawlerLoginResp(), nil
|
||||||
}
|
}
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
||||||
if user == nil {
|
if user == nil {
|
||||||
@@ -371,7 +110,7 @@ func GetInfo(ctx context.Context, userId int64, ua useragent.UA) (*LoginResp, *s
|
|||||||
setDoc[usermod.FN.User.UpdatedAt] = now
|
setDoc[usermod.FN.User.UpdatedAt] = now
|
||||||
_ = usermod.UpdateOneUser(ctx, bson.M{usermod.FN.User.Id: user.Id}, bson.M{"$set": setDoc})
|
_ = usermod.UpdateOneUser(ctx, bson.M{usermod.FN.User.Id: user.Id}, bson.M{"$set": setDoc})
|
||||||
}
|
}
|
||||||
return toLoginResp(ctx, user, "", true), nil
|
return toLoginResp(ctx, user, true), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeUAExtFieldsToSet(setDoc bson.M, user *usermod.User, ua useragent.UA) {
|
func mergeUAExtFieldsToSet(setDoc bson.M, user *usermod.User, ua useragent.UA) {
|
||||||
@@ -397,16 +136,14 @@ func mergeUAExtFieldsToSet(setDoc bson.M, user *usermod.User, ua useragent.UA) {
|
|||||||
|
|
||||||
// UpdateProfileReq 修改用户资料的参数(所有字段均为可选)
|
// UpdateProfileReq 修改用户资料的参数(所有字段均为可选)
|
||||||
type UpdateProfileReq struct {
|
type UpdateProfileReq struct {
|
||||||
UserId int64 // 用户ID(从 token 中获取)
|
UserId int64 // 用户ID(按设备ID识别)
|
||||||
NickName *string // 新昵称(可选)
|
NickName *string // 新昵称(可选)
|
||||||
Avatar *string // 新头像 URL(可选)
|
Avatar *string // 新头像 URL(可选)
|
||||||
Introduction *string // 简介(可选)
|
Introduction *string // 简介(可选)
|
||||||
PrivacyMode *bool // 隐私模式:true-开启,false-关闭(可选)
|
PrivacyMode *bool // 隐私模式:true-开启,false-关闭(可选)
|
||||||
OldPassword *string // 旧密码明文(已设置密码时修改必传)
|
|
||||||
NewPassword *string // 新密码明文(设置或修改密码时必传)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateProfile 修改用户资料:支持修改头像、简介、密码,或组合修改
|
// UpdateProfile 修改用户资料:支持修改昵称、头像、简介、隐私模式,或组合修改
|
||||||
func UpdateProfile(ctx context.Context, req *UpdateProfileReq) *srvdef.SrvErr {
|
func UpdateProfile(ctx context.Context, req *UpdateProfileReq) *srvdef.SrvErr {
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: req.UserId})
|
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: req.UserId})
|
||||||
if user == nil {
|
if user == nil {
|
||||||
@@ -428,28 +165,6 @@ func UpdateProfile(ctx context.Context, req *UpdateProfileReq) *srvdef.SrvErr {
|
|||||||
setDoc[usermod.FN.User.PrivacyMode] = *req.PrivacyMode
|
setDoc[usermod.FN.User.PrivacyMode] = *req.PrivacyMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置或修改密码
|
|
||||||
if req.OldPassword != nil || req.NewPassword != nil {
|
|
||||||
if req.NewPassword == nil || strings.TrimSpace(*req.NewPassword) == "" {
|
|
||||||
return srvdef.New(srvdef.ErrParamError, "新密码不能为空", "")
|
|
||||||
}
|
|
||||||
if strings.TrimSpace(user.Password) != "" {
|
|
||||||
if req.OldPassword == nil || strings.TrimSpace(*req.OldPassword) == "" {
|
|
||||||
return srvdef.New(srvdef.ErrParamError, "修改密码时旧密码和新密码均需提供", "")
|
|
||||||
}
|
|
||||||
if !checkPassword(*req.OldPassword, user.Password) {
|
|
||||||
return srvdef.New(srvdef.AccountErrPasswordError, "旧密码错误", "")
|
|
||||||
}
|
|
||||||
} else if req.OldPassword != nil && strings.TrimSpace(*req.OldPassword) != "" {
|
|
||||||
return srvdef.New(srvdef.ErrParamError, "修改密码时旧密码和新密码均需提供", "")
|
|
||||||
}
|
|
||||||
hashed, err := hashPassword(*req.NewPassword)
|
|
||||||
if err != nil {
|
|
||||||
return srvdef.New(srvdef.Failure, "密码处理失败", "")
|
|
||||||
}
|
|
||||||
setDoc[usermod.FN.User.Password] = hashed
|
|
||||||
}
|
|
||||||
|
|
||||||
// 没有任何需要更新的字段
|
// 没有任何需要更新的字段
|
||||||
if len(setDoc) == 1 {
|
if len(setDoc) == 1 {
|
||||||
return srvdef.New(srvdef.ErrParamError, "至少需要修改一项资料", "")
|
return srvdef.New(srvdef.ErrParamError, "至少需要修改一项资料", "")
|
||||||
@@ -460,27 +175,3 @@ func UpdateProfile(ctx context.Context, req *UpdateProfileReq) *srvdef.SrvErr {
|
|||||||
bson.M{"$set": setDoc},
|
bson.M{"$set": setDoc},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetPassword 通过账号+邮箱双重校验后重置密码
|
|
||||||
func ResetPassword(ctx context.Context, accountNo, email, newPassword string) *srvdef.SrvErr {
|
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{
|
|
||||||
usermod.FN.User.AccountNo: accountNo,
|
|
||||||
usermod.FN.User.Email: email,
|
|
||||||
})
|
|
||||||
if user == nil {
|
|
||||||
return srvdef.New(srvdef.ErrUserNotExsit, "账号或邮箱不匹配", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
hashed, err := hashPassword(newPassword)
|
|
||||||
if err != nil {
|
|
||||||
return srvdef.New(srvdef.Failure, "密码处理失败", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
return usermod.UpdateOneUser(ctx,
|
|
||||||
bson.M{usermod.FN.User.Id: user.Id},
|
|
||||||
bson.M{"$set": bson.M{
|
|
||||||
usermod.FN.User.Password: hashed,
|
|
||||||
usermod.FN.User.UpdatedAt: time.Now(),
|
|
||||||
}},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
+72
-141
@@ -3,13 +3,12 @@ package authser
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"videoweb/app/appg"
|
"videoweb/app/appg"
|
||||||
"videoweb/app/middleware/reptilerecord"
|
|
||||||
"videoweb/app/middleware/visit"
|
|
||||||
"videoweb/app/service/configser"
|
"videoweb/app/service/configser"
|
||||||
"videoweb/app/service/reportser"
|
"videoweb/pub/common/enum/redisconst"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/netutil"
|
"videoweb/pub/common/netutil"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
@@ -17,76 +16,73 @@ import (
|
|||||||
"videoweb/pub/models/usermod"
|
"videoweb/pub/models/usermod"
|
||||||
"videoweb/pub/mongos"
|
"videoweb/pub/mongos"
|
||||||
"videoweb/pub/pubdef"
|
"videoweb/pub/pubdef"
|
||||||
|
"videoweb/pub/redis"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GuestLoginReq 游客登录请求
|
const (
|
||||||
type GuestLoginReq struct {
|
deviceUserLockRetry = 10
|
||||||
DevID string `json:"devID"` // 设备唯一标示(必填)
|
deviceUserLockInterval = 100 * time.Millisecond
|
||||||
Mac string `json:"mac"` // 设备 Mac(可选)
|
)
|
||||||
DeviceId string `json:"deviceId"` // 备用设备ID(可选,写入 DevV2)
|
|
||||||
Channel string `json:"channel"` // 渠道码(可选,用户无商区码时写入 DistrictCode)
|
// ResolveDeviceUser 按设备ID识别用户:先查缓存,再查库,都没有则自动创建
|
||||||
|
func ResolveDeviceUser(ctx context.Context, ua useragent.UA, ip, channel string) (int64, *srvdef.SrvErr) {
|
||||||
|
devID := strings.TrimSpace(ua.DevID)
|
||||||
|
if devID == "" {
|
||||||
|
return 0, srvdef.New(srvdef.ErrParamError, "devID不能为空", "")
|
||||||
|
}
|
||||||
|
ua.DevID = devID
|
||||||
|
|
||||||
|
cacheKey := redisconst.AppDeviceUserKey(devID)
|
||||||
|
if v, err := redis.Get(cacheKey); err == nil && v != nil {
|
||||||
|
if userId, perr := strconv.ParseInt(*v, 10, 64); perr == nil && userId > 0 {
|
||||||
|
return userId, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isGuestUser 是否为可升级的游客身份
|
user, serr := findOrCreateDeviceUser(ctx, ua, ip, channel)
|
||||||
func isGuestUser(user *usermod.User) bool {
|
|
||||||
if user == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if user.Type == pubdef.UserTypeNormal {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return !user.IsRegister && strings.TrimSpace(user.AccountNo) == ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// GuestLogin 游客登录:按 token / DevID / Mac / DeviceId 查找,不存在则创建游客
|
|
||||||
func GuestLogin(ctx context.Context, userId int64, ip string, req *GuestLoginReq, ua useragent.UA) (*LoginResp, *srvdef.SrvErr) {
|
|
||||||
if isBotRequest(ctx) {
|
|
||||||
return crawlerGuestLogin()
|
|
||||||
}
|
|
||||||
if req == nil || strings.TrimSpace(req.DevID) == "" {
|
|
||||||
return nil, srvdef.New(srvdef.ErrParamError, "devID不能为空", "")
|
|
||||||
}
|
|
||||||
ua.DevID = strings.TrimSpace(req.DevID)
|
|
||||||
|
|
||||||
var user *usermod.User
|
|
||||||
var serr *srvdef.SrvErr
|
|
||||||
reuseToken := false
|
|
||||||
|
|
||||||
if userId > 0 {
|
|
||||||
user, serr = usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
if serr.Code != srvdef.ErrUserNotExsit {
|
return 0, serr
|
||||||
return nil, serr
|
|
||||||
}
|
}
|
||||||
userId = 0
|
|
||||||
user = nil
|
|
||||||
} else {
|
|
||||||
reuseToken = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isNewUser := false
|
|
||||||
if userId == 0 {
|
|
||||||
user, serr = findGuestUser(ctx, req)
|
|
||||||
if serr != nil {
|
|
||||||
if serr.Code != srvdef.ErrUserNotExsit {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
user, serr = createGuestUser(ctx, ua, req, ip)
|
|
||||||
if serr != nil {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
isNewUser = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.Status == pubdef.UserStatusDisable {
|
if user.Status == pubdef.UserStatusDisable {
|
||||||
return nil, srvdef.New(srvdef.AccountErrAccessForbid, srvdef.AccountErrAccessForbid.Msg(), "")
|
return 0, srvdef.New(srvdef.AccountErrAccessForbid, srvdef.AccountErrAccessForbid.Msg(), "")
|
||||||
|
}
|
||||||
|
if err := redis.Set(cacheKey, user.Id, redisconst.AppDeviceUserExpire); err != nil {
|
||||||
|
log.Warn("authser:ResolveDeviceUser cache set failed", log.Any("devID", devID), log.E(err))
|
||||||
|
}
|
||||||
|
return user.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// findOrCreateDeviceUser 按设备ID查找用户,不存在时加锁创建,避免同一设备并发请求建出多个用户
|
||||||
|
func findOrCreateDeviceUser(ctx context.Context, ua useragent.UA, ip, channel string) (*usermod.User, *srvdef.SrvErr) {
|
||||||
|
lockKey := redisconst.AppDeviceUserLockKey(ua.DevID)
|
||||||
|
for i := 0; i < deviceUserLockRetry; i++ {
|
||||||
|
user, serr := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.DevID: ua.DevID})
|
||||||
|
if serr == nil {
|
||||||
|
touchDeviceUser(ctx, user, ua, ip, channel)
|
||||||
|
return user, nil
|
||||||
|
}
|
||||||
|
if serr.Code != srvdef.ErrUserNotExsit {
|
||||||
|
return nil, serr
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := redis.Setnx_NewOK(lockKey, 1, redisconst.AppDeviceUserLockExpire)
|
||||||
|
if err != nil {
|
||||||
|
return nil, srvdef.New(srvdef.StoreLevel, "用户创建失败", "")
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
defer func() { _ = redis.Del(lockKey) }()
|
||||||
|
return createGuestUser(ctx, ua, ip, channel)
|
||||||
|
}
|
||||||
|
// 其他请求正在为该设备建用户,稍后重查
|
||||||
|
time.Sleep(deviceUserLockInterval)
|
||||||
|
}
|
||||||
|
return nil, srvdef.New(srvdef.StoreLevel, "用户创建失败", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// touchDeviceUser 更新最近访问信息(缓存未命中时执行,频率受缓存时长限制)
|
||||||
|
func touchDeviceUser(ctx context.Context, user *usermod.User, ua useragent.UA, ip, channel string) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
setDoc := bson.M{
|
setDoc := bson.M{
|
||||||
usermod.FN.User.LastLoginAt: now,
|
usermod.FN.User.LastLoginAt: now,
|
||||||
@@ -94,9 +90,6 @@ func GuestLogin(ctx context.Context, userId int64, ip string, req *GuestLoginReq
|
|||||||
usermod.FN.User.LastIp: ip,
|
usermod.FN.User.LastIp: ip,
|
||||||
usermod.FN.User.LoginType: pubdef.LoginTypeDevice,
|
usermod.FN.User.LoginType: pubdef.LoginTypeDevice,
|
||||||
}
|
}
|
||||||
if v := strings.TrimSpace(ua.DevID); v != "" {
|
|
||||||
setDoc[usermod.FN.User.DevID] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(ua.DevType); v != "" {
|
if v := strings.TrimSpace(ua.DevType); v != "" {
|
||||||
setDoc[usermod.FN.User.Device] = v
|
setDoc[usermod.FN.User.Device] = v
|
||||||
}
|
}
|
||||||
@@ -106,74 +99,15 @@ func GuestLogin(ctx context.Context, userId int64, ip string, req *GuestLoginReq
|
|||||||
if v := strings.TrimSpace(ua.Ver); v != "" {
|
if v := strings.TrimSpace(ua.Ver); v != "" {
|
||||||
setDoc[usermod.FN.User.AppVer] = v
|
setDoc[usermod.FN.User.AppVer] = v
|
||||||
}
|
}
|
||||||
if v := strings.TrimSpace(req.Mac); v != "" {
|
|
||||||
setDoc[usermod.FN.User.Mac] = v
|
|
||||||
}
|
|
||||||
if v := strings.TrimSpace(req.DeviceId); v != "" {
|
|
||||||
setDoc[usermod.FN.User.DevV2] = v
|
|
||||||
}
|
|
||||||
// 历史用户 Type 为空/旧值时,未注册则归为游客
|
|
||||||
if isGuestUser(user) && user.Type != pubdef.UserTypeGuest {
|
|
||||||
setDoc[usermod.FN.User.Type] = pubdef.UserTypeGuest
|
|
||||||
user.Type = pubdef.UserTypeGuest
|
|
||||||
}
|
|
||||||
mergeUAExtFieldsToSet(setDoc, user, ua)
|
mergeUAExtFieldsToSet(setDoc, user, ua)
|
||||||
|
applyChannelIfMissing(setDoc, user, channel)
|
||||||
_ = usermod.UpdateOneUser(ctx, bson.M{usermod.FN.User.Id: user.Id}, bson.M{"$set": setDoc})
|
_ = usermod.UpdateOneUser(ctx, bson.M{usermod.FN.User.Id: user.Id}, bson.M{"$set": setDoc})
|
||||||
|
|
||||||
var token string
|
|
||||||
if reuseToken {
|
|
||||||
if old, err := tokener.Get(user.Id); err == nil && len(old) > 0 {
|
|
||||||
token = string(old)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if token == "" {
|
|
||||||
token, serr = generateAndSaveToken(user.Id)
|
|
||||||
if serr != nil {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := toLoginResp(ctx, user, token, true)
|
func createGuestUser(ctx context.Context, ua useragent.UA, ip, channel string) (*usermod.User, *srvdef.SrvErr) {
|
||||||
resp.IsNewUser = isNewUser
|
|
||||||
if isNewUser {
|
|
||||||
visit.RecordDailyVisit(ctx, user.Id, ua, ip)
|
|
||||||
reportser.ReportUserRegister(user, ua, ip, "deviceid")
|
|
||||||
}
|
|
||||||
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeDevice)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func findGuestUser(ctx context.Context, req *GuestLoginReq) (*usermod.User, *srvdef.SrvErr) {
|
|
||||||
user, serr := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.DevID: req.DevID})
|
|
||||||
if serr == nil {
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
if serr.Code != srvdef.ErrUserNotExsit {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
|
|
||||||
mac := strings.TrimSpace(req.Mac)
|
|
||||||
if mac != "" && !strings.Contains(mac, "00:00:00:00") {
|
|
||||||
user, serr = usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Mac: mac})
|
|
||||||
if serr == nil {
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
if serr.Code != srvdef.ErrUserNotExsit {
|
|
||||||
return nil, serr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceId := strings.TrimSpace(req.DeviceId)
|
|
||||||
if deviceId != "" && !strings.Contains(deviceId, "00:00:00:00") {
|
|
||||||
return usermod.FindOneUser(ctx, bson.M{usermod.FN.User.DevV2: deviceId})
|
|
||||||
}
|
|
||||||
return nil, srvdef.New(srvdef.ErrUserNotExsit, "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func createGuestUser(ctx context.Context, ua useragent.UA, req *GuestLoginReq, ip string) (*usermod.User, *srvdef.SrvErr) {
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
uid := mongos.Lid.User.Get()
|
uid := mongos.Lid.User.Get()
|
||||||
districtInfo := resolveUserDistrict(req.Channel, "", ip, ua.SysType)
|
districtInfo := resolveUserDistrict(channel, "", ip, ua.SysType)
|
||||||
user := &usermod.User{
|
user := &usermod.User{
|
||||||
Id: uid,
|
Id: uid,
|
||||||
Type: pubdef.UserTypeGuest,
|
Type: pubdef.UserTypeGuest,
|
||||||
@@ -183,13 +117,11 @@ func createGuestUser(ctx context.Context, ua useragent.UA, req *GuestLoginReq, i
|
|||||||
NickName: fmt.Sprintf("游客%d", uid),
|
NickName: fmt.Sprintf("游客%d", uid),
|
||||||
Avatar: randomAvatar(),
|
Avatar: randomAvatar(),
|
||||||
InviteCode: generateUniqueInviteCode(ctx),
|
InviteCode: generateUniqueInviteCode(ctx),
|
||||||
DistrictCode: normalizeChannel(req.Channel),
|
DistrictCode: normalizeChannel(channel),
|
||||||
IsDirect: districtInfo.IsDirect,
|
IsDirect: districtInfo.IsDirect,
|
||||||
RegIp: ip,
|
RegIp: ip,
|
||||||
LastIp: ip,
|
LastIp: ip,
|
||||||
DevID: ua.DevID,
|
DevID: ua.DevID,
|
||||||
Mac: strings.TrimSpace(req.Mac),
|
|
||||||
DevV2: strings.TrimSpace(req.DeviceId),
|
|
||||||
Device: ua.DevType,
|
Device: ua.DevType,
|
||||||
SysType: ua.SysType,
|
SysType: ua.SysType,
|
||||||
AppVer: ua.Ver,
|
AppVer: ua.Ver,
|
||||||
@@ -213,14 +145,13 @@ func createGuestUser(ctx context.Context, ua useragent.UA, req *GuestLoginReq, i
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toLoginResp(ctx context.Context, user *usermod.User, token string, withCDN bool) *LoginResp {
|
func toLoginResp(ctx context.Context, user *usermod.User, withCDN bool) *LoginResp {
|
||||||
avatar := user.Avatar
|
avatar := user.Avatar
|
||||||
if withCDN {
|
if withCDN {
|
||||||
cdn := configser.GetAppImageCdn(configser.ClientIPFromCtx(ctx))
|
cdn := configser.GetAppImageCdn(configser.ClientIPFromCtx(ctx))
|
||||||
avatar = netutil.MergeURL(cdn, user.Avatar)
|
avatar = netutil.MergeURL(cdn, user.Avatar)
|
||||||
}
|
}
|
||||||
return &LoginResp{
|
return &LoginResp{
|
||||||
Token: token,
|
|
||||||
UserId: user.Id,
|
UserId: user.Id,
|
||||||
AccountNo: user.AccountNo,
|
AccountNo: user.AccountNo,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
@@ -247,16 +178,16 @@ func normalizeChannel(channel string) string {
|
|||||||
return strings.TrimSpace(channel)
|
return strings.TrimSpace(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isBotRequest(ctx context.Context) bool {
|
func hasDistrictCode(code string) bool {
|
||||||
gc, ok := ctx.(*gin.Context)
|
return strings.TrimSpace(code) != ""
|
||||||
return ok && reptilerecord.IsBot(gc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// crawlerGuestLogin 给爬虫签发可观看的虚拟游客 token,不建用户、不写日活、不上报。
|
func applyChannelIfMissing(setDoc bson.M, user *usermod.User, channel string) {
|
||||||
func crawlerGuestLogin() (*LoginResp, *srvdef.SrvErr) {
|
if user == nil || hasDistrictCode(user.DistrictCode) {
|
||||||
token, serr := generateCrawlerToken()
|
return
|
||||||
if serr != nil {
|
}
|
||||||
return nil, serr
|
if ch := normalizeChannel(channel); ch != "" {
|
||||||
|
setDoc[usermod.FN.User.DistrictCode] = ch
|
||||||
|
user.DistrictCode = ch
|
||||||
}
|
}
|
||||||
return CrawlerLoginResp(token), nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,12 @@ package coinser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"videoweb/app/service/rechargeser"
|
"videoweb/app/service/rechargeser"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/common/useragent"
|
"videoweb/pub/common/useragent"
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/models/eventmod"
|
|
||||||
"videoweb/pub/models/rechargepackagemod"
|
"videoweb/pub/models/rechargepackagemod"
|
||||||
"videoweb/pub/models/usermod"
|
"videoweb/pub/models/usermod"
|
||||||
"videoweb/pub/models/vipordermod"
|
"videoweb/pub/models/vipordermod"
|
||||||
@@ -116,8 +109,6 @@ func CreateCoinOrder(ctx context.Context,
|
|||||||
return nil, serr
|
return nil, serr
|
||||||
}
|
}
|
||||||
|
|
||||||
go reportCoinOrderCreated(order, pkg, ip)
|
|
||||||
|
|
||||||
return &BuyCoinResp{
|
return &BuyCoinResp{
|
||||||
TradeNo: tradeNo,
|
TradeNo: tradeNo,
|
||||||
PayUrl: payInfo.PayUrl,
|
PayUrl: payInfo.PayUrl,
|
||||||
@@ -126,65 +117,6 @@ func CreateCoinOrder(ctx context.Context,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportCoinOrderCreated(order *vipordermod.VipOrder, pkg *rechargepackagemod.RechargePackage, ip string) {
|
|
||||||
ctx := context.Background()
|
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: order.UserId})
|
|
||||||
districtCode := order.DistrictCode
|
|
||||||
if user != nil && strings.TrimSpace(user.DistrictCode) != "" {
|
|
||||||
districtCode = user.DistrictCode
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceKey, sourceName := orderSource(order)
|
|
||||||
ua := order.Client.UA(order.SysType)
|
|
||||||
eventId := newEventId(pubdef.TrackerAppId(), order.UserId, order.TradeNo, order.CreatedAt.Unix())
|
|
||||||
commonField := dataReport.NewCommonField(eventId, dataReport.EventTypeOrderCreated, districtCode, ua, strconv.FormatInt(order.UserId, 10), ip)
|
|
||||||
commonField.Payload = dataReport.JsonRawMessage(&dataReport.OrderCreatedEvent{
|
|
||||||
OrderID: order.TradeNo,
|
|
||||||
OrderType: "coin_purchase",
|
|
||||||
ProductID: strconv.FormatInt(pkg.Id, 10),
|
|
||||||
ProductName: pkg.Name,
|
|
||||||
Amount: dataReport.JsonNumber(order.Amount),
|
|
||||||
Currency: "CNY",
|
|
||||||
CoinQuantity: dataReport.JsonNumber(order.Coin),
|
|
||||||
SourcePageKey: sourceKey,
|
|
||||||
SourcePageName: sourceName,
|
|
||||||
CreateTime: dataReport.JsonNumber(order.CreatedAt.Unix()),
|
|
||||||
})
|
|
||||||
|
|
||||||
eventData, _ := json.Marshal(commonField)
|
|
||||||
if err := eventmod.InsertOneEvent(ctx, &eventmod.Event{
|
|
||||||
EventId: commonField.EventID,
|
|
||||||
EventType: commonField.Event,
|
|
||||||
Data: string(eventData),
|
|
||||||
Status: eventmod.Default,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error("reportCoinOrderCreated InsertOneEvent failed",
|
|
||||||
log.Any("tradeNo", order.TradeNo), log.E(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func orderSource(order *vipordermod.VipOrder) (string, string) {
|
|
||||||
key, name := "deposit", "充值中心"
|
|
||||||
if order != nil && order.Client != nil {
|
|
||||||
if value := strings.TrimSpace(order.Client.SourcePageKey); value != "" {
|
|
||||||
key = value
|
|
||||||
}
|
|
||||||
if value := strings.TrimSpace(order.Client.SourcePageName); value != "" {
|
|
||||||
name = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return key, name
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
|
|
||||||
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
|
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(input))
|
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCoinOrderHistory 查询用户金币购买记录
|
// GetCoinOrderHistory 查询用户金币购买记录
|
||||||
func GetCoinOrderHistory(ctx context.Context, userId int64, page, pageSize int64) (vipordermod.VipOrderList, int64, *srvdef.SrvErr) {
|
func GetCoinOrderHistory(ctx context.Context, userId int64, page, pageSize int64) (vipordermod.VipOrderList, int64, *srvdef.SrvErr) {
|
||||||
filter := bson.M{
|
filter := bson.M{
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
"videoweb/app/api/proto"
|
"videoweb/app/api/proto"
|
||||||
"videoweb/app/service/configser"
|
"videoweb/app/service/configser"
|
||||||
"videoweb/app/service/reportser"
|
|
||||||
"videoweb/pub/common/enum/redisconst"
|
"videoweb/pub/common/enum/redisconst"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/netutil"
|
"videoweb/pub/common/netutil"
|
||||||
@@ -126,13 +125,6 @@ func SendComment(ctx context.Context, userId int64, ip string, req *proto.Commen
|
|||||||
log.Error("评论发布后更新短剧热度失败", log.Any("短剧ID", playletId), log.Any("评论信息", info), log.E(err))
|
log.Error("评论发布后更新短剧热度失败", log.Any("短剧ID", playletId), log.Any("评论信息", info), log.E(err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
chapterId := int64(0)
|
|
||||||
if req.ObjectType == ObjectTypePlayletChapter {
|
|
||||||
chapterId = req.ObjectId
|
|
||||||
}
|
|
||||||
reportser.ReportPlayletComment(ctx, user, playletId, chapterId, text)
|
|
||||||
} else if req.ObjectType == ObjectTypeVideo {
|
|
||||||
reportser.ReportVideoComment(ctx, user, req.ObjectId, text)
|
|
||||||
}
|
}
|
||||||
// app端发布评论先进入待审核状态,不立即增加业务对象评论数;后台审核通过时再统一同步 countComment
|
// app端发布评论先进入待审核状态,不立即增加业务对象评论数;后台审核通过时再统一同步 countComment
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -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
|
package configser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"videoweb/app/api/proto"
|
"strings"
|
||||||
"videoweb/app/appg"
|
"videoweb/app/appg"
|
||||||
"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
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdvitiseData 从广告中心拉取广告并更新内存缓存,列表为空时重试一次
|
||||||
|
func UpdateAdvitiseData(ctx context.Context) {
|
||||||
|
resp, err := fetchAdvertiseList()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("UpdateAdvitiseData 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("UpdateAdvitiseData 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 := proxy.AdvitiseData{}
|
||||||
AdvertiseName: ad.AdvertiseName,
|
|
||||||
AdvertiseUrl: ad.AdvertiseUrl,
|
for _, v := range list {
|
||||||
AdvertiseIcon: ad.AdvertiseIcon,
|
pos := int64(v.LocId)
|
||||||
AdvertiseType: ad.AdvertiseType,
|
info := proxy.AdvitiseInfo{
|
||||||
AdMode: ad.AdMode,
|
Id: strconv.FormatInt(v.Id, 10),
|
||||||
AppCode: ad.AppCode,
|
Location: pos,
|
||||||
LocationType: ad.LocationType,
|
Title: v.Title,
|
||||||
AdvertiseDesc: ad.AdvertiseDesc,
|
Images: netutil.MergeURL(config.ImgCdn, strings.TrimLeft(v.CoverImg, "/")),
|
||||||
PageType: ad.PageType,
|
Link: strings.ReplaceAll(v.Link, "inner://yinseinner/", "yinseinner://"),
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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.VideoTopList = append(data.VideoTopList, info)
|
||||||
resp.DetailbannerList = ads
|
data.VideoDownList = append(data.VideoDownList, info)
|
||||||
|
|
||||||
case 12:
|
case 12:
|
||||||
resp.AList = ads
|
data.AppInfoAList = append(data.AppInfoAList, info)
|
||||||
case 13:
|
case 13:
|
||||||
resp.BList = ads
|
data.AppInfoBList = append(data.AppInfoBList, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheMgr.Lock.Lock()
|
CacheMgr.Lock.Lock()
|
||||||
defer CacheMgr.Lock.Unlock()
|
defer CacheMgr.Lock.Unlock()
|
||||||
CacheMgr.Advitise = resp
|
CacheMgr.Advitise = data
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/netutil"
|
"videoweb/pub/common/netutil"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/models/announcementmod"
|
"videoweb/pub/models/announcementmod"
|
||||||
"videoweb/pub/models/cfg"
|
"videoweb/pub/models/cfg"
|
||||||
"videoweb/pub/models/ipblackmod"
|
"videoweb/pub/models/ipblackmod"
|
||||||
@@ -61,16 +60,15 @@ func init() {
|
|||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
dataReport.StartSDKConfigCron()
|
|
||||||
UpdateConfigInfo(ctx)
|
UpdateConfigInfo(ctx)
|
||||||
UpdateAdvitiseDataFromJt()
|
UpdateAdvitiseData(ctx)
|
||||||
updateIpBlack()
|
updateIpBlack()
|
||||||
updateTagsCache()
|
updateTagsCache()
|
||||||
updateAppRichTexts()
|
updateAppRichTexts()
|
||||||
updateAnnouncements()
|
updateAnnouncements()
|
||||||
_, _ = skdCron.AddFunc("0 */5 * * * ?", func() {
|
_, _ = skdCron.AddFunc("0 */5 * * * ?", func() {
|
||||||
UpdateConfigInfo(ctx)
|
UpdateConfigInfo(ctx)
|
||||||
UpdateAdvitiseDataFromJt()
|
UpdateAdvitiseData(ctx)
|
||||||
updateIpBlack()
|
updateIpBlack()
|
||||||
updateTagsCache()
|
updateTagsCache()
|
||||||
updateAppRichTexts()
|
updateAppRichTexts()
|
||||||
@@ -155,7 +153,6 @@ func UpdateConfigInfo(ctx context.Context) {
|
|||||||
config.DHSiteName = sysCfg.DHSiteName
|
config.DHSiteName = sysCfg.DHSiteName
|
||||||
config.DHTitle = sysCfg.DHTitle
|
config.DHTitle = sysCfg.DHTitle
|
||||||
config.ActressBackGround = netutil.MergeURL(sysCfg.ImgAppCdn, sysCfg.ActressBackGround)
|
config.ActressBackGround = netutil.MergeURL(sysCfg.ImgAppCdn, sysCfg.ActressBackGround)
|
||||||
config.ReportSDKConfig = dataReport.GetSDKDomainConfig()
|
|
||||||
config.WatermarkImage = sysCfg.WatermarkImage
|
config.WatermarkImage = sysCfg.WatermarkImage
|
||||||
config.CustomerServiceHost = sysCfg.CustomerServiceHost
|
config.CustomerServiceHost = sysCfg.CustomerServiceHost
|
||||||
config.ChannelCode = sysCfg.ChannelCode
|
config.ChannelCode = sysCfg.ChannelCode
|
||||||
@@ -563,7 +560,6 @@ func GetVideoTagCategoryDataList() []proto.VideoTagCategoryData {
|
|||||||
return rsl
|
return rsl
|
||||||
}
|
}
|
||||||
func Stop() {
|
func Stop() {
|
||||||
dataReport.StopSDKConfigCron()
|
|
||||||
skdCron.Stop()
|
skdCron.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"videoweb/app/api/proto"
|
"videoweb/app/api/proto"
|
||||||
"videoweb/app/service/configser"
|
"videoweb/app/service/configser"
|
||||||
"videoweb/app/service/playletcache"
|
"videoweb/app/service/playletcache"
|
||||||
"videoweb/app/service/reportser"
|
|
||||||
"videoweb/app/service/videoser"
|
"videoweb/app/service/videoser"
|
||||||
"videoweb/pub/common/enum/redisconst"
|
"videoweb/pub/common/enum/redisconst"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
@@ -919,9 +918,6 @@ func SetLike(ctx context.Context, userId int64, req *proto.PlayletLikeSetReq) (*
|
|||||||
IsLike: operateStatusByFlag(*req.IsLike),
|
IsLike: operateStatusByFlag(*req.IsLike),
|
||||||
CountLike: countLike,
|
CountLike: countLike,
|
||||||
}
|
}
|
||||||
if changed {
|
|
||||||
reportser.ReportPlayletLike(ctx, userId, req.Id, resp.IsLike)
|
|
||||||
}
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -941,9 +937,6 @@ func SetCollect(ctx context.Context, userId int64, req *proto.PlayletCollectSetR
|
|||||||
IsCollect: operateStatusByFlag(*req.IsCollect),
|
IsCollect: operateStatusByFlag(*req.IsCollect),
|
||||||
CountCollect: countCollect,
|
CountCollect: countCollect,
|
||||||
}
|
}
|
||||||
if changed {
|
|
||||||
reportser.ReportPlayletCollect(ctx, userId, req.Id, resp.IsCollect)
|
|
||||||
}
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,9 +986,6 @@ func SetChapterLike(ctx context.Context, userId int64, req *proto.PlayletChapter
|
|||||||
IsLike: operateStatusByFlag(*req.IsLike),
|
IsLike: operateStatusByFlag(*req.IsLike),
|
||||||
CountLike: countLike,
|
CountLike: countLike,
|
||||||
}
|
}
|
||||||
if changed {
|
|
||||||
reportser.ReportPlayletChapterLike(ctx, userId, chapter.PlayletId, req.ChapterId, resp.IsLike)
|
|
||||||
}
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1015,9 +1005,6 @@ func SetChapterCollect(ctx context.Context, userId int64, req *proto.PlayletChap
|
|||||||
IsCollect: operateStatusByFlag(*req.IsCollect),
|
IsCollect: operateStatusByFlag(*req.IsCollect),
|
||||||
CountCollect: countCollect,
|
CountCollect: countCollect,
|
||||||
}
|
}
|
||||||
if changed {
|
|
||||||
reportser.ReportPlayletChapterCollect(ctx, userId, chapter.PlayletId, req.ChapterId, resp.IsCollect)
|
|
||||||
}
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1281,7 +1268,6 @@ func UnlockChapter(ctx context.Context, userId int64, req *proto.PlayletChapterU
|
|||||||
return nil, srvdef.New(srvdef.DBTransaction, "解锁失败,请稍后重试", "解锁失败,请稍后重试")
|
return nil, srvdef.New(srvdef.DBTransaction, "解锁失败,请稍后重试", "解锁失败,请稍后重试")
|
||||||
}
|
}
|
||||||
updatePlayletChapterUnlockStatsAsync(chapter.PlayletId, chapter.Id)
|
updatePlayletChapterUnlockStatsAsync(chapter.PlayletId, chapter.Id)
|
||||||
reportser.ReportPlayletUnlock(ctx, user, playlet, chapter, chapter.SingleCoins, user.Recharge, balanceAfter, orderNo)
|
|
||||||
return playletChapterUnlockResp(chapter, balanceAfter, -chapter.SingleCoins), nil
|
return playletChapterUnlockResp(chapter, balanceAfter, -chapter.SingleCoins), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,18 +2,11 @@ package rechargeser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/common/useragent"
|
"videoweb/pub/common/useragent"
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/models/eventmod"
|
|
||||||
"videoweb/pub/models/rechargepackagemod"
|
"videoweb/pub/models/rechargepackagemod"
|
||||||
"videoweb/pub/models/usermod"
|
"videoweb/pub/models/usermod"
|
||||||
"videoweb/pub/models/vipordermod"
|
"videoweb/pub/models/vipordermod"
|
||||||
@@ -104,8 +97,6 @@ func CreateOrder(ctx context.Context,
|
|||||||
return nil, serr
|
return nil, serr
|
||||||
}
|
}
|
||||||
|
|
||||||
go reportOrderCreated(ctx, order, pkg, userId, ip)
|
|
||||||
|
|
||||||
return &SubmitOrderResp{
|
return &SubmitOrderResp{
|
||||||
TradeNo: tradeNo,
|
TradeNo: tradeNo,
|
||||||
PayUrl: payInfo.PayUrl,
|
PayUrl: payInfo.PayUrl,
|
||||||
@@ -138,56 +129,3 @@ func GetOrderHistory(ctx context.Context, userId int64, page, pageSize int64) (v
|
|||||||
func GetUserInfo(ctx context.Context, userId int64) (*usermod.User, *srvdef.SrvErr) {
|
func GetUserInfo(ctx context.Context, userId int64) (*usermod.User, *srvdef.SrvErr) {
|
||||||
return usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
return usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportOrderCreated(ctx context.Context, order *vipordermod.VipOrder, pkg *rechargepackagemod.RechargePackage, userId int64, ip string) {
|
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
|
||||||
districtCode := ""
|
|
||||||
if user != nil {
|
|
||||||
districtCode = user.DistrictCode
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceKey, sourceName := "deposit", "充值中心"
|
|
||||||
if order.Client != nil {
|
|
||||||
if value := strings.TrimSpace(order.Client.SourcePageKey); value != "" {
|
|
||||||
sourceKey = value
|
|
||||||
}
|
|
||||||
if value := strings.TrimSpace(order.Client.SourcePageName); value != "" {
|
|
||||||
sourceName = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ua := order.Client.UA(order.SysType)
|
|
||||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, order.TradeNo, order.CreatedAt.Unix())
|
|
||||||
commonField := dataReport.NewCommonField(eventId, dataReport.EventTypeOrderCreated, districtCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
|
|
||||||
commonField.Payload = dataReport.JsonRawMessage(&dataReport.OrderCreatedEvent{
|
|
||||||
OrderID: order.TradeNo,
|
|
||||||
OrderType: "vip_subscription",
|
|
||||||
ProductID: strconv.FormatInt(pkg.Id, 10),
|
|
||||||
ProductName: pkg.Name,
|
|
||||||
Amount: dataReport.JsonNumber(order.Amount),
|
|
||||||
Currency: "CNY",
|
|
||||||
SourcePageKey: sourceKey,
|
|
||||||
SourcePageName: sourceName,
|
|
||||||
CreateTime: dataReport.JsonNumber(order.CreatedAt.Unix()),
|
|
||||||
})
|
|
||||||
|
|
||||||
eventData, _ := json.Marshal(commonField)
|
|
||||||
if err := eventmod.InsertOneEvent(ctx, &eventmod.Event{
|
|
||||||
EventId: commonField.EventID,
|
|
||||||
EventType: commonField.Event,
|
|
||||||
Data: string(eventData),
|
|
||||||
Status: eventmod.Default,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error("reportOrderCreated InsertOneEvent failed",
|
|
||||||
log.Any("tradeNo", order.TradeNo), log.E(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
|
|
||||||
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
|
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(input))
|
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,559 +0,0 @@
|
|||||||
package reportser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"videoweb/app/service/playletcache"
|
|
||||||
"videoweb/pub/common"
|
|
||||||
"videoweb/pub/common/enum/consts"
|
|
||||||
"videoweb/pub/common/ipaddr"
|
|
||||||
"videoweb/pub/common/log"
|
|
||||||
"videoweb/pub/common/useragent"
|
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/models/eventmod"
|
|
||||||
"videoweb/pub/models/playletchaptermod"
|
|
||||||
"videoweb/pub/models/playletmod"
|
|
||||||
"videoweb/pub/models/usermod"
|
|
||||||
"videoweb/pub/models/videoinformationmod"
|
|
||||||
"videoweb/pub/pubdef"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
videoContentTypeVideo = "video"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReportUserRegister 用户注册事件
|
|
||||||
func ReportUserRegister(user *usermod.User, ua useragent.UA, ip, registerType string) {
|
|
||||||
if user == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if registerType == "" {
|
|
||||||
registerType = "deviceid"
|
|
||||||
}
|
|
||||||
ua = fillUserUA(user, ua)
|
|
||||||
createAt := user.CreatedAt
|
|
||||||
if !user.RegisterTime.IsZero() {
|
|
||||||
createAt = user.RegisterTime
|
|
||||||
}
|
|
||||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, "", createAt.Unix())
|
|
||||||
event := dataReport.NewCommonField(eventId, dataReport.EventTypeUserRegister, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.UserRegisterEvent{
|
|
||||||
Type: registerType,
|
|
||||||
CreateTime: dataReport.JsonNumber(createAt.Unix()),
|
|
||||||
})
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportUserLogin 用户登录事件
|
|
||||||
func ReportUserLogin(user *usermod.User, ua useragent.UA, ip string, loginType pubdef.LoginType) {
|
|
||||||
if user == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua = fillUserUA(user, ua)
|
|
||||||
createTime := time.Now().Unix()
|
|
||||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, "", createTime)
|
|
||||||
event := dataReport.NewCommonField(eventId, dataReport.EventTypeUserLogin, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.UserLoginEvent{
|
|
||||||
Type: loginTypeEventValue(loginType),
|
|
||||||
})
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportPlayletLike 短剧点赞
|
|
||||||
func ReportPlayletLike(ctx context.Context, userId, playletId, flag int64) {
|
|
||||||
reportDramaEvent(ctx, userId, playletId, 0, dataReport.EventTypeDramaLike, flag, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportVideoLike 视频点赞
|
|
||||||
func ReportVideoLike(ctx context.Context, userId, videoId, flag int64) {
|
|
||||||
reportVideoEvent(ctx, userId, videoId, dataReport.EventTypeVideoLike, flag)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportPlayletCollect 短剧收藏
|
|
||||||
func ReportPlayletCollect(ctx context.Context, userId, playletId, flag int64) {
|
|
||||||
reportDramaEvent(ctx, userId, playletId, 0, dataReport.EventTypeDramaCollect, flag, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportVideoCollect 视频收藏
|
|
||||||
func ReportVideoCollect(ctx context.Context, userId, videoId, flag int64) {
|
|
||||||
reportVideoEvent(ctx, userId, videoId, dataReport.EventTypeVideoCollect, flag)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportVideoComment 视频评论
|
|
||||||
func ReportVideoComment(ctx context.Context, user *usermod.User, videoId int64, content string) {
|
|
||||||
if user == nil || videoId <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pub := buildVideoPub(ctx, videoId)
|
|
||||||
if pub.VideoID == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua, ip := uaAndIPFromCtx(ctx)
|
|
||||||
ua = fillUserUA(user, ua)
|
|
||||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeVideoComment, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoCommentEvent{
|
|
||||||
VideoEventPub: pub,
|
|
||||||
CommentContent: content,
|
|
||||||
})
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportPlayletChapterLike 短剧剧集点赞
|
|
||||||
func ReportPlayletChapterLike(ctx context.Context, userId, playletId, chapterId, flag int64) {
|
|
||||||
reportDramaEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeDramaLike, flag, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportPlayletChapterCollect 短剧剧集收藏
|
|
||||||
func ReportPlayletChapterCollect(ctx context.Context, userId, playletId, chapterId, flag int64) {
|
|
||||||
reportDramaEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeDramaCollect, flag, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportPlayletComment 短剧/剧集评论
|
|
||||||
func ReportPlayletComment(ctx context.Context, user *usermod.User, playletId, chapterId int64, content string) {
|
|
||||||
if user == nil || playletId <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pub := buildDramaPub(ctx, playletId, chapterId)
|
|
||||||
if pub.DramaID == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua, ip := uaAndIPFromCtx(ctx)
|
|
||||||
ua = fillUserUA(user, ua)
|
|
||||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeDramaComment, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCommentEvent{
|
|
||||||
DramaEventPub: pub,
|
|
||||||
CommentContent: content,
|
|
||||||
})
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportPlayletUnlock 短剧剧集金币解锁:同时上报金币消耗和购买
|
|
||||||
func ReportPlayletUnlock(ctx context.Context, user *usermod.User, playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter, amount, balanceBefore, balanceAfter int64, orderNo string) {
|
|
||||||
if user == nil || playlet == nil || chapter == nil || amount <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if full, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: user.Id}); err == nil && full != nil {
|
|
||||||
user = full
|
|
||||||
}
|
|
||||||
ua, ip := uaAndIPFromCtx(ctx)
|
|
||||||
ua = fillUserUA(user, ua)
|
|
||||||
productId := strconv.FormatInt(chapter.Id, 10)
|
|
||||||
productName := playletUnlockProductName(playlet, chapter)
|
|
||||||
reportCoinConsume(user, ua, ip, productId, productName, amount, balanceBefore, balanceAfter, KeyPlayletUnlock, orderNo)
|
|
||||||
reportDramaPurchase(ctx, user, ua, ip, playlet, chapter, amount, orderNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReportPlayletStatusChange 短剧上下架,复用 video_status_change
|
|
||||||
func ReportPlayletStatusChange(playlet *playletmod.Playlet, flag int64) {
|
|
||||||
if playlet == nil || playlet.Id == 0 || flag == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
typeID, typeName := resolvePlayletType(playlet)
|
|
||||||
event := dataReport.NewCommonField("", dataReport.EventTypeVideoStatusChange, "", useragent.UA{}, "", "")
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoStatusChangeEvent{
|
|
||||||
MediaId: playletMediaId(playlet),
|
|
||||||
VideoID: strconv.FormatInt(playlet.Id, 10),
|
|
||||||
VideoTitle: playlet.Title,
|
|
||||||
VideoTypeID: typeID,
|
|
||||||
VideoTypeName: typeName,
|
|
||||||
Flag: dataReport.JsonNumber(flag),
|
|
||||||
})
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PlayletStatusFlag 短剧上下架映射上报 flag:1上架 2下架
|
|
||||||
func PlayletStatusFlag(status playletmod.Status) int64 {
|
|
||||||
switch status {
|
|
||||||
case playletmod.StatusUp:
|
|
||||||
return 1
|
|
||||||
case playletmod.StatusDown:
|
|
||||||
return 2
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func reportDramaEvent(ctx context.Context, userId, playletId, chapterId int64, eventType string, flag int64, content string) {
|
|
||||||
if userId <= 0 || playletId <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
user, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
|
||||||
if err != nil || user == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pub := buildDramaPub(ctx, playletId, chapterId)
|
|
||||||
if pub.DramaID == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua, ip := uaAndIPFromCtx(ctx)
|
|
||||||
ua = fillUserUA(user, ua)
|
|
||||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), eventType, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
switch eventType {
|
|
||||||
case dataReport.EventTypeDramaLike:
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaLikeEvent{
|
|
||||||
DramaEventPub: pub,
|
|
||||||
Flag: dataReport.JsonNumber(flag),
|
|
||||||
})
|
|
||||||
case dataReport.EventTypeDramaCollect:
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCollectEvent{
|
|
||||||
DramaEventPub: pub,
|
|
||||||
Flag: dataReport.JsonNumber(flag),
|
|
||||||
})
|
|
||||||
case dataReport.EventTypeDramaComment:
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCommentEvent{
|
|
||||||
DramaEventPub: pub,
|
|
||||||
CommentContent: content,
|
|
||||||
})
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func reportVideoEvent(ctx context.Context, userId, videoId int64, eventType string, flag int64) {
|
|
||||||
if userId <= 0 || videoId <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
user, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
|
||||||
if err != nil || user == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pub := buildVideoPub(ctx, videoId)
|
|
||||||
if pub.VideoID == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ua, ip := uaAndIPFromCtx(ctx)
|
|
||||||
ua = fillUserUA(user, ua)
|
|
||||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), eventType, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
switch eventType {
|
|
||||||
case dataReport.EventTypeVideoLike:
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoLikeEvent{
|
|
||||||
VideoEventPub: pub,
|
|
||||||
Flag: dataReport.JsonNumber(flag),
|
|
||||||
})
|
|
||||||
case dataReport.EventTypeVideoCollect:
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoCollectEvent{
|
|
||||||
VideoEventPub: pub,
|
|
||||||
Flag: dataReport.JsonNumber(flag),
|
|
||||||
})
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func reportCoinConsume(user *usermod.User, ua useragent.UA, ip, productId, productName string, amount, balanceBefore, balanceAfter int64, reason Key, orderId string) {
|
|
||||||
if user == nil || amount == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if productId == "" {
|
|
||||||
if productName == "" {
|
|
||||||
productName = "金币消耗"
|
|
||||||
}
|
|
||||||
productId = md5String(productName)
|
|
||||||
}
|
|
||||||
createTime := time.Now().Unix()
|
|
||||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, orderId, createTime)
|
|
||||||
event := dataReport.NewCommonField(eventId, dataReport.EventTypeCoinConsume, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.CoinConsumeEvent{
|
|
||||||
ProductID: productId,
|
|
||||||
ProductName: productName,
|
|
||||||
CoinConsumeAmount: dataReport.JsonNumber(amount),
|
|
||||||
CoinBalanceBefore: dataReport.JsonNumber(balanceBefore),
|
|
||||||
CoinBalanceAfter: dataReport.JsonNumber(balanceAfter),
|
|
||||||
ConsumeReasonKey: reason.Key(),
|
|
||||||
ConsumeReasonName: reason.Name(),
|
|
||||||
CreateTime: dataReport.JsonNumber(createTime),
|
|
||||||
OrderId: orderId,
|
|
||||||
})
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func reportDramaPurchase(ctx context.Context, user *usermod.User, ua useragent.UA, ip string, playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter, amount int64, orderId string) {
|
|
||||||
pub := dataReport.DramaEventPub{}
|
|
||||||
if playlet != nil && chapter != nil && chapter.Id > 0 {
|
|
||||||
pub = buildDramaPub(ctx, playlet.Id, chapter.Id)
|
|
||||||
}
|
|
||||||
if pub.DramaID == "" {
|
|
||||||
pub = playletToDramaPub(playlet, chapter)
|
|
||||||
}
|
|
||||||
if pub.DramaID == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeDramaPurchase, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaPurchaseEvent{
|
|
||||||
DramaEventPub: pub,
|
|
||||||
CoinQuantity: dataReport.JsonNumber(amount),
|
|
||||||
OrderID: orderId,
|
|
||||||
UnlockType: dataReport.DramaUnlockTypeCoin,
|
|
||||||
})
|
|
||||||
insertEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildDramaPub(ctx context.Context, playletId, chapterId int64) dataReport.DramaEventPub {
|
|
||||||
playlet, err := playletmod.FindOnePlaylet(ctx, bson.M{playletmod.FN.Playlet.Id: playletId}, options.FindOne().SetProjection(bson.D{
|
|
||||||
{Key: playletmod.FN.Playlet.Id, Value: 1},
|
|
||||||
{Key: playletmod.FN.Playlet.Title, Value: 1},
|
|
||||||
{Key: playletmod.FN.Playlet.ThemeIds, Value: 1},
|
|
||||||
{Key: playletmod.FN.Playlet.TagIds, Value: 1},
|
|
||||||
{Key: playletmod.FN.Playlet.TotalEpisode, Value: 1},
|
|
||||||
}))
|
|
||||||
if err != nil || playlet == nil {
|
|
||||||
return dataReport.DramaEventPub{}
|
|
||||||
}
|
|
||||||
chapter := findDramaReportChapter(ctx, playletId, chapterId)
|
|
||||||
return playletToDramaPub(playlet, chapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
// findDramaReportChapter 取上报用剧集。指定了剧集就用该集,短剧维度事件用第一集,保证 drama_id、video_id 都来自剧集。
|
|
||||||
func findDramaReportChapter(ctx context.Context, playletId, chapterId int64) *playletchaptermod.PlayletChapter {
|
|
||||||
projection := options.FindOne().SetProjection(bson.D{
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.Id, Value: 1},
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.PlayletId, Value: 1},
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.MediaContentId, Value: 1},
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.Title, Value: 1},
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.CurrentEpisode, Value: 1},
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.MediaTime, Value: 1},
|
|
||||||
})
|
|
||||||
if chapterId > 0 {
|
|
||||||
chapter, _ := playletchaptermod.FindOnePlayletChapter(ctx, bson.M{playletchaptermod.FN.PlayletChapter.Id: chapterId}, projection)
|
|
||||||
return chapter
|
|
||||||
}
|
|
||||||
chapter, _ := playletchaptermod.FindOnePlayletChapter(ctx, bson.M{playletchaptermod.FN.PlayletChapter.PlayletId: playletId}, projection.SetSort(bson.D{
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.CurrentEpisode, Value: 1},
|
|
||||||
{Key: playletchaptermod.FN.PlayletChapter.Id, Value: 1},
|
|
||||||
}))
|
|
||||||
return chapter
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildVideoPub(ctx context.Context, videoId int64) dataReport.VideoEventPub {
|
|
||||||
video, err := videoinformationmod.FindOneVideoInformationWithOptions(ctx, bson.M{videoinformationmod.FN.VideoInformation.Id: videoId}, options.FindOne().SetProjection(bson.D{
|
|
||||||
{Key: videoinformationmod.FN.VideoInformation.Id, Value: 1},
|
|
||||||
{Key: videoinformationmod.FN.VideoInformation.Title, Value: 1},
|
|
||||||
{Key: videoinformationmod.FN.VideoInformation.MediaType, Value: 1},
|
|
||||||
{Key: videoinformationmod.FN.VideoInformation.Video.FileId, Value: 1},
|
|
||||||
{Key: videoinformationmod.FN.VideoInformation.Video.TaskId, Value: 1},
|
|
||||||
{Key: videoinformationmod.FN.VideoInformation.SyncId, Value: 1},
|
|
||||||
}))
|
|
||||||
if err != nil || video == nil {
|
|
||||||
return dataReport.VideoEventPub{}
|
|
||||||
}
|
|
||||||
return videoToVideoPub(video)
|
|
||||||
}
|
|
||||||
|
|
||||||
func videoToVideoPub(video *videoinformationmod.VideoInformation) dataReport.VideoEventPub {
|
|
||||||
if video == nil {
|
|
||||||
return dataReport.VideoEventPub{}
|
|
||||||
}
|
|
||||||
mediaId := video.Video.FileId
|
|
||||||
if mediaId == "" {
|
|
||||||
mediaId = video.Video.TaskId
|
|
||||||
}
|
|
||||||
if mediaId == "" {
|
|
||||||
mediaId = video.SyncId
|
|
||||||
}
|
|
||||||
return dataReport.VideoEventPub{
|
|
||||||
MediaId: mediaId,
|
|
||||||
VideoID: strconv.FormatInt(video.Id, 10),
|
|
||||||
VideoTitle: video.Title,
|
|
||||||
VideoTypeID: strconv.FormatInt(int64(video.MediaType), 10),
|
|
||||||
VideoTypeName: videoMediaTypeName(video.MediaType),
|
|
||||||
VideoContentType: videoContentTypeVideo,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func playletToDramaPub(playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter) dataReport.DramaEventPub {
|
|
||||||
if playlet == nil {
|
|
||||||
return dataReport.DramaEventPub{}
|
|
||||||
}
|
|
||||||
typeID, typeName := resolvePlayletType(playlet)
|
|
||||||
tagKey, tagName := resolvePlayletTags(playlet.TagIds)
|
|
||||||
episode := int64(1)
|
|
||||||
duration := int64(0)
|
|
||||||
dramaID := ""
|
|
||||||
videoID := ""
|
|
||||||
if chapter != nil && chapter.Id > 0 {
|
|
||||||
if chapter.CurrentEpisode > 0 {
|
|
||||||
episode = chapter.CurrentEpisode
|
|
||||||
}
|
|
||||||
duration = chapter.MediaTime
|
|
||||||
dramaID = strconv.FormatInt(chapter.Id, 10)
|
|
||||||
if chapter.MediaContentId > 0 {
|
|
||||||
videoID = strconv.FormatUint(uint64(chapter.MediaContentId), 10)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dataReport.DramaEventPub{
|
|
||||||
DramaID: dramaID,
|
|
||||||
DramaTitle: playlet.Title,
|
|
||||||
Episode: dataReport.JsonNumber(episode),
|
|
||||||
VideoID: videoID,
|
|
||||||
TotalEpisode: dataReport.JsonNumber(playlet.TotalEpisode),
|
|
||||||
DramaTypeID: typeID,
|
|
||||||
DramaTypeName: typeName,
|
|
||||||
DramaContentType: dataReport.DramaContentTypeShortDrama,
|
|
||||||
DramaTagKey: tagKey,
|
|
||||||
DramaTagName: tagName,
|
|
||||||
DramaDuration: dataReport.JsonNumber(duration),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func videoMediaTypeName(mediaType videoinformationmod.MediaType) string {
|
|
||||||
switch mediaType {
|
|
||||||
case videoinformationmod.MediaType_Video:
|
|
||||||
return "视频"
|
|
||||||
case videoinformationmod.MediaType_Collection:
|
|
||||||
return "合集"
|
|
||||||
case videoinformationmod.MediaType_Advitise:
|
|
||||||
return "广告"
|
|
||||||
case videoinformationmod.MediaType_VideoV2:
|
|
||||||
return "视频"
|
|
||||||
default:
|
|
||||||
return "视频"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func playletUnlockProductName(playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter) string {
|
|
||||||
title := ""
|
|
||||||
if playlet != nil {
|
|
||||||
title = playlet.Title
|
|
||||||
}
|
|
||||||
if chapter == nil {
|
|
||||||
return title
|
|
||||||
}
|
|
||||||
if chapter.Title != "" {
|
|
||||||
if title == "" {
|
|
||||||
return chapter.Title
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s %s", title, chapter.Title)
|
|
||||||
}
|
|
||||||
if chapter.CurrentEpisode > 0 {
|
|
||||||
if title == "" {
|
|
||||||
return fmt.Sprintf("第%d集", chapter.CurrentEpisode)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s 第%d集", title, chapter.CurrentEpisode)
|
|
||||||
}
|
|
||||||
return title
|
|
||||||
}
|
|
||||||
|
|
||||||
func playletMediaId(playlet *playletmod.Playlet) string {
|
|
||||||
if playlet == nil || playlet.MediaCenterId == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return strconv.FormatUint(uint64(playlet.MediaCenterId), 10)
|
|
||||||
}
|
|
||||||
|
|
||||||
func resolvePlayletType(playlet *playletmod.Playlet) (string, string) {
|
|
||||||
if playlet == nil || len(playlet.ThemeIds) == 0 {
|
|
||||||
return "default", "默认分类"
|
|
||||||
}
|
|
||||||
id := playlet.ThemeIds[0]
|
|
||||||
if id <= 0 {
|
|
||||||
return "default", "默认分类"
|
|
||||||
}
|
|
||||||
name := strings.TrimSpace(playletcache.ThemeNameMap([]int64{id})[id])
|
|
||||||
if name == "" {
|
|
||||||
name = "默认分类"
|
|
||||||
}
|
|
||||||
return strconv.FormatInt(id, 10), name
|
|
||||||
}
|
|
||||||
|
|
||||||
func resolvePlayletTags(ids []int64) (string, string) {
|
|
||||||
keys := make([]string, 0, len(ids))
|
|
||||||
for _, id := range ids {
|
|
||||||
if id > 0 {
|
|
||||||
keys = append(keys, strconv.FormatInt(id, 10))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(keys) == 0 {
|
|
||||||
return "default", "默认标签"
|
|
||||||
}
|
|
||||||
nameMap := playletcache.TagNameMap(ids)
|
|
||||||
names := make([]string, 0, len(keys))
|
|
||||||
for _, id := range ids {
|
|
||||||
if id <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name := strings.TrimSpace(nameMap[id])
|
|
||||||
if name == "" {
|
|
||||||
name = strconv.FormatInt(id, 10)
|
|
||||||
}
|
|
||||||
names = append(names, name)
|
|
||||||
}
|
|
||||||
return strings.Join(keys, ","), strings.Join(names, ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
func uaAndIPFromCtx(ctx context.Context) (useragent.UA, string) {
|
|
||||||
gc, ok := ctx.(*gin.Context)
|
|
||||||
if !ok {
|
|
||||||
if v := ctx.Value(consts.CtxUA); v != nil {
|
|
||||||
if ua, ok := v.(useragent.UA); ok {
|
|
||||||
return ua, ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return useragent.UA{}, ""
|
|
||||||
}
|
|
||||||
ua, _ := common.GetUA(gc)
|
|
||||||
return ua, ipaddr.ResolveClientIP(gc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fillUserUA(user *usermod.User, ua useragent.UA) useragent.UA {
|
|
||||||
if user == nil {
|
|
||||||
return ua
|
|
||||||
}
|
|
||||||
if ua.DevID == "" {
|
|
||||||
ua.DevID = user.DevID
|
|
||||||
}
|
|
||||||
if ua.DevType == "" {
|
|
||||||
ua.DevType = user.Device
|
|
||||||
}
|
|
||||||
if ua.SysType == "" {
|
|
||||||
ua.SysType = user.SysType
|
|
||||||
}
|
|
||||||
return ua
|
|
||||||
}
|
|
||||||
|
|
||||||
func loginTypeEventValue(loginType pubdef.LoginType) string {
|
|
||||||
switch loginType {
|
|
||||||
case pubdef.LoginTypeAccount:
|
|
||||||
return "username"
|
|
||||||
case pubdef.LoginTypeEmail:
|
|
||||||
return "email"
|
|
||||||
default:
|
|
||||||
return "deviceid"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
|
|
||||||
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
|
|
||||||
return md5String(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
func md5String(input string) string {
|
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(input))
|
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
func insertEvent(event dataReport.CommonField) {
|
|
||||||
b, _ := json.Marshal(event)
|
|
||||||
if err := eventmod.InsertOneEvent(context.Background(), &eventmod.Event{
|
|
||||||
EventId: event.EventID,
|
|
||||||
EventType: event.Event,
|
|
||||||
Data: string(b),
|
|
||||||
Status: eventmod.Default,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error("reportser insertEvent failed", log.Any("eventType", event.Event), log.Any("eventId", event.EventID), log.E(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package reportser
|
|
||||||
|
|
||||||
type Key string
|
|
||||||
|
|
||||||
const (
|
|
||||||
KeyPlayletUnlock Key = "playlet_unlock" // 短剧剧集解锁
|
|
||||||
KeyCoinConsume Key = "coin_consume" // 金币消耗
|
|
||||||
)
|
|
||||||
|
|
||||||
var keyMap = map[Key]string{
|
|
||||||
KeyPlayletUnlock: "短剧解锁",
|
|
||||||
KeyCoinConsume: "金币消耗",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Key) Name() string {
|
|
||||||
return keyMap[p]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Key) Key() string {
|
|
||||||
return string(p)
|
|
||||||
}
|
|
||||||
@@ -123,14 +123,14 @@ func GetM3U8Ex(ctx *gin.Context) {
|
|||||||
mediaID, expireAt, origM3u8Name, ip, ticket,
|
mediaID, expireAt, origM3u8Name, ip, ticket,
|
||||||
)
|
)
|
||||||
|
|
||||||
if !ticketOK {
|
// if !ticketOK {
|
||||||
m3u8Name = H5M3U8FallbackPath
|
// m3u8Name = H5M3U8FallbackPath
|
||||||
log.Warn("【GetM3U8Ex】H5播放票据无效",
|
// log.Warn("【GetM3U8Ex】H5播放票据无效",
|
||||||
log.Any("mediaId", mediaID),
|
// log.Any("mediaId", mediaID),
|
||||||
log.Any("expireAt", expireAt),
|
// log.Any("expireAt", expireAt),
|
||||||
log.Any("ip", ip),
|
// log.Any("ip", ip),
|
||||||
log.Any("hasTicket", ticket != ""))
|
// log.Any("hasTicket", ticket != ""))
|
||||||
}
|
// }
|
||||||
|
|
||||||
countTowardDailyLimit := ticketOK && ticketInfo.Playable && !ticketInfo.Preview
|
countTowardDailyLimit := ticketOK && ticketInfo.Playable && !ticketInfo.Preview
|
||||||
if countTowardDailyLimit && appg.Conf.RunMod == string(consts.RunModeProd) {
|
if countTowardDailyLimit && appg.Conf.RunMod == string(consts.RunModeProd) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"videoweb/app/api/proto"
|
"videoweb/app/api/proto"
|
||||||
"videoweb/app/service/configser"
|
"videoweb/app/service/configser"
|
||||||
"videoweb/app/service/reportser"
|
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/netutil"
|
"videoweb/pub/common/netutil"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
@@ -255,9 +254,6 @@ func SetLike(ctx context.Context, userId int64, req *proto.VideoLikeSetReq) (*pr
|
|||||||
IsLike: videoOperateStatusByFlag(*req.IsLike),
|
IsLike: videoOperateStatusByFlag(*req.IsLike),
|
||||||
CountLike: countLike,
|
CountLike: countLike,
|
||||||
}
|
}
|
||||||
if changed {
|
|
||||||
reportser.ReportVideoLike(ctx, userId, req.Id, resp.IsLike)
|
|
||||||
}
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,9 +273,6 @@ func SetCollect(ctx context.Context, userId int64, req *proto.VideoCollectSetReq
|
|||||||
IsCollect: videoOperateStatusByFlag(*req.IsCollect),
|
IsCollect: videoOperateStatusByFlag(*req.IsCollect),
|
||||||
CountCollect: countCollect,
|
CountCollect: countCollect,
|
||||||
}
|
}
|
||||||
if changed {
|
|
||||||
reportser.ReportVideoCollect(ctx, userId, req.Id, resp.IsCollect)
|
|
||||||
}
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ const (
|
|||||||
FiveMVisit = "bd_visitFmt:%s"
|
FiveMVisit = "bd_visitFmt:%s"
|
||||||
BloomUser = "bd_bloom_user:%d"
|
BloomUser = "bd_bloom_user:%d"
|
||||||
AppUserToken = "bd_app_user_token:%d"
|
AppUserToken = "bd_app_user_token:%d"
|
||||||
|
appDeviceUserFmt = "app:device:user:%s"
|
||||||
|
appDeviceUserLockFmt = "app:device:user:lock:%s"
|
||||||
|
AppDeviceUserExpire = 10 * time.Minute
|
||||||
|
AppDeviceUserLockExpire = 5 * time.Second
|
||||||
captchaKey = "bd_captcha_mobile_%s"
|
captchaKey = "bd_captcha_mobile_%s"
|
||||||
CaptchaExpire = 5 * time.Minute
|
CaptchaExpire = 5 * time.Minute
|
||||||
replayNonceKey = "bd_replay:nonce:_%s"
|
replayNonceKey = "bd_replay:nonce:_%s"
|
||||||
@@ -209,3 +213,13 @@ func M3U8DailyMediaUserKey(userId int64, mediaId int64) string {
|
|||||||
func M3U8UserVipExpireKey(userId int64) string {
|
func M3U8UserVipExpireKey(userId int64) string {
|
||||||
return fmt.Sprintf(m3u8UserVipExpireFmt, userId)
|
return fmt.Sprintf(m3u8UserVipExpireFmt, userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AppDeviceUserKey 设备ID到用户ID的缓存
|
||||||
|
func AppDeviceUserKey(devID string) string {
|
||||||
|
return fmt.Sprintf(appDeviceUserFmt, devID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppDeviceUserLockKey 按设备ID创建用户时的并发锁
|
||||||
|
func AppDeviceUserLockKey(devID string) string {
|
||||||
|
return fmt.Sprintf(appDeviceUserLockFmt, devID)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,266 +0,0 @@
|
|||||||
package dataReport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"videoweb/pub/common/godef"
|
|
||||||
"videoweb/pub/common/log"
|
|
||||||
"videoweb/pub/common/useragent"
|
|
||||||
"videoweb/pub/pubdef"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/moul/http2curl"
|
|
||||||
)
|
|
||||||
|
|
||||||
var config = Config{}
|
|
||||||
|
|
||||||
func Init(c Config) {
|
|
||||||
config = c
|
|
||||||
// 根据运行模式设置SDK配置API地址
|
|
||||||
switch c.RunMod {
|
|
||||||
case "prod", "release":
|
|
||||||
sdkConfigAPIURL = sdkConfigAPIProd
|
|
||||||
default:
|
|
||||||
sdkConfigAPIURL = sdkConfigAPIDev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateGlobalEventID 生成全局唯一的 event_id
|
|
||||||
func GenerateGlobalEventID() string {
|
|
||||||
// 生成一个新的 UUID
|
|
||||||
return strings.ReplaceAll(uuid.New().String(), "-", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func AsyncReport(eventData interface{}, retryCount int) {
|
|
||||||
// TODO 后续可改成kafka异步处理
|
|
||||||
godef.Go(func() {
|
|
||||||
// 自动重试
|
|
||||||
baseDelay := 1 * time.Second
|
|
||||||
for i := 0; i < retryCount; i++ {
|
|
||||||
err := report(eventData)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event.report failed", log.Any("retryCount", retryCount), log.Any("eventData", eventData), log.E(err))
|
|
||||||
// 指数退避 + 随机抖动
|
|
||||||
sleepTime := time.Duration(math.Pow(2, float64(i)))*baseDelay + time.Duration(rand.Intn(1000))*time.Millisecond
|
|
||||||
time.Sleep(sleepTime)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上报事件
|
|
||||||
func report(eventData interface{}) error {
|
|
||||||
// 将结构体转换为表单数据
|
|
||||||
formData, err := structToFormData(eventData)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
apiUrl := config.ApiUrl + "/api/eventTracking/report.json"
|
|
||||||
req, err := http.NewRequest("POST", apiUrl, bytes.NewBufferString(formData))
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report NewRequest fail", log.E(err))
|
|
||||||
return fmt.Errorf("failed to create request: %v", err)
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
client := &http.Client{
|
|
||||||
Timeout: 5 * time.Second, // 设置超时时间为 5 秒
|
|
||||||
}
|
|
||||||
command, _ := http2curl.GetCurlCommand(req)
|
|
||||||
fmt.Println(command)
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report fail", log.E(err))
|
|
||||||
return fmt.Errorf("failed to send request: %v", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
log.Error("Event report fail", log.Any("http.code", resp.StatusCode))
|
|
||||||
return fmt.Errorf("failed to report event, http.code: %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
// 读取返回的 body
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report fail", log.E(err))
|
|
||||||
return fmt.Errorf("failed to read response body: %v", err)
|
|
||||||
}
|
|
||||||
res := &Response{}
|
|
||||||
err = json.Unmarshal(body, res)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report json.Unmarshal(body, res) fail", log.Any("body", string(body)), log.E(err))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if res.Code != 0 {
|
|
||||||
log.Error("Event report fail", log.Any("code", res.Code), log.Any("msg", res.Msg), log.Any("data", res.Data))
|
|
||||||
return fmt.Errorf("failed to report event, res.code: %d", res.Code)
|
|
||||||
}
|
|
||||||
// 输出响应状态和返回的 body
|
|
||||||
log.Info("Event report Response", log.Any("eventData", eventData), log.Any("body", string(body)))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func structToFormData(data interface{}) (string, error) {
|
|
||||||
// 序列化结构体为 JSON 字符串
|
|
||||||
jsonData, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 反序列化为 map
|
|
||||||
var dataMap map[string]interface{}
|
|
||||||
err = json.Unmarshal(jsonData, &dataMap)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var formData []string
|
|
||||||
|
|
||||||
// 遍历 map,将其转换为 form 数据
|
|
||||||
for key, value := range dataMap {
|
|
||||||
if value == nil {
|
|
||||||
continue // 如果值为 nil,跳过
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将值转换为字符串
|
|
||||||
valueStr := fmt.Sprintf("%v", value)
|
|
||||||
|
|
||||||
// 使用 URL 编码
|
|
||||||
formData = append(formData, fmt.Sprintf(
|
|
||||||
"%s=%s",
|
|
||||||
url.QueryEscape(key),
|
|
||||||
url.QueryEscape(valueStr),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(formData, "&"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCommonField(eventId, event string, districtCode string, ua useragent.UA, uid, ip string) CommonField {
|
|
||||||
return NewCommonFieldAt(eventId, event, districtCode, ua, uid, ip, time.Now().Unix())
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCommonFieldAt(eventId, event string, districtCode string, ua useragent.UA, uid, ip string, clientTS int64) CommonField {
|
|
||||||
channel := strings.TrimSpace(districtCode)
|
|
||||||
if eventId == "" {
|
|
||||||
eventId = GenerateGlobalEventID()
|
|
||||||
}
|
|
||||||
// 五项公共字段和 app_version 使用当前请求中的 SDK 原值。
|
|
||||||
// device_id 只取 SDK,不用业务 DevID 补,避免和客户端埋点不是同一个编号。
|
|
||||||
// device 为空时才用本次请求的 SysType 映射成 Android / iOS / PC。
|
|
||||||
sdk := ua.SDKCommon
|
|
||||||
if missing := sdk.MissingFields(); len(missing) > 0 {
|
|
||||||
log.Warn("【SDK公共参数缺失】NewCommonFieldAt",
|
|
||||||
log.Any("接口", ua.RequestPath), log.Any("事件", event),
|
|
||||||
log.Any("eventId", eventId), log.Any("userId", uid), log.Any("客户端版本", ua.Ver),
|
|
||||||
log.Any("已获取SDK参数", sdk != nil), log.Any("缺失字段", missing))
|
|
||||||
}
|
|
||||||
if sdk == nil {
|
|
||||||
sdk = &useragent.SDKCommonFields{}
|
|
||||||
}
|
|
||||||
sid := strings.TrimSpace(sdk.SID)
|
|
||||||
if sid == "" {
|
|
||||||
sid = strings.TrimSpace(ua.SessionID)
|
|
||||||
}
|
|
||||||
return CommonField{
|
|
||||||
UID: uid,
|
|
||||||
EventID: eventId,
|
|
||||||
Event: event,
|
|
||||||
Channel: channel,
|
|
||||||
AppID: pubdef.TrackerAppId(),
|
|
||||||
AppVersion: sdk.AppVersion,
|
|
||||||
ClientTS: fmt.Sprintf("%v", clientTS),
|
|
||||||
Device: reportDevice(sdk.Device, ua.SysType, ua.SystemName),
|
|
||||||
DeviceID: sdk.DeviceID,
|
|
||||||
DeviceFingerprint: sdk.DeviceFingerprint,
|
|
||||||
FPVersion: sdk.FPVersion,
|
|
||||||
UserAgent: strings.TrimSpace(ua.UserAgent),
|
|
||||||
DeviceBrand: strings.TrimSpace(ua.DeviceBrand),
|
|
||||||
DeviceModel: strings.TrimSpace(ua.DeviceModel),
|
|
||||||
SystemName: strings.TrimSpace(ua.SystemName),
|
|
||||||
SystemVersion: strings.TrimSpace(ua.SystemVersion),
|
|
||||||
SID: sid,
|
|
||||||
IP: ip,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// reportDevice 优先使用 SDK 的设备类型。SDK 没给时,用本次请求的系统类型映射。
|
|
||||||
func reportDevice(sdkDevice, sysType, systemName string) string {
|
|
||||||
if device := strings.TrimSpace(sdkDevice); device != "" {
|
|
||||||
return device
|
|
||||||
}
|
|
||||||
text := strings.ToLower(strings.TrimSpace(sysType) + " " + strings.TrimSpace(systemName))
|
|
||||||
// "macos" 含 "ios",先归一化,避免 Mac 被判成 iOS。
|
|
||||||
text = strings.ReplaceAll(text, "macos", "mac")
|
|
||||||
switch {
|
|
||||||
case strings.Contains(text, "ios") || strings.Contains(text, "iphone") || strings.Contains(text, "ipad"):
|
|
||||||
return "iOS"
|
|
||||||
case strings.Contains(text, "android"):
|
|
||||||
return "Android"
|
|
||||||
case strings.Contains(text, "pc") || strings.Contains(text, "windows") || strings.Contains(text, "mac") || strings.Contains(text, "linux") || strings.Contains(text, "h5"):
|
|
||||||
return "PC"
|
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func JsonNumber(v int64) json.Number {
|
|
||||||
return json.Number(strconv.FormatInt(v, 10))
|
|
||||||
}
|
|
||||||
func JsonRawMessage(v interface{}) json.RawMessage {
|
|
||||||
b, _ := json.Marshal(v)
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量上报事件
|
|
||||||
func BatchReport(ctx context.Context, data interface{}) error {
|
|
||||||
apiUrl := config.ApiUrl + "/api/eventTracking/batchReport.json"
|
|
||||||
reqBody, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report json.Marshal fail", log.E(err))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
req, err := http.NewRequest("POST", apiUrl, bytes.NewReader(reqBody))
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report NewRequest fail", log.E(err))
|
|
||||||
return fmt.Errorf("failed to create request: %v", err)
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
curl, _ := http2curl.GetCurlCommand(req)
|
|
||||||
client := &http.Client{
|
|
||||||
Timeout: 5 * time.Second, // 设置超时时间为 5 秒
|
|
||||||
}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report fail", log.Any("curl", curl), log.E(err))
|
|
||||||
return fmt.Errorf("failed to send request: %v", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
log.Error("Event report fail", log.Any("curl", curl), log.Any("http.code", resp.StatusCode))
|
|
||||||
return fmt.Errorf("failed to report event, status code: %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
// 读取返回的 body
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Event report fail", log.Any("curl", curl), log.E(err))
|
|
||||||
return fmt.Errorf("failed to read response body: %v", err)
|
|
||||||
}
|
|
||||||
// 输出响应状态和返回的 body
|
|
||||||
log.Info("Event report Response", log.Any("body", string(body)))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
package dataReport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
"videoweb/pub/common/log"
|
|
||||||
"videoweb/pub/redis"
|
|
||||||
|
|
||||||
"github.com/robfig/cron/v3"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sdkConfigAPIProd = "https://api.dc-server.cc/sdk/getAvailableDomainList"
|
|
||||||
sdkConfigAPIDev = "https://dcapi.dc-dev.cc/sdk/getAvailableDomainList"
|
|
||||||
sdkConfigCacheKey = "report:sdk:domain_config"
|
|
||||||
sdkConfigCacheTTL = 30 * time.Minute
|
|
||||||
sdkConfigFetchInterval = "0 */10 * * * *"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
sdkConfigAPIURL = sdkConfigAPIProd // 默认正式环境,Init时会根据RunMod覆盖
|
|
||||||
sdkConfigCron *cron.Cron
|
|
||||||
sdkConfigOnce sync.Once
|
|
||||||
|
|
||||||
sdkConfigMu sync.RWMutex
|
|
||||||
sdkDomainConfig string
|
|
||||||
sdkConfigUpdatedAt time.Time
|
|
||||||
)
|
|
||||||
|
|
||||||
type sdkConfigResponse struct {
|
|
||||||
Code int `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
Data string `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// StartSDKConfigCron 定时拉取 SDK 域名配置串,服务端只缓存并原样透传。
|
|
||||||
func StartSDKConfigCron() {
|
|
||||||
sdkConfigOnce.Do(func() {
|
|
||||||
if err := RefreshSDKDomainConfig(); err != nil {
|
|
||||||
log.Error("RefreshSDKDomainConfig first run fail", log.E(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
sdkConfigCron = cron.New(cron.WithSeconds())
|
|
||||||
if _, err := sdkConfigCron.AddFunc(sdkConfigFetchInterval, func() {
|
|
||||||
if err := RefreshSDKDomainConfig(); err != nil {
|
|
||||||
log.Error("RefreshSDKDomainConfig cron fail", log.E(err))
|
|
||||||
}
|
|
||||||
}); err != nil {
|
|
||||||
log.Error("StartSDKConfigCron AddFunc fail", log.E(err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sdkConfigCron.Start()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func StopSDKConfigCron() {
|
|
||||||
if sdkConfigCron == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx := sdkConfigCron.Stop()
|
|
||||||
<-ctx.Done()
|
|
||||||
}
|
|
||||||
|
|
||||||
func RefreshSDKDomainConfig() error {
|
|
||||||
data, err := fetchSDKDomainConfig(sdkConfigAPIURL, &http.Client{Timeout: 5 * time.Second})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
setSDKDomainConfig(data)
|
|
||||||
if redis.Client() == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return redis.Set(sdkConfigCacheKey, data, sdkConfigCacheTTL)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSDKDomainConfig() string {
|
|
||||||
if redis.Client() != nil {
|
|
||||||
data, err := redis.Get(sdkConfigCacheKey)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("GetSDKDomainConfig redis get fail", log.E(err))
|
|
||||||
} else if data != nil && *data != "" {
|
|
||||||
setSDKDomainConfig(*data)
|
|
||||||
return *data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sdkConfigMu.RLock()
|
|
||||||
defer sdkConfigMu.RUnlock()
|
|
||||||
return sdkDomainConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func setSDKDomainConfig(data string) {
|
|
||||||
sdkConfigMu.Lock()
|
|
||||||
defer sdkConfigMu.Unlock()
|
|
||||||
sdkDomainConfig = data
|
|
||||||
sdkConfigUpdatedAt = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchSDKDomainConfig(apiURL string, client *http.Client) (string, error) {
|
|
||||||
req, err := http.NewRequest(http.MethodGet, apiURL, nil)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return "", fmt.Errorf("sdk config http status: %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
var result sdkConfigResponse
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if result.Code != 0 {
|
|
||||||
return "", fmt.Errorf("sdk config code: %d, msg: %s", result.Code, result.Msg)
|
|
||||||
}
|
|
||||||
if strings.TrimSpace(result.Data) == "" {
|
|
||||||
return "", fmt.Errorf("sdk config data is empty")
|
|
||||||
}
|
|
||||||
return result.Data, nil
|
|
||||||
}
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
package dataReport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Response struct {
|
|
||||||
Code int `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
ApiUrl string `json:"apiUrl"`
|
|
||||||
RunMod string `json:"runMod"` // 运行模式: dev/test/prod/release
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
EventTypeAdClick = "ad_click"
|
|
||||||
EventTypeUserLogin = "user_login"
|
|
||||||
EventTypeUserRegister = "user_register"
|
|
||||||
EventTypeOrderCreated = "order_created"
|
|
||||||
EventTypeOrderPaid = "order_paid"
|
|
||||||
EventTypeCoinConsume = "coin_consume"
|
|
||||||
EventTypeVideoPurchase = "video_purchase"
|
|
||||||
EventTypeVideoLike = "video_like"
|
|
||||||
EventTypeVideoCollect = "video_collect"
|
|
||||||
EventTypeVideoComment = "video_comment"
|
|
||||||
EventTypeVideoStatusChange = "video_status_change" // 视频状态变更
|
|
||||||
EventTypeDramaLike = "drama_like"
|
|
||||||
EventTypeDramaCollect = "drama_collect"
|
|
||||||
EventTypeDramaComment = "drama_comment"
|
|
||||||
EventTypeDramaPurchase = "drama_purchase"
|
|
||||||
|
|
||||||
DramaContentTypeShortDrama = "short_drama"
|
|
||||||
DramaUnlockTypeCoin = "coin"
|
|
||||||
DramaUnlockTypeVIP = "vip_subscription"
|
|
||||||
DramaUnlockTypeAd = "ad"
|
|
||||||
DramaUnlockTypeOther = "other"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Event 定义事件的接口
|
|
||||||
type Event interface {
|
|
||||||
Generate(ctx context.Context, retryCount int)
|
|
||||||
AsyncReport(ctx context.Context, retryCount int) error // 执行事件上报
|
|
||||||
}
|
|
||||||
|
|
||||||
// 定义公共字段和事件数据结构
|
|
||||||
type CommonField struct {
|
|
||||||
Event string `json:"event"` // 事件类型
|
|
||||||
Channel string `json:"channel"` // 渠道码
|
|
||||||
EventID string `json:"event_id"` // 事件唯一标识符
|
|
||||||
AppID string `json:"app_id"` // 应用ID
|
|
||||||
AppVersion string `json:"app_version"` // 客户端通过 X-SDK-Common 传入的版本,缺失时留空
|
|
||||||
UID string `json:"uid"` // 用户ID
|
|
||||||
SID string `json:"sid"` // 会话ID
|
|
||||||
ClientTS string `json:"client_ts"` // 客户端时间戳
|
|
||||||
Device string `json:"device"` // 设备类型(如:Android, iOS, PC)
|
|
||||||
DeviceID string `json:"device_id"` // 设备ID
|
|
||||||
DeviceFingerprint string `json:"device_fingerprint"` // SDK 设备指纹,SDK 原值为空时也保留字段。
|
|
||||||
FPVersion string `json:"fp_version"` // SDK 指纹算法版本
|
|
||||||
UserAgent string `json:"user_agent"` // 用户代理信息
|
|
||||||
DeviceBrand string `json:"device_brand"` // 设备品牌(如:HUAWEI)
|
|
||||||
DeviceModel string `json:"device_model"` // 设备型号
|
|
||||||
SystemName string `json:"system_name"` // 系统名称
|
|
||||||
SystemVersion string `json:"system_version"` // 系统版本
|
|
||||||
IP string `json:"ip"` // 用户IP地址
|
|
||||||
Payload json.RawMessage `json:"payload"` // 事件数据
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserRegisterEvent 注册事件
|
|
||||||
type UserRegisterEvent struct {
|
|
||||||
Type string `json:"type"` // 注册方式:phone, deviceid, email, username
|
|
||||||
TraceID string `json:"trace_id"` // 唯一标识,落地页点击生成
|
|
||||||
CreateTime json.Number `json:"create_time"` // 注册时间,10位时间戳
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserLoginEvent struct {
|
|
||||||
Type string `json:"type"` // 登录方式
|
|
||||||
}
|
|
||||||
|
|
||||||
// OrderCreatedEvent 订单创建
|
|
||||||
type OrderCreatedEvent struct {
|
|
||||||
OrderID string `json:"order_id"` // 订单号(唯一标识)
|
|
||||||
OrderType string `json:"order_type"` // 订单类型
|
|
||||||
ProductID string `json:"product_id"` // 商品ID
|
|
||||||
ProductName string `json:"product_name"` // 商品名称
|
|
||||||
VIPDurationID string `json:"vip_duration_type"`
|
|
||||||
VIPDurationName string `json:"vip_duration_name"`
|
|
||||||
Amount json.Number `json:"amount"` // 订单金额(分)
|
|
||||||
Currency string `json:"currency"` // 货币类型
|
|
||||||
CoinQuantity json.Number `json:"coin_quantity"` // 金币数量
|
|
||||||
SourcePageKey string `json:"source_page_key"` // 来源页面标识
|
|
||||||
SourcePageName string `json:"source_page_name"` // 来源页面名称
|
|
||||||
CreateTime json.Number `json:"create_time"` // 订单创建时间
|
|
||||||
}
|
|
||||||
|
|
||||||
// OrderPaidEvent 订单支付成功
|
|
||||||
type OrderPaidEvent struct {
|
|
||||||
OrderID string `json:"order_id"` // 订单号(关联创建事件)
|
|
||||||
OrderType string `json:"order_type"` // 订单类型:coin_purchase, vip_subscription
|
|
||||||
ProductID string `json:"product_id"` // 商品ID
|
|
||||||
Amount json.Number `json:"amount"` // 实际支付金额(分)
|
|
||||||
Currency string `json:"currency"` // 货币类型:CNY, USD
|
|
||||||
CoinQuantity json.Number `json:"coin_quantity"` // 金币数量(仅金币订单)
|
|
||||||
VIPExpirationTime json.Number `json:"vip_expiration_time"` // VIP过期时间(10位时间戳)
|
|
||||||
PayType string `json:"pay_type"` // 支付方式:wechat, alipay, bank_card
|
|
||||||
PayChannel string `json:"pay_channel"` // 支付渠道:银行名称
|
|
||||||
TransactionID string `json:"transaction_id"` // 第三方支付交易号
|
|
||||||
CreateTime json.Number `json:"create_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CoinConsumeEvent 金币消耗
|
|
||||||
type CoinConsumeEvent struct {
|
|
||||||
ProductID string `json:"product_id"` // 商品ID
|
|
||||||
ProductName string `json:"product_name"` // 商品名称
|
|
||||||
CoinConsumeAmount json.Number `json:"coin_consume_amount"` // 金币消耗数量
|
|
||||||
CoinBalanceBefore json.Number `json:"coin_balance_before"` // 消耗前金币余额
|
|
||||||
CoinBalanceAfter json.Number `json:"coin_balance_after"` // 消耗后金币余额
|
|
||||||
ConsumeReasonKey string `json:"consume_reason_key"` // 消耗原因
|
|
||||||
ConsumeReasonName string `json:"consume_reason_name"` // 消耗原因名称
|
|
||||||
CreateTime json.Number `json:"create_time"` // 订单创建时间
|
|
||||||
OrderId string `json:"order_id"` // 订单id
|
|
||||||
}
|
|
||||||
|
|
||||||
// VideoPurchaseEvent 视频购买事件
|
|
||||||
type VideoPurchaseEvent struct {
|
|
||||||
MediaId string `json:"media_id"` // 老司机媒体资源ID(老司机接口返回的id字段)
|
|
||||||
VideoID string `json:"video_id"` // 视频ID
|
|
||||||
VideoTitle string `json:"video_title"` // 视频标题
|
|
||||||
VideoTypeID string `json:"video_type_id"` // 视频分类ID
|
|
||||||
VideoTypeName string `json:"video_type_name"` // 视频分类名称
|
|
||||||
VideoContentType string `json:"video_content_type"` // 视频类型: video(长视频)、short_video(短视频)
|
|
||||||
RecommendTraceId string `json:"recommend_trace_id"` // 推荐引擎的trace_id。没有对接搜索推荐引擎的上报空字符串。
|
|
||||||
CoinQuantity json.Number `json:"coin_quantity"` // 金币数量
|
|
||||||
OrderID string `json:"order_id"` // 订单号
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
VideoEventPub struct {
|
|
||||||
MediaId string `json:"media_id"` // 老司机媒体资源ID(老司机接口返回的id字段)
|
|
||||||
VideoID string `json:"video_id"` // 视频ID
|
|
||||||
VideoTitle string `json:"video_title"` // 视频标题
|
|
||||||
VideoTypeID string `json:"video_type_id"` // 视频分类ID
|
|
||||||
VideoTypeName string `json:"video_type_name"` // 视频分类名称
|
|
||||||
VideoContentType string `json:"video_content_type"` // 视频类型: video(长视频)、short_video(短视频)
|
|
||||||
RecommendTraceId string `json:"recommend_trace_id"` // 推荐引擎的trace_id。没有对接搜索推荐引擎的上报空字符串。
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoLikeEvent struct {
|
|
||||||
VideoEventPub
|
|
||||||
Flag json.Number `json:"flag"` // 点赞状态:1(点赞), 2(取消点赞)
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoCollectEvent struct {
|
|
||||||
VideoEventPub
|
|
||||||
Flag json.Number `json:"flag"` // 收藏状态:1(收藏), 2(取消收藏)
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoCommentEvent struct {
|
|
||||||
VideoEventPub
|
|
||||||
CommentContent string `json:"comment_content"` // 评论内容
|
|
||||||
}
|
|
||||||
|
|
||||||
// VideoStatusChangeEvent 视频状态变更事件
|
|
||||||
VideoStatusChangeEvent struct {
|
|
||||||
MediaId string `json:"media_id"` // 老司机媒体资源ID
|
|
||||||
VideoID string `json:"video_id"` // 视频ID
|
|
||||||
VideoTitle string `json:"video_title"` // 视频标题
|
|
||||||
VideoTypeID string `json:"video_type_id"` // 视频分类ID
|
|
||||||
VideoTypeName string `json:"video_type_name"` // 视频分类名称
|
|
||||||
Flag json.Number `json:"flag"` // 状态标识
|
|
||||||
}
|
|
||||||
|
|
||||||
DramaEventPub struct {
|
|
||||||
DramaID string `json:"drama_id"` // 剧集章节ID(PlayletChapter.Id)
|
|
||||||
DramaTitle string `json:"drama_title"` // 剧集名称
|
|
||||||
Episode json.Number `json:"episode"` // 第几集,默认1
|
|
||||||
VideoID string `json:"video_id"` // 媒资中心章节ID(PlayletChapter.MediaContentId)
|
|
||||||
TotalEpisode json.Number `json:"total_episode"` // 已上线总集数
|
|
||||||
DramaTypeID string `json:"drama_type_id"` // 剧集分类ID
|
|
||||||
DramaTypeName string `json:"drama_type_name"` // 剧集分类名称
|
|
||||||
DramaContentType string `json:"drama_content_type"` // short_drama
|
|
||||||
DramaTagKey string `json:"drama_tag_key"` // 标签KEY,逗号分隔
|
|
||||||
DramaTagName string `json:"drama_tag_name"` // 标签名称,逗号分隔
|
|
||||||
DramaDuration json.Number `json:"drama_duration"` // 剧集时长(秒)
|
|
||||||
}
|
|
||||||
|
|
||||||
DramaLikeEvent struct {
|
|
||||||
DramaEventPub
|
|
||||||
Flag json.Number `json:"flag"` // 点赞状态:1(点赞), 2(取消点赞)
|
|
||||||
}
|
|
||||||
|
|
||||||
DramaCollectEvent struct {
|
|
||||||
DramaEventPub
|
|
||||||
Flag json.Number `json:"flag"` // 收藏状态:1(收藏), 2(取消收藏)
|
|
||||||
}
|
|
||||||
|
|
||||||
DramaCommentEvent struct {
|
|
||||||
DramaEventPub
|
|
||||||
CommentContent string `json:"comment_content"` // 评论内容
|
|
||||||
}
|
|
||||||
|
|
||||||
DramaPurchaseEvent struct {
|
|
||||||
DramaEventPub
|
|
||||||
CoinQuantity json.Number `json:"coin_quantity"` // 金币数量
|
|
||||||
OrderID string `json:"order_id"` // 订单号,与 coin_consume 保持一致
|
|
||||||
UnlockType string `json:"unlock_type"` // coin / vip_subscription / ad / other
|
|
||||||
AdID string `json:"ad_id"` // 广告解锁时的广告ID
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type AdClickEvent struct {
|
|
||||||
CommonField
|
|
||||||
PageKey string `json:"page_key"` // 页面标识
|
|
||||||
PageName string `json:"page_name"` // 页面名称
|
|
||||||
AdSlotKey string `json:"ad_slot_key"` // 广告位标识
|
|
||||||
AdSlotName string `json:"ad_slot_name"` // 广告位名称
|
|
||||||
AdID string `json:"ad_id"` // 广告ID
|
|
||||||
CreativeID string `json:"creative_id"` // 素材ID(可选)
|
|
||||||
AdType string `json:"ad_type"` // 广告类型
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package eventmod
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"videoweb/pub/mongos"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
)
|
|
||||||
|
|
||||||
var db *mongos.Collection
|
|
||||||
|
|
||||||
func Init(ctx context.Context) {
|
|
||||||
db = mongos.Shop.Coll(TN.Event)
|
|
||||||
indexes := []mongo.IndexModel{
|
|
||||||
{
|
|
||||||
Keys: bson.D{
|
|
||||||
{Key: FN.Event.Status, Value: 1},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Keys: bson.D{
|
|
||||||
{Key: FN.Event.EventType, Value: 1},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Keys: bson.D{
|
|
||||||
{Key: FN.Event.EventId, Value: 1},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Keys: bson.D{
|
|
||||||
{Key: FN.Event.Status, Value: 1},
|
|
||||||
{Key: FN.Event.RetryCount, Value: 1},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Keys: bson.D{
|
|
||||||
{Key: FN.Event.CreatedAt, Value: -1},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
|
||||||
panic(fmt.Sprintf("(eventmod:Init) Create Event Index failed! err:%+v:", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
package eventmod
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"videoweb/pub/common/log"
|
|
||||||
"videoweb/pub/common/srvdef"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InsertOneEvent 插入一个事件
|
|
||||||
func InsertOneEvent(ctx context.Context, event *Event) *srvdef.SrvErr {
|
|
||||||
if _, err := db.InsertOne(ctx, event); err != nil {
|
|
||||||
log.Warn("eventmod:InsertOneEvent db.InsertOne failed", log.E(err))
|
|
||||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// InsertManyEvent 批量插入事件
|
|
||||||
func InsertManyEvent(ctx context.Context, events *EventList) *srvdef.SrvErr {
|
|
||||||
if _, err := db.InsertMany(ctx, events); err != nil {
|
|
||||||
log.Warn("eventmod:InsertManyEvent db.InsertMany failed", log.E(err))
|
|
||||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DelOneEvent 删除一个事件
|
|
||||||
func DelOneEvent(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
|
||||||
count, err := db.DeleteOne(ctx, filter)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("eventmod:DelOneEvent db.DeleteOne failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
|
||||||
}
|
|
||||||
return count, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DelManyEvent 批量删除事件
|
|
||||||
func DelManyEvent(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
|
||||||
count, err := db.DeleteMany(ctx, filter)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("eventmod:DelManyEvent db.DeleteMany failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
|
||||||
}
|
|
||||||
return count, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindOneEvent 查找一个事件
|
|
||||||
func FindOneEvent(ctx context.Context, filter bson.M, opts ...*options.FindOneOptions) (*Event, *srvdef.SrvErr) {
|
|
||||||
var event Event
|
|
||||||
if err := db.FindOneEx(ctx, &event, filter, opts...); err != nil {
|
|
||||||
if err != mongo.ErrNoDocuments {
|
|
||||||
log.Warn("eventmod:FindOneEvent db.FindOne failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
|
||||||
}
|
|
||||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
|
||||||
}
|
|
||||||
return &event, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindManyEvent 查找多个事件
|
|
||||||
func FindManyEvent(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (EventList, *srvdef.SrvErr) {
|
|
||||||
data := make(EventList, 0)
|
|
||||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
|
||||||
log.Warn("eventmod:FindManyEvent db.Find failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
|
||||||
}
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CountEvent 统计事件数量
|
|
||||||
func CountEvent(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
|
||||||
count, err := db.Count(ctx, filter)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("eventmod:CountEvent db.Count failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
|
||||||
}
|
|
||||||
return count, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateOneEvent 更新一个事件
|
|
||||||
func UpdateOneEvent(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
|
||||||
result, err := db.UpdateOne(ctx, filter, update)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("eventmod:UpdateOneEvent db.UpdateOne failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
|
||||||
}
|
|
||||||
if result.MatchedCount != 1 {
|
|
||||||
log.Warn("eventmod:UpdateOneEvent db.UpdateOne not matched",
|
|
||||||
log.Any("filter", filter))
|
|
||||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateManyEvent 批量更新事件
|
|
||||||
func UpdateManyEvent(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
|
||||||
result, err := db.UpdateMany(ctx, filter, update)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("eventmod:UpdateManyEvent db.UpdateMany failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
|
||||||
}
|
|
||||||
if result.MatchedCount < 1 {
|
|
||||||
log.Warn("eventmod:UpdateManyEvent db.UpdateMany not matched",
|
|
||||||
log.Any("filter", filter))
|
|
||||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpsertOneEvent 插入或更新一个事件
|
|
||||||
func UpsertOneEvent(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
|
||||||
opts := options.Update().SetUpsert(true)
|
|
||||||
if _, err := db.UpdateOne(ctx, filter, update, opts); err != nil {
|
|
||||||
log.Warn("eventmod:UpsertOneEvent db.UpdateOne failed",
|
|
||||||
log.E(err), log.Any("filter", filter))
|
|
||||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package eventmod
|
|
||||||
|
|
||||||
type TagEvent struct {
|
|
||||||
ID string //
|
|
||||||
CreatedAt string // 创建事件
|
|
||||||
RetryCount string // 重试次数
|
|
||||||
Status string //
|
|
||||||
Data string //
|
|
||||||
EventType string //
|
|
||||||
EventId string //
|
|
||||||
UpdatedAt string // 修改时间
|
|
||||||
}
|
|
||||||
|
|
||||||
var FN struct {
|
|
||||||
Event TagEvent
|
|
||||||
}
|
|
||||||
var TN struct {
|
|
||||||
Event string
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
FN.Event.ID = "_id"
|
|
||||||
FN.Event.CreatedAt = "createdAt"
|
|
||||||
FN.Event.RetryCount = "retryCount"
|
|
||||||
FN.Event.Status = "status"
|
|
||||||
FN.Event.Data = "data"
|
|
||||||
FN.Event.EventType = "eventType"
|
|
||||||
FN.Event.EventId = "eventId"
|
|
||||||
FN.Event.UpdatedAt = "updatedAt"
|
|
||||||
TN.Event = "event"
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package eventmod
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EventStatus int
|
|
||||||
|
|
||||||
const (
|
|
||||||
Default EventStatus = 0 // 默认状态,等待上报
|
|
||||||
Success EventStatus = 1 // 成功
|
|
||||||
Failure EventStatus = 2 // 失败
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:generate fox mongo --model
|
|
||||||
//go:generate fox mongo --tag
|
|
||||||
//go:generate fox mongo --update
|
|
||||||
|
|
||||||
// @table:event
|
|
||||||
// @title:事件表
|
|
||||||
type Event struct {
|
|
||||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
|
||||||
EventId string `json:"eventId" bson:"eventId"`
|
|
||||||
EventType string `json:"eventType" bson:"eventType"`
|
|
||||||
Data string `json:"data" bson:"data"`
|
|
||||||
Status EventStatus `json:"status" bson:"status"` //
|
|
||||||
RetryCount int `json:"retryCount" bson:"retryCount"` // 重试次数
|
|
||||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建事件
|
|
||||||
UpdatedAt time.Time `bson:"updatedAt"` // 修改时间
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package eventmod
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EventList []*Event
|
|
||||||
type EventUpdate struct {
|
|
||||||
RetryCount *int `json:"retryCount" bson:"retryCount,omitempty"` // 重试次数
|
|
||||||
Status *EventStatus `json:"status" bson:"status,omitempty"` //
|
|
||||||
Data *string `json:"data" bson:"data,omitempty"` //
|
|
||||||
EventType *string `json:"eventType" bson:"eventType,omitempty"` //
|
|
||||||
EventId *string `json:"eventId" bson:"eventId,omitempty"` //
|
|
||||||
UpdatedAt *time.Time `json:"" bson:"updatedAt,omitempty"` // 修改时间
|
|
||||||
}
|
|
||||||
type EventQuery struct {
|
|
||||||
ID *primitive.ObjectID `json:"" bson:"_id,omitempty"` //
|
|
||||||
RetryCount *int `json:"retryCount" bson:"retryCount,omitempty"` // 重试次数
|
|
||||||
Status *EventStatus `json:"status" bson:"status,omitempty"` //
|
|
||||||
Data *string `json:"data" bson:"data,omitempty"` //
|
|
||||||
EventType *string `json:"eventType" bson:"eventType,omitempty"` //
|
|
||||||
EventId *string `json:"eventId" bson:"eventId,omitempty"` //
|
|
||||||
UpdatedAt *time.Time `json:"" bson:"updatedAt,omitempty"` // 修改时间
|
|
||||||
}
|
|
||||||
|
|
||||||
func (query *EventQuery) GetQueryFilter() bson.M {
|
|
||||||
filter := bson.M{}
|
|
||||||
if query.ID != nil {
|
|
||||||
filter[FN.Event.ID] = *query.ID
|
|
||||||
}
|
|
||||||
if query.RetryCount != nil {
|
|
||||||
filter[FN.Event.RetryCount] = *query.RetryCount
|
|
||||||
}
|
|
||||||
if query.Status != nil {
|
|
||||||
filter[FN.Event.Status] = *query.Status
|
|
||||||
}
|
|
||||||
if query.Data != nil {
|
|
||||||
filter[FN.Event.Data] = bson.M{"$regex": primitive.Regex{Pattern: *query.Data, Options: "i"}}
|
|
||||||
}
|
|
||||||
if query.EventType != nil {
|
|
||||||
filter[FN.Event.EventType] = bson.M{"$regex": primitive.Regex{Pattern: *query.EventType, Options: "i"}}
|
|
||||||
}
|
|
||||||
if query.EventId != nil {
|
|
||||||
filter[FN.Event.EventId] = bson.M{"$regex": primitive.Regex{Pattern: *query.EventId, Options: "i"}}
|
|
||||||
}
|
|
||||||
if query.UpdatedAt != nil {
|
|
||||||
filter[FN.Event.UpdatedAt] = *query.UpdatedAt
|
|
||||||
}
|
|
||||||
return filter
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"videoweb/pub/models/contactusmod"
|
"videoweb/pub/models/contactusmod"
|
||||||
"videoweb/pub/models/detailnavmod"
|
"videoweb/pub/models/detailnavmod"
|
||||||
"videoweb/pub/models/esmod"
|
"videoweb/pub/models/esmod"
|
||||||
"videoweb/pub/models/eventmod"
|
|
||||||
"videoweb/pub/models/feedbackmod"
|
"videoweb/pub/models/feedbackmod"
|
||||||
"videoweb/pub/models/homebannermod"
|
"videoweb/pub/models/homebannermod"
|
||||||
"videoweb/pub/models/homeconfigmod"
|
"videoweb/pub/models/homeconfigmod"
|
||||||
@@ -77,7 +76,6 @@ func Init() {
|
|||||||
ipdailystatmod.Init(ctx)
|
ipdailystatmod.Init(ctx)
|
||||||
esmod.Init(ctx)
|
esmod.Init(ctx)
|
||||||
detailnavmod.Init(ctx)
|
detailnavmod.Init(ctx)
|
||||||
eventmod.Init(ctx)
|
|
||||||
translationcategorymod.Init(ctx)
|
translationcategorymod.Init(ctx)
|
||||||
translationmod.Init(ctx)
|
translationmod.Init(ctx)
|
||||||
playletthememod.Init(ctx)
|
playletthememod.Init(ctx)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package pubdef
|
package pubdef
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
PageNum int64 `form:"pageNum" json:"pageNum,omitempty"`
|
PageNum int64 `form:"pageNum" json:"pageNum,omitempty"`
|
||||||
PageSize int64 `form:"pageSize" json:"pageSize,omitempty"`
|
PageSize int64 `form:"pageSize" json:"pageSize,omitempty"`
|
||||||
@@ -25,11 +23,6 @@ const (
|
|||||||
seoPushEnabled = false
|
seoPushEnabled = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackerAppId 数据上报 SDK / 服务端埋点共用的应用 ID
|
|
||||||
func TrackerAppId() string {
|
|
||||||
return fmt.Sprintf("JHA-%d", AppId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enabled 业务开关是否打开(不含环境判断)。
|
// Enabled 业务开关是否打开(不含环境判断)。
|
||||||
func Enabled() bool {
|
func Enabled() bool {
|
||||||
return seoPushEnabled
|
return seoPushEnabled
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"videoweb/pub/models/videoinformationmod"
|
"videoweb/pub/models/videoinformationmod"
|
||||||
@@ -425,6 +426,33 @@ type AdvitiseInfo struct {
|
|||||||
Images string `json:"images" bson:"images"` // 视频banner
|
Images string `json:"images" bson:"images"` // 视频banner
|
||||||
Link string `json:"link" bson:"link"` // 链接
|
Link string `json:"link" bson:"link"` // 链接
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON 兼容远端 id 返回数字或字符串两种格式,统一解析为字符串,避免大整数(雪花ID)在 JS 端丢精度
|
||||||
|
func (a *AdvitiseInfo) UnmarshalJSON(data []byte) error {
|
||||||
|
type alias AdvitiseInfo
|
||||||
|
aux := &struct {
|
||||||
|
Id json.RawMessage `json:"id"`
|
||||||
|
*alias
|
||||||
|
}{alias: (*alias)(a)}
|
||||||
|
if err := json.Unmarshal(data, aux); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
raw := strings.TrimSpace(string(aux.Id))
|
||||||
|
switch {
|
||||||
|
case raw == "" || raw == "null":
|
||||||
|
a.Id = ""
|
||||||
|
case strings.HasPrefix(raw, `"`):
|
||||||
|
var s string
|
||||||
|
if err := json.Unmarshal([]byte(raw), &s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a.Id = s
|
||||||
|
default:
|
||||||
|
a.Id = raw
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type AdvitiseData struct {
|
type AdvitiseData struct {
|
||||||
DialogList []AdvitiseInfo `json:"dialogList" bson:"dialogList"` // 弹窗广告
|
DialogList []AdvitiseInfo `json:"dialogList" bson:"dialogList"` // 弹窗广告
|
||||||
HomeList []AdvitiseInfo `json:"homeList" bson:"homeList"` // 首页列表
|
HomeList []AdvitiseInfo `json:"homeList" bson:"homeList"` // 首页列表
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func AccLogin(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
accInfo, err := srv_mwacc.AccLogin(c, req.Acc, req.Pwd, req.Code)
|
accInfo, err := srv_mwacc.AccLogin(c, req.Acc, req.Pwd)
|
||||||
if err != nil || accInfo == nil {
|
if err != nil || accInfo == nil {
|
||||||
common.ServerJSON(c, err.Code, err.Msg)
|
common.ServerJSON(c, err.Code, err.Msg)
|
||||||
return
|
return
|
||||||
|
|||||||
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
—Џ€И’љБCЏ„
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
redis:
|
|
||||||
addr: 172.104.181.99:16789
|
|
||||||
db: 2
|
|
||||||
passwd: "B6vJHlYiTseLj77z"
|
|
||||||
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"
|
|
||||||
es:
|
|
||||||
addr: "http://172.104.181.99:9200"
|
|
||||||
user: "elastic"
|
|
||||||
pass: "admin123456"
|
|
||||||
jwtKey: "2311b15a4da1c80dc541b99abb622233"
|
|
||||||
tgToken: ""
|
|
||||||
runMod: "dev"
|
|
||||||
tsAuthKey: "fT5xSg4hltHpzVy6aV9rVECDJ1J1pN"
|
|
||||||
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"
|
|
||||||
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"
|
|
||||||
apiUrl: "https://zhlsaj.zrr4ij4.site"
|
|
||||||
imageYuan: "https://d1kh52pvweq1c0.cloudfront.net"
|
|
||||||
keyHex: "525202f9149e061d"
|
|
||||||
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"
|
|
||||||
|
|
||||||
newPayCenter:
|
|
||||||
appName: ""
|
|
||||||
callbackUrl: ""
|
|
||||||
apiUrl: ""
|
|
||||||
mercID: ""
|
|
||||||
mercSecret: ""
|
|
||||||
dataCenterBackflow:
|
|
||||||
key: "ld_XLWM9pojLnf_OZFQ1ISac4cELop-WnJH_CcjS5D_ROY"
|
|
||||||
selfSourceBaseUrl: "https://172.104.181.99:25333/api/web/m3u8"
|
|
||||||
+9
-26
@@ -1,28 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
FILE_NAME="web_mdcom_web"
|
|
||||||
REMOTE_FILE_PATH="/home/server2/web_mdcom/web/"
|
|
||||||
TAG_NAME="web_mdcom_web.tar.gz"
|
|
||||||
|
|
||||||
set -e
|
|
||||||
set -o
|
|
||||||
function send_msg() {
|
|
||||||
msg="@jscdsndj @xiuyuan_Lee @steven0yu %0A服务:SERVER2 站点-91spz.com管理服务(WEB)%0A更新内容:$content%0A创建时间: $(date +%F_%X)%0A操作人:$(git config user.name)"
|
|
||||||
curl -X POST "https://api.telegram.org/bot6357085965:AAEmXfjZnZwnDTicL7Wjbd7cXvYv_G98w8A/sendMessage" -d "chat_id=$1&text=$msg" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
read -p "输入yes, 开始上传: " word
|
|
||||||
if [[ ! "yes" =~ $word ]]; then
|
|
||||||
echo "终止"
|
|
||||||
else
|
|
||||||
read -e -p "本次更新内容(输入q退出编辑): " -r content
|
|
||||||
echo "开始"
|
echo "开始"
|
||||||
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
|
rm -rf ./web_hgc_web ./web_hgc_web.tar.gz
|
||||||
GOOS=linux GOARCH=amd64 go build -o $FILE_NAME
|
GOOS=linux GOARCH=amd64 go build -o web_hgc_web
|
||||||
md5sum $FILE_NAME | cut -d ' ' -f1 >yinsemd5.txt
|
tar zvcf web_hgc_web.tar.gz web_hgc_web
|
||||||
tar zvcf $TAG_NAME ./$FILE_NAME yinsemd5.txt
|
|
||||||
md5sum $TAG_NAME | cut -d ' ' -f1 >yinsemd5.txt
|
|
||||||
scp -i ~/.ssh/id_rsa -P 22889 ./yinsemd5.txt server2@116.212.120.2:$REMOTE_FILE_PATH
|
scp web_hgc_web.tar.gz root@172.104.166.87:/data/uzip
|
||||||
scp -i ~/.ssh/id_rsa -P 22889 ./$TAG_NAME server2@116.212.120.2:$REMOTE_FILE_PATH
|
ssh root@172.104.166.87 "/server/web_hgc/web/up_app.sh"
|
||||||
send_msg -4791758991 #服务器小组
|
|
||||||
fi
|
rm -rf ./web_hgc_web ./web_hgc_web.tar.gz
|
||||||
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
sudo make test
|
|
||||||
|
|
||||||
scp -P 22889 web_91av_web.tar.gz root@172.104.181.99:/server/web_91av/web/
|
|
||||||
ssh root@172.104.181.99 -p 22889 "cd /server/web_91av/web/ && /bin/tar -xf /server/web_91av/web/web_91av_web.tar.gz && /usr/bin/supervisorctl restart web_91av_web"
|
|
||||||
if [ $? -eq 0 ];then
|
|
||||||
echo -e "\033[32m 91spz.com web更新成功 \033[0m"
|
|
||||||
else
|
|
||||||
echo -e "\033[31m 91spz.com web更新失败 \033[0m"
|
|
||||||
fi
|
|
||||||
rm -f web_91av_web.tar.gz
|
|
||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"videoweb/pub/common/laosiji"
|
"videoweb/pub/common/laosiji"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvversion"
|
"videoweb/pub/common/srvversion"
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/esmanager"
|
"videoweb/pub/esmanager"
|
||||||
"videoweb/pub/models"
|
"videoweb/pub/models"
|
||||||
"videoweb/pub/mongos"
|
"videoweb/pub/mongos"
|
||||||
@@ -80,10 +79,6 @@ func Run(args []string) {
|
|||||||
mongos.StartLid()
|
mongos.StartLid()
|
||||||
initData()
|
initData()
|
||||||
initSeoPush()
|
initSeoPush()
|
||||||
dataReport.Init(dataReport.Config{
|
|
||||||
ApiUrl: webg.Conf.DataReport.Url,
|
|
||||||
RunMod: webg.Conf.RunMod,
|
|
||||||
})
|
|
||||||
|
|
||||||
initHttpServer()
|
initHttpServer()
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,9 @@ import (
|
|||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/common/utils"
|
"videoweb/pub/common/utils"
|
||||||
"videoweb/pub/google"
|
|
||||||
"videoweb/pub/models/mwacc"
|
"videoweb/pub/models/mwacc"
|
||||||
"videoweb/web/webg"
|
"videoweb/web/webg"
|
||||||
|
|
||||||
"github.com/skip2/go-qrcode"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -78,8 +76,8 @@ func isCustomerServiceRole(ctx context.Context, acc *mwacc.MwAcc) bool {
|
|||||||
return strings.Contains(roleName, "客服")
|
return strings.Contains(roleName, "客服")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 账号登录
|
// 账号登录(已取消谷歌验证,密码正确即登录)
|
||||||
func AccLogin(ctx context.Context, acc string, pwd string, code string) (*mwacc.MwAcc, *srvdef.SrvErr) {
|
func AccLogin(ctx context.Context, acc string, pwd string) (*mwacc.MwAcc, *srvdef.SrvErr) {
|
||||||
var data *mwacc.MwAcc
|
var data *mwacc.MwAcc
|
||||||
res, dataErr := mwacc.FindOneAccByFilter(ctx, bson.M{
|
res, dataErr := mwacc.FindOneAccByFilter(ctx, bson.M{
|
||||||
mwacc.FN.MwAcc.Acc: acc,
|
mwacc.FN.MwAcc.Acc: acc,
|
||||||
@@ -99,43 +97,18 @@ func AccLogin(ctx context.Context, acc string, pwd string, code string) (*mwacc.
|
|||||||
return data, srvdef.New(srvdef.AccountErrPasswordError, srvdef.AccountErrPasswordError.Msg(), "")
|
return data, srvdef.New(srvdef.AccountErrPasswordError, srvdef.AccountErrPasswordError.Msg(), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !res.IsBase32 {
|
|
||||||
// 谷歌绑定二维码
|
|
||||||
googleUrl := google.NewGoogleAuth().GetQrcode(acc, res.Base32)
|
|
||||||
qrCodePNG, _ := qrcode.Encode(googleUrl, qrcode.Medium, 256)
|
|
||||||
|
|
||||||
bq := &mwacc.MwAcc{}
|
|
||||||
bq.Qurl = qrCodePNG
|
|
||||||
data = bq
|
|
||||||
} else {
|
|
||||||
// hf屏蔽
|
|
||||||
if webg.Conf.RunMod == "prod" && (res.RoleId != 46761 && res.RoleId != 29601) {
|
|
||||||
if code == "" {
|
|
||||||
return data, srvdef.New(srvdef.ErrCaptcha, srvdef.ErrCaptcha.Msg(), "")
|
|
||||||
}
|
|
||||||
result, Verr := google.NewGoogleAuth().VerifyCode(res.Base32, code)
|
|
||||||
if Verr != nil || !result {
|
|
||||||
return data, srvdef.New(srvdef.ErrCaptchaInvalid, srvdef.ErrCaptchaInvalid.Msg(), "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 通过验证,再次验证密码是否正确
|
|
||||||
pwd := crypt.StrToMd5(pwd)
|
|
||||||
if res.Pwd != pwd {
|
|
||||||
return data, srvdef.New(srvdef.AccountErrPasswordError, srvdef.AccountErrPasswordError.Msg(), "")
|
|
||||||
}
|
|
||||||
getToken, err := generateToken(res.Id)
|
getToken, err := generateToken(res.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return data, srvdef.New(srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg(), "")
|
return data, srvdef.New(srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg(), "")
|
||||||
}
|
}
|
||||||
|
// 更新最近登录时间
|
||||||
_ = mwacc.UpOneAccByFilter(ctx, bson.M{
|
_ = mwacc.UpOneAccByFilter(ctx, bson.M{
|
||||||
mwacc.FN.MwAcc.Id: res.Id,
|
mwacc.FN.MwAcc.Id: res.Id,
|
||||||
}, bson.M{
|
}, bson.M{
|
||||||
mwacc.FN.MwAcc.LastTime: time.Now(),
|
mwacc.FN.MwAcc.LastTime: time.Now(),
|
||||||
})
|
})
|
||||||
// 更新最近登录时间
|
|
||||||
data = res
|
data = res
|
||||||
data.Token = getToken
|
data.Token = getToken
|
||||||
}
|
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"videoweb/app/service/reportser"
|
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/response"
|
"videoweb/pub/common/response"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
@@ -520,9 +519,6 @@ func SetPlayletStatus(ctx context.Context, req *proto.PlayletStatusSetReq) *srvd
|
|||||||
log.Error("短剧状态同步ES失败", log.Any("短剧ID", syncIds), log.Any("状态", syncStatus), log.E(err))
|
log.Error("短剧状态同步ES失败", log.Any("短剧ID", syncIds), log.Any("状态", syncStatus), log.E(err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if flag := reportser.PlayletStatusFlag(req.Status); flag != 0 {
|
|
||||||
reportPlayletStatusEvents(ctx, ids, flag)
|
|
||||||
}
|
|
||||||
if req.Status == playletmod.StatusUp {
|
if req.Status == playletmod.StatusUp {
|
||||||
submitPlayletAiComments(ids...)
|
submitPlayletAiComments(ids...)
|
||||||
}
|
}
|
||||||
@@ -541,24 +537,6 @@ func submitPlayletAiComments(ids ...int64) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportPlayletStatusEvents(ctx context.Context, ids []int64, flag int64) {
|
|
||||||
if len(ids) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
list, err := playletmod.FindManyPlaylet(ctx, bson.M{playletmod.FN.Playlet.Id: bson.M{"$in": ids}}, options.Find().SetProjection(bson.D{
|
|
||||||
{Key: playletmod.FN.Playlet.Id, Value: 1},
|
|
||||||
{Key: playletmod.FN.Playlet.Title, Value: 1},
|
|
||||||
{Key: playletmod.FN.Playlet.MediaCenterId, Value: 1},
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
log.Error("短剧状态变更上报查询失败", log.Any("短剧ID", ids), log.E(err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, item := range list {
|
|
||||||
reportser.ReportPlayletStatusChange(item, flag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPlayletRecommend 单/批量设置短剧是否推荐
|
// SetPlayletRecommend 单/批量设置短剧是否推荐
|
||||||
func SetPlayletRecommend(ctx context.Context, req *proto.PlayletRecommendSetReq) *srvdef.SrvErr {
|
func SetPlayletRecommend(ctx context.Context, req *proto.PlayletRecommendSetReq) *srvdef.SrvErr {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
@@ -1641,6 +1619,10 @@ func applyPlayletDescription(doc *playletmod.Playlet) {
|
|||||||
}
|
}
|
||||||
doc.Description = description
|
doc.Description = description
|
||||||
doc.SeoInfo.Description = description
|
doc.SeoInfo.Description = description
|
||||||
|
// SEO 标题跟随 Playlet.Title 同步。
|
||||||
|
if title := strings.TrimSpace(doc.Title); title != "" {
|
||||||
|
doc.SeoInfo.Title = title
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyPlayletDescriptionOnUpdate(exist *playletmod.Playlet, req *proto.PlayletUpdateReq, setDoc bson.M) {
|
func applyPlayletDescriptionOnUpdate(exist *playletmod.Playlet, req *proto.PlayletUpdateReq, setDoc bson.M) {
|
||||||
@@ -1654,6 +1636,10 @@ func applyPlayletDescriptionOnUpdate(exist *playletmod.Playlet, req *proto.Playl
|
|||||||
if playName == "" {
|
if playName == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
title := strings.TrimSpace(exist.Title)
|
||||||
|
if req.Title != nil {
|
||||||
|
title = strings.TrimSpace(*req.Title)
|
||||||
|
}
|
||||||
desc := exist.Desc
|
desc := exist.Desc
|
||||||
if req.Desc != nil {
|
if req.Desc != nil {
|
||||||
desc = strings.TrimSpace(*req.Desc)
|
desc = strings.TrimSpace(*req.Desc)
|
||||||
@@ -1676,7 +1662,11 @@ func applyPlayletDescriptionOnUpdate(exist *playletmod.Playlet, req *proto.Playl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
seo = normalizeSeoValue(seo)
|
seo = normalizeSeoValue(seo)
|
||||||
|
// 每次 description 更新 → SEO 描述、SEO 标题同步。
|
||||||
seo.Description = description
|
seo.Description = description
|
||||||
|
if title != "" {
|
||||||
|
seo.Title = title
|
||||||
|
}
|
||||||
setDoc["seoInfo"] = seo
|
setDoc["seoInfo"] = seo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,11 @@ package srv_recharge
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/models/cointransmod"
|
"videoweb/pub/models/cointransmod"
|
||||||
"videoweb/pub/models/eventmod"
|
|
||||||
"videoweb/pub/models/rechargepackagemod"
|
"videoweb/pub/models/rechargepackagemod"
|
||||||
"videoweb/pub/models/usermod"
|
"videoweb/pub/models/usermod"
|
||||||
"videoweb/pub/models/vipordermod"
|
"videoweb/pub/models/vipordermod"
|
||||||
@@ -73,19 +67,18 @@ func OnPayCenterCallback(ctx *gin.Context, param *BillCallbackParam) *srvdef.Srv
|
|||||||
|
|
||||||
orderSnap := *order
|
orderSnap := *order
|
||||||
realAmount := param.RealAmount
|
realAmount := param.RealAmount
|
||||||
oid := param.Oid
|
|
||||||
|
|
||||||
switch order.OrderType {
|
switch order.OrderType {
|
||||||
case vipordermod.OrderTypeCoin:
|
case vipordermod.OrderTypeCoin:
|
||||||
go handleCoinOrderSuccess(orderSnap, oid, realAmount)
|
go handleCoinOrderSuccess(orderSnap, realAmount)
|
||||||
default:
|
default:
|
||||||
go handleVipOrderSuccess(orderSnap, oid, realAmount)
|
go handleVipOrderSuccess(orderSnap, realAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleVipOrderSuccess(order vipordermod.VipOrder, oid string, realAmount int64) {
|
func handleVipOrderSuccess(order vipordermod.VipOrder, realAmount int64) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
pkg, err := findVipPackage(ctx, order.CardId)
|
pkg, err := findVipPackage(ctx, order.CardId)
|
||||||
@@ -118,11 +111,9 @@ func handleVipOrderSuccess(order vipordermod.VipOrder, oid string, realAmount in
|
|||||||
Remark: payment.CoinTransRemark(cointransmod.TranTypeVipGiftCoin, pkg.Name),
|
Remark: payment.CoinTransRemark(cointransmod.TranTypeVipGiftCoin, pkg.Name),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
reportVipOrderPaid(ctx, &order, oid, realAmount, expire)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCoinOrderSuccess(order vipordermod.VipOrder, oid string, realAmount int64) {
|
func handleCoinOrderSuccess(order vipordermod.VipOrder, realAmount int64) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if err := addUserCoins(ctx, order.UserId, order.Coin); err != nil {
|
if err := addUserCoins(ctx, order.UserId, order.Coin); err != nil {
|
||||||
@@ -137,8 +128,6 @@ func handleCoinOrderSuccess(order vipordermod.VipOrder, oid string, realAmount i
|
|||||||
log.Info("handleCoinOrderSuccess done", log.Any("userId", order.UserId), log.Any("coin", order.Coin))
|
log.Info("handleCoinOrderSuccess done", log.Any("userId", order.UserId), log.Any("coin", order.Coin))
|
||||||
|
|
||||||
writeCoinOrderTrans(ctx, order)
|
writeCoinOrderTrans(ctx, order)
|
||||||
|
|
||||||
reportCoinOrderPaid(ctx, &order, oid, realAmount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeCoinOrderTrans(ctx context.Context, order vipordermod.VipOrder) {
|
func writeCoinOrderTrans(ctx context.Context, order vipordermod.VipOrder) {
|
||||||
@@ -229,79 +218,3 @@ func addUserCoins(ctx context.Context, userId int64, coin int64) *srvdef.SrvErr
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportVipOrderPaid(ctx context.Context, order *vipordermod.VipOrder, oid string, realAmount int64, vipExpire time.Time) {
|
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: order.UserId})
|
|
||||||
districtCode, ip := "", order.IPAddr
|
|
||||||
if user != nil {
|
|
||||||
districtCode = user.DistrictCode
|
|
||||||
}
|
|
||||||
|
|
||||||
ua := order.Client.UA(order.SysType)
|
|
||||||
eventId := newEventId(pubdef.TrackerAppId(), order.UserId, order.TradeNo, order.CreatedAt.Unix())
|
|
||||||
cf := dataReport.NewCommonField(eventId, dataReport.EventTypeOrderPaid, districtCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
|
|
||||||
var expireTS int64
|
|
||||||
if !vipExpire.IsZero() {
|
|
||||||
expireTS = vipExpire.Unix()
|
|
||||||
}
|
|
||||||
cf.Payload = dataReport.JsonRawMessage(&dataReport.OrderPaidEvent{
|
|
||||||
OrderID: order.TradeNo,
|
|
||||||
OrderType: "vip_subscription",
|
|
||||||
ProductID: strconv.FormatInt(order.CardId, 10),
|
|
||||||
Amount: dataReport.JsonNumber(realAmount),
|
|
||||||
Currency: "CNY",
|
|
||||||
VIPExpirationTime: dataReport.JsonNumber(expireTS),
|
|
||||||
PayType: order.PayMode,
|
|
||||||
PayChannel: order.PayChannel,
|
|
||||||
TransactionID: oid,
|
|
||||||
CreateTime: dataReport.JsonNumber(order.CreatedAt.Unix()),
|
|
||||||
})
|
|
||||||
insertEvent(ctx, cf, order.TradeNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func reportCoinOrderPaid(ctx context.Context, order *vipordermod.VipOrder, oid string, realAmount int64) {
|
|
||||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: order.UserId})
|
|
||||||
districtCode, ip := "", order.IPAddr
|
|
||||||
if user != nil {
|
|
||||||
districtCode = user.DistrictCode
|
|
||||||
}
|
|
||||||
|
|
||||||
ua := order.Client.UA(order.SysType)
|
|
||||||
eventId := newEventId(pubdef.TrackerAppId(), order.UserId, order.TradeNo, order.CreatedAt.Unix())
|
|
||||||
cf := dataReport.NewCommonField(eventId, dataReport.EventTypeOrderPaid, districtCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
|
||||||
|
|
||||||
cf.Payload = dataReport.JsonRawMessage(&dataReport.OrderPaidEvent{
|
|
||||||
OrderID: order.TradeNo,
|
|
||||||
OrderType: "coin_purchase",
|
|
||||||
ProductID: strconv.FormatInt(order.CoinCfgId, 10),
|
|
||||||
Amount: dataReport.JsonNumber(realAmount),
|
|
||||||
Currency: "CNY",
|
|
||||||
CoinQuantity: dataReport.JsonNumber(order.Coin),
|
|
||||||
PayType: order.PayMode,
|
|
||||||
PayChannel: order.PayChannel,
|
|
||||||
TransactionID: oid,
|
|
||||||
CreateTime: dataReport.JsonNumber(order.CreatedAt.Unix()),
|
|
||||||
})
|
|
||||||
insertEvent(ctx, cf, order.TradeNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func insertEvent(ctx context.Context, cf dataReport.CommonField, tradeNo string) {
|
|
||||||
data, _ := json.Marshal(cf)
|
|
||||||
if err := eventmod.InsertOneEvent(ctx, &eventmod.Event{
|
|
||||||
EventId: cf.EventID,
|
|
||||||
EventType: cf.Event,
|
|
||||||
Data: string(data),
|
|
||||||
Status: eventmod.Default,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error("insertEvent failed", log.Any("tradeNo", tradeNo), log.E(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
|
|
||||||
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
|
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(input))
|
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
package srv_report
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
"videoweb/pub/common/log"
|
|
||||||
"videoweb/pub/common/useragent"
|
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/models/eventmod"
|
|
||||||
"videoweb/pub/models/videocategorymod"
|
|
||||||
"videoweb/pub/models/videoinformationmod"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReportVideoStatusChangeEvent 视频状态变更事件上报
|
|
||||||
func ReportVideoStatusChangeEvent(media *videoinformationmod.VideoInformation, flag, userId int64, ua useragent.UA) {
|
|
||||||
if media == nil || media.Id == 0 || flag == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var lsjId string
|
|
||||||
|
|
||||||
var videoTypeID = "default"
|
|
||||||
var videoTypeName = "默认分类"
|
|
||||||
if len(media.CategoryIds) > 0 {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
|
|
||||||
defer cancel()
|
|
||||||
category, _ := videocategorymod.FindOneVideoCategory(ctx, bson.M{
|
|
||||||
videocategorymod.FN.VideoCategory.Id: media.CategoryIds[0],
|
|
||||||
})
|
|
||||||
if category != nil {
|
|
||||||
videoTypeID = fmt.Sprintf("%v", category.Id)
|
|
||||||
videoTypeName = category.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event := dataReport.NewCommonField("", dataReport.EventTypeVideoStatusChange, "", ua, strconv.FormatInt(userId, 10), "")
|
|
||||||
|
|
||||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoStatusChangeEvent{
|
|
||||||
MediaId: lsjId,
|
|
||||||
VideoID: fmt.Sprintf("%v", media.Id),
|
|
||||||
VideoTitle: media.Title,
|
|
||||||
VideoTypeID: videoTypeID,
|
|
||||||
VideoTypeName: videoTypeName,
|
|
||||||
Flag: dataReport.JsonNumber(flag),
|
|
||||||
})
|
|
||||||
b, _ := json.Marshal(event)
|
|
||||||
if err := eventmod.InsertOneEvent(context.Background(), &eventmod.Event{
|
|
||||||
EventId: event.EventID,
|
|
||||||
EventType: event.Event,
|
|
||||||
Data: string(b),
|
|
||||||
Status: eventmod.Default,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error("ReportVideoStatusChangeEvent fail", log.Any("mediaId", media.Id), log.E(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// VideoStatusFlag 将媒体状态映射为上报flag
|
|
||||||
func VideoStatusFlag(status videoinformationmod.InformationSatus) int64 {
|
|
||||||
switch status {
|
|
||||||
case videoinformationmod.InformationSatusVerifyOK:
|
|
||||||
return 1 // 上架
|
|
||||||
case videoinformationmod.InformationSatusVerifyCancel:
|
|
||||||
return 2 // 未通过
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
"videoweb/pub/common/godef"
|
|
||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/pub/common/playletcache"
|
"videoweb/pub/common/playletcache"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
@@ -17,7 +16,6 @@ import (
|
|||||||
"videoweb/pub/seo/sitemapdirty"
|
"videoweb/pub/seo/sitemapdirty"
|
||||||
"videoweb/pub/storage"
|
"videoweb/pub/storage"
|
||||||
"videoweb/pub/storage/proxy"
|
"videoweb/pub/storage/proxy"
|
||||||
"videoweb/web/service/srv_report"
|
|
||||||
"videoweb/web/service/srv_search"
|
"videoweb/web/service/srv_search"
|
||||||
"videoweb/web/service/srv_seopush"
|
"videoweb/web/service/srv_seopush"
|
||||||
"videoweb/web/service/srv_videoslug"
|
"videoweb/web/service/srv_videoslug"
|
||||||
@@ -353,15 +351,6 @@ func UpdateVideoInfo(ctx context.Context, id, userId int64, param VideoInfoUpdat
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if param.Status != nil && info.Status != *param.Status {
|
|
||||||
if flag := srv_report.VideoStatusFlag(*param.Status); flag != 0 {
|
|
||||||
mediaCopy := *info
|
|
||||||
mediaCopy.Status = *param.Status
|
|
||||||
godef.Go(func() {
|
|
||||||
srv_report.ReportVideoStatusChangeEvent(&mediaCopy, flag, userId, ua)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sitemapdirty.Mark(ctx)
|
sitemapdirty.Mark(ctx)
|
||||||
if param.Status != nil {
|
if param.Status != nil {
|
||||||
if *param.Status == videoinformationmod.InformationSatusVerifyOK &&
|
if *param.Status == videoinformationmod.InformationSatusVerifyOK &&
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
package job
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"videoweb/pub/common/log"
|
|
||||||
"videoweb/pub/dataReport"
|
|
||||||
"videoweb/pub/models/eventmod"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
)
|
|
||||||
|
|
||||||
var isRuining = false
|
|
||||||
|
|
||||||
const (
|
|
||||||
maxRetryCount = 10 // 最大重试次数
|
|
||||||
maxReportNum = 100 // 最大上报数
|
|
||||||
)
|
|
||||||
|
|
||||||
func Report() {
|
|
||||||
//防止重入
|
|
||||||
if isRuining {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isRuining = true
|
|
||||||
defer func() {
|
|
||||||
isRuining = false
|
|
||||||
}()
|
|
||||||
ctx := context.Background()
|
|
||||||
opts := options.Find()
|
|
||||||
opts = opts.SetSort(bson.D{{Key: "_id", Value: 1}}).SetLimit(1000)
|
|
||||||
// 查询出一千条记录批量上传
|
|
||||||
list, stdErr := eventmod.FindManyEvent(ctx, bson.M{
|
|
||||||
"$or": []bson.M{
|
|
||||||
bson.M{
|
|
||||||
"status": eventmod.Default,
|
|
||||||
},
|
|
||||||
bson.M{
|
|
||||||
"status": eventmod.Failure,
|
|
||||||
"retryCount": bson.M{"$lte": maxRetryCount},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, opts)
|
|
||||||
if stdErr != nil {
|
|
||||||
log.Error("Get event list error", log.E(stdErr))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(list) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var eventList []*dataReport.CommonField
|
|
||||||
for _, v := range list {
|
|
||||||
event := &dataReport.CommonField{}
|
|
||||||
err := json.Unmarshal([]byte(v.Data), &event)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("event report json.Unmarshal fail", log.Any("eventData", v.Data), log.E(err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
eventList = append(eventList, event)
|
|
||||||
if len(eventList) < maxReportNum {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// 批量上报
|
|
||||||
err = dataReport.BatchReport(ctx, eventList)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Batch report error", log.E(err))
|
|
||||||
// 将这些设置为失败
|
|
||||||
onReportEventFail(ctx, eventList)
|
|
||||||
} else {
|
|
||||||
onReportEventSuccess(ctx, eventList)
|
|
||||||
}
|
|
||||||
eventList = []*dataReport.CommonField{} // 重新变成0个
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将剩余的批量上报
|
|
||||||
err := dataReport.BatchReport(ctx, eventList)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Batch report error", log.E(err))
|
|
||||||
// 将这些设置为失败
|
|
||||||
onReportEventFail(ctx, eventList)
|
|
||||||
} else {
|
|
||||||
onReportEventSuccess(ctx, eventList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func onReportEventSuccess(ctx context.Context, eventList []*dataReport.CommonField) {
|
|
||||||
eventIds := []string{}
|
|
||||||
for _, v := range eventList {
|
|
||||||
eventIds = append(eventIds, v.EventID)
|
|
||||||
}
|
|
||||||
if len(eventIds) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err := eventmod.UpdateManyEvent(ctx, bson.M{
|
|
||||||
"eventId": bson.M{"$in": eventIds},
|
|
||||||
}, bson.M{
|
|
||||||
"$set": bson.M{"status": eventmod.Success},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Update event fail", log.E(err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func onReportEventFail(ctx context.Context, eventList []*dataReport.CommonField) {
|
|
||||||
eventIds := []string{}
|
|
||||||
for _, v := range eventList {
|
|
||||||
eventIds = append(eventIds, v.EventID)
|
|
||||||
}
|
|
||||||
if len(eventIds) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err := eventmod.UpdateManyEvent(ctx, bson.M{
|
|
||||||
"eventId": bson.M{"$in": eventIds},
|
|
||||||
}, bson.M{
|
|
||||||
"$set": bson.M{"status": eventmod.Failure},
|
|
||||||
"$inc": bson.M{"retryCount": 1},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Update event fail", log.E(err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"videoweb/pub/common/log"
|
"videoweb/pub/common/log"
|
||||||
"videoweb/web/service/srv_aicomment"
|
"videoweb/web/service/srv_aicomment"
|
||||||
"videoweb/web/service/srv_mediaresource"
|
"videoweb/web/service/srv_mediaresource"
|
||||||
job "videoweb/web/skd/job/reportdata"
|
|
||||||
seopushjob "videoweb/web/skd/job/seopush"
|
seopushjob "videoweb/web/skd/job/seopush"
|
||||||
"videoweb/web/skd/job/vipexpiry"
|
"videoweb/web/skd/job/vipexpiry"
|
||||||
"videoweb/web/skd/playletwatermark"
|
"videoweb/web/skd/playletwatermark"
|
||||||
@@ -64,10 +63,6 @@ func Start() {
|
|||||||
srv_mediaresource.StartCGDJOriginalBackfillOnce(context.Background())
|
srv_mediaresource.StartCGDJOriginalBackfillOnce(context.Background())
|
||||||
go srv_mediaresource.RefreshAIContentBackflowTodayStats()
|
go srv_mediaresource.RefreshAIContentBackflowTodayStats()
|
||||||
|
|
||||||
_, _ = skdCron.AddFunc("0/1 * * * * ?", func() { // 每秒执行一次批量上报
|
|
||||||
job.Report()
|
|
||||||
})
|
|
||||||
|
|
||||||
// 每天凌晨 02:00 重置 VIP 已过期用户的 VipType
|
// 每天凌晨 02:00 重置 VIP 已过期用户的 VipType
|
||||||
_, _ = skdCron.AddFunc("0 0 2 * * ?", func() {
|
_, _ = skdCron.AddFunc("0 0 2 * * ?", func() {
|
||||||
vipexpiry.ResetExpiredVip()
|
vipexpiry.ResetExpiredVip()
|
||||||
|
|||||||
@@ -57,9 +57,6 @@ type GlobalCfgEx struct {
|
|||||||
Secret string `yaml:"secret"` // 商户密钥
|
Secret string `yaml:"secret"` // 商户密钥
|
||||||
} `yaml:"playletMediaResourceDBCfg"`
|
} `yaml:"playletMediaResourceDBCfg"`
|
||||||
NewInnerStatUrl string `yaml:"newInnerStatUrl"`
|
NewInnerStatUrl string `yaml:"newInnerStatUrl"`
|
||||||
DataReport struct {
|
|
||||||
Url string `yaml:"url"`
|
|
||||||
} `yaml:"dataReport"`
|
|
||||||
AiComment struct {
|
AiComment struct {
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
AppId string `yaml:"appId"`
|
AppId string `yaml:"appId"`
|
||||||
|
|||||||
Reference in New Issue
Block a user