Compare commits

..
14 Commits
Author SHA1 Message Date
rootandClaude Opus 4.7 ea87fafb6b refactor(adcenter): /api/app/ads/click 改用 AdsClickInfo,接收并透传 appId
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-29 16:23:29 +08:00
rootandClaude Opus 4.7 a1c12f0971 feat(adcenter): 新增 POST /api/app/ads/click 广告点击上报到广告中心
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-29 16:19:52 +08:00
root 4a794a4ccc 广告修改 2026-10-28 17:19:24 +08:00
rootandClaude Opus 4.7 456ebdad45 feat(adcenter): 切到 versionUrl /api/stat/advitise/v2/get 接口拉取,appId=12
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-28 17:10:23 +08:00
rootandClaude Opus 5.5 7bf8bf3030 sitemap 播放页直接写第一集地址,避免 /play/{slug}/ 301
取第一集的规则与 app 详情接口选集列表一致(集号、ID 升序;原创剧只算已加水印的剧集),
没有可播放剧集的短剧不再写入 sitemap。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 10:55:29 +08:00
root b0bbda3a55 鉴权 2026-10-24 11:21:35 +08:00
root 813fc6aa01 验证 2026-10-22 18:14:31 +08:00
root 2d5a890a14 配置文件 2026-09-23 23:01:29 +08:00
rootandClaude Opus 5.5 ad016ee1ac 专题和短剧 slug 改为 8 位随机小写字母
后台新建/修改(未填 slug)和媒资入库时生成随机 slug,不再按标题拼音生成;标签、分类不变。

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 22:10:53 +08:00
rootandClaude Opus 5.5 5a6cd2a51b web 部署脚本改为调用 web 自己的 up_app.sh
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 17:26:24 +08:00
rootandClaude Opus 5.5 d378ddb0ab 后台登录取消谷歌验证,密码正确即登录
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 17:26:24 +08:00
rootandClaude Opus 5.5 07fcde2148 广告改为参考模板从媒资中心按 AppId 拉取
- 新增 proxy.QueryAdvitise / storage.QueryAdvitiseList,调用 /media/web/app/advitise
- proxy.AdvitiseInfo 兼容 id 为数字或字符串
- configser 改用 UpdateAdvitiseData,定时拉取并拼接 CDN,移除广告中心(Jt)拉取
- proto.AdvitiseData 改为 proxy.AdvitiseData 别名,应用列表 A/B 广告位改用 appInfoAList/appInfoBList
- 同步 swagger 文档

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 16:32:12 +08:00
root 442f0c0d1c 更新脚本 2026-09-23 16:29:09 +08:00
rootandClaude Opus 5.5 4efdbfeffc app端取消用户注册和token验证,改为按设备ID识别用户
- 删除注册、登录、找回密码、游客登录接口及密码、token 相关代码
- 鉴权中间件不再校验 token,按 X-User-Agent 中的 devID 识别用户,首次访问自动创建,Redis 缓存 10 分钟
- 渠道码改从请求头 channel 读取;修改资料不再支持改密码
- 同步更新 swagger 文档

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 16:22:10 +08:00
34 changed files with 892 additions and 2075 deletions
+31
View File
@@ -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
View File
@@ -1,10 +1,8 @@
package authapi package authapi
import ( import (
"strings"
"videoweb/app/service/authser" "videoweb/app/service/authser"
"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"
@@ -17,132 +15,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" binding:"required"` // 邮箱
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 均为可选,至少提供一项。修改密码时旧密码和新密码必须同时提供。 // @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 "修改资料参数"
@@ -166,8 +49,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)
@@ -179,7 +60,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 "失败"
@@ -187,7 +68,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 {
@@ -201,27 +82,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, "")
}
+2 -19
View File
@@ -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"` // 暂停广告
}
+12 -12
View File
@@ -1,19 +1,19 @@
redis: redis:
addr: "172.104.181.99:16789" addr: 139.162.47.194:6379
db: 2 db: 1
passwd: "B6vJHlYiTseLj77z" passwd: "Redis@fish2026!"
subscribe: true subscribe: true
mongodb: 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" addr: "mongodb://webhgdj:lQbmsIanlpZAj6au3Nh5gqWN6GV0@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/webhgdj?replicaSet=fish0&maxPoolSize=200&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" logaddr: "mongodb://webhgdj:lQbmsIanlpZAj6au3Nh5gqWN6GV0@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/webhgdj_log?replicaSet=fish0&maxPoolSize=200&authSource=admin"
es: es:
addr: "http://172.104.181.99:9200" addr: "http://139.162.47.194:9200"
user: "elastic" user: "elastic"
pass: "admin123456" pass: "Es@fish2026!"
httpOptions: httpOptions:
dcCtxTimeOut: 10 dcCtxTimeOut: 10
jwtKey: "2311b15a4da1c80dc541b99abb622233" jwtKey: "2311b15a4da1c80dc541b99abb622233"
runMod: "debug" runMod: "prod"
resKey: "vEukA&w15z4VAD3kAY#fkL#rBnU!WDhN" resKey: "vEukA&w15z4VAD3kAY#fkL#rBnU!WDhN"
cdnKey: "vEukAw15z4VAD3kAYfkLrBnUWDhN123" cdnKey: "vEukAw15z4VAD3kAYfkLrBnUWDhN123"
tsAuthKey: "fT5xSg4hltHpzVy6aV9rVECDJ1J1pN" tsAuthKey: "fT5xSg4hltHpzVy6aV9rVECDJ1J1pN"
@@ -24,12 +24,12 @@ attack:
h5key: "kaFttDJRcahRMTI7" h5key: "kaFttDJRcahRMTI7"
windowDurationSeconds: 60 windowDurationSeconds: 60
pprof: false pprof: false
host: "172.104.181.99" host: "172.104.166.87"
listenAddr: "25119" listenAddr: "20001"
origDomain: "https://yuan.bbaazz.me/" origDomain: "https://yuan.bbaazz.me/"
trustedProxies: "" trustedProxies: ""
bucketVideoAddressV2: "http://139.162.22.207:24996" bucketVideoAddressV2: "http://139.162.27.29:19996"
transactionUrl: "https://bill.ruishengces.com" versionUrl: "http://139.162.47.194:8089"
adCenter: adCenter:
apiDomain: "https://adopenapi.adcs01.top" apiDomain: "https://adopenapi.adcs01.top"
merchantCode: "1991129808640122880" merchantCode: "1991129808640122880"
+8 -25
View File
@@ -1,28 +1,11 @@
#!/bin/bash #!/bin/bash
FILE_NAME="web_mdcom_app" echo "开始"
REMOTE_FILE_PATH="/home/server2/web_mdcom/app/" rm -rf ./web_huangguo_app ./web_huangguo_app.tar.gz
TAG_NAME="web_mdcom_app.tar.gz" GOOS=linux GOARCH=amd64 go build -o web_huangguo_app
tar zvcf web_huangguo_app.tar.gz web_huangguo_app
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 scp web_huangguo_app.tar.gz root@172.104.166.87:/data/uzip
if [[ ! "yes" =~ $word ]]; then ssh root@172.104.166.87 "/server/web_huangguo/app/up_app.sh"
echo "终止"
else rm -rf ./web_huangguo_app ./web_huangguo_app.tar.gz
read -e -p "本次更新内容(输入q退出编辑): " -r content
echo "开始"
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
GOOS=linux GOARCH=amd64 go build -o $FILE_NAME
md5sum $FILE_NAME | cut -d ' ' -f1 >yinsemd5.txt
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 -i ~/.ssh/id_rsa -P 22889 ./$TAG_NAME server2@116.212.120.2:$REMOTE_FILE_PATH
send_msg -4791758991 #服务器小组
fi
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
-11
View File
@@ -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
+117 -401
View File
@@ -58,7 +58,7 @@ const docTemplate = `{
}, },
"/api/app/auth/getInfo": { "/api/app/auth/getInfo": {
"get": { "get": {
"description": "通过 token 获取最新用户信息,包含金币余额、VIP状态等", "description": "按请求头 X-User-Agent 中的 devID 识别用户,返回最新用户信息,包含金币余额、VIP状态等",
"produces": [ "produces": [
"application/json" "application/json"
], ],
@@ -82,89 +82,9 @@ const docTemplate = `{
} }
} }
}, },
"/api/app/auth/guest": {
"post": {
"description": "按设备ID创建或找回游客账号;请求头可带 Authorization 复用已有游客会话。需传 X-User-Agent",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "游客登录",
"parameters": [
{
"description": "游客登录参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authser.GuestLoginReq"
}
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"$ref": "#/definitions/authser.LoginResp"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/auth/login": {
"post": {
"description": "账号或邮箱均可作为登录凭证",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "登录",
"parameters": [
{
"description": "登录参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authapi.loginReq"
}
}
],
"responses": {
"200": {
"description": "登录成功,返回 token 及用户基本信息",
"schema": {
"$ref": "#/definitions/authser.LoginResp"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/auth/profile": { "/api/app/auth/profile": {
"post": { "post": {
"description": "用户信息通过 token 获取,无需传账号;nickName、avatar、introduction、oldPassword+newPassword 均为可选,至少提供一项。修改密码时旧密码和新密码必须同时提供。", "description": "按请求头 X-User-Agent 中的 devID 识别用户;nickName、avatar、introduction、privacyMode 均为可选,至少提供一项。",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@@ -174,7 +94,7 @@ const docTemplate = `{
"tags": [ "tags": [
"用户认证" "用户认证"
], ],
"summary": "修改用户资料(头像 / 简介 / 密码,可任意组合)", "summary": "修改用户资料(昵称 / 头像 / 简介 / 隐私模式,可任意组合)",
"parameters": [ "parameters": [
{ {
"description": "修改资料参数", "description": "修改资料参数",
@@ -202,86 +122,6 @@ const docTemplate = `{
} }
} }
}, },
"/api/app/auth/register": {
"post": {
"description": "传入账号、邮箱、明文密码。请求头带游客 Authorization 时升级该游客为普通用户,否则新建用户",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "注册",
"parameters": [
{
"description": "注册参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authapi.registerReq"
}
}
],
"responses": {
"200": {
"description": "注册成功,返回 token 及用户基本信息",
"schema": {
"$ref": "#/definitions/authser.LoginResp"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/auth/resetPassword": {
"post": {
"description": "通过账号和邮箱双重校验后重置密码,两者必须同时匹配同一用户",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "找回密码",
"parameters": [
{
"description": "找回密码参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authapi.resetPasswordReq"
}
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"type": "string"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/coin/buy": { "/api/app/coin/buy": {
"post": { "post": {
"security": [ "security": [
@@ -2295,87 +2135,6 @@ const docTemplate = `{
} }
}, },
"definitions": { "definitions": {
"authapi.loginReq": {
"type": "object",
"required": [
"account",
"password"
],
"properties": {
"account": {
"description": "账号或邮箱",
"type": "string"
},
"channel": {
"description": "渠道码(可选,用户无商区码时写入)",
"type": "string"
},
"devID": {
"description": "设备唯一标示(可选)",
"type": "string"
},
"password": {
"description": "明文密码",
"type": "string"
}
}
},
"authapi.registerReq": {
"type": "object",
"required": [
"accountNo",
"email",
"password"
],
"properties": {
"accountNo": {
"description": "账号",
"type": "string"
},
"agentInviteCode": {
"description": "邀请人的邀请码(可选)",
"type": "string"
},
"channel": {
"description": "渠道码(可选,用户无商区码时写入)",
"type": "string"
},
"devID": {
"description": "设备唯一标示(可选)",
"type": "string"
},
"email": {
"description": "邮箱",
"type": "string"
},
"password": {
"description": "明文密码",
"type": "string"
}
}
},
"authapi.resetPasswordReq": {
"type": "object",
"required": [
"accountNo",
"email",
"newPassword"
],
"properties": {
"accountNo": {
"description": "账号",
"type": "string"
},
"email": {
"description": "邮箱",
"type": "string"
},
"newPassword": {
"description": "新密码",
"type": "string"
}
}
},
"authapi.updateProfileReq": { "authapi.updateProfileReq": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -2387,45 +2146,16 @@ const docTemplate = `{
"description": "简介(可选)", "description": "简介(可选)",
"type": "string" "type": "string"
}, },
"newPassword": {
"description": "新密码明文(修改密码时必填)",
"type": "string"
},
"nickName": { "nickName": {
"description": "新昵称(可选)", "description": "新昵称(可选)",
"type": "string" "type": "string"
}, },
"oldPassword": {
"description": "旧密码明文(修改密码时必填)",
"type": "string"
},
"privacyMode": { "privacyMode": {
"description": "隐私模式:true-开启,false-关闭(可选)", "description": "隐私模式:true-开启,false-关闭(可选)",
"type": "boolean" "type": "boolean"
} }
} }
}, },
"authser.GuestLoginReq": {
"type": "object",
"properties": {
"channel": {
"description": "渠道码(可选,用户无商区码时写入 DistrictCode)",
"type": "string"
},
"devID": {
"description": "设备唯一标示(必填)",
"type": "string"
},
"deviceId": {
"description": "备用设备ID(可选,写入 DevV2)",
"type": "string"
},
"mac": {
"description": "设备 Mac(可选)",
"type": "string"
}
}
},
"authser.LoginResp": { "authser.LoginResp": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -2451,10 +2181,6 @@ const docTemplate = `{
"description": "邀请码", "description": "邀请码",
"type": "string" "type": "string"
}, },
"isNewUser": {
"description": "本次是否新建游客",
"type": "boolean"
},
"isRegister": { "isRegister": {
"description": "是否已注册", "description": "是否已注册",
"type": "boolean" "type": "boolean"
@@ -2493,9 +2219,6 @@ const docTemplate = `{
"status": { "status": {
"$ref": "#/definitions/pubdef.UserStatus" "$ref": "#/definitions/pubdef.UserStatus"
}, },
"token": {
"type": "string"
},
"type": { "type": {
"description": "身份类型:0游客 1普通用户", "description": "身份类型:0游客 1普通用户",
"allOf": [ "allOf": [
@@ -2585,123 +2308,6 @@ const docTemplate = `{
"TranTypeAdminAdjust" "TranTypeAdminAdjust"
] ]
}, },
"proto.AdvitiseData": {
"type": "object",
"properties": {
"AList": {
"description": "固定12广告位",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"BList": {
"description": "固定13广告位",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"bottomBanner": {
"description": "底部banner",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"detailTopList": {
"description": "详情页顶部广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"detailbannerList": {
"description": "详情banner",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"dialogList": {
"description": "弹窗广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"downList": {
"description": "底部广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"floatingList": {
"description": "悬浮小方块",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"friendList": {
"description": "友链",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"homeList": {
"description": "首页列表",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"launchScreenList": {
"description": "启动页广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"nineGridList": {
"description": "9宫格",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"pauseyList": {
"description": "暂停广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"playList": {
"description": "播放强制跳转",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"titleList": {
"description": "标题广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoInfoList": {
"description": "视频详情",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
}
}
},
"proto.AnnouncementItem": { "proto.AnnouncementItem": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -2803,7 +2409,7 @@ const docTemplate = `{
"description": "广告", "description": "广告",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -3424,7 +3030,7 @@ const docTemplate = `{
"description": "广告配置", "description": "广告配置",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -3719,7 +3325,7 @@ const docTemplate = `{
"description": "广告", "description": "广告",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -5634,7 +5240,7 @@ const docTemplate = `{
"description": "广告", "description": "广告",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -5775,6 +5381,116 @@ const docTemplate = `{
} }
} }
}, },
"proxy.AdvitiseData": {
"type": "object",
"properties": {
"appInfoAList": {
"description": "应用管理广告A",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"appInfoBList": {
"description": "应用管理广告B",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"dialogList": {
"description": "弹窗广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"forcedJumpList": {
"description": "强制跳转广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"friendList": {
"description": "友链",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"homeList": {
"description": "首页列表",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"hotAppList": {
"description": "热门应用",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"mustAppList": {
"description": "必备精品",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"newAppList": {
"description": "最新上架",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"nineGridList": {
"description": "9宫格",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"stopList": {
"description": "暂停广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"titleAppList": {
"description": "标题广告(APP名称)",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoDownList": {
"description": "帖子详情(下)",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoList": {
"description": "视频列表",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoTopList": {
"description": "帖子详情(上)",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
}
}
},
"proxy.AdvitiseInfo": { "proxy.AdvitiseInfo": {
"type": "object", "type": "object",
"properties": { "properties": {
+117 -401
View File
@@ -56,7 +56,7 @@
}, },
"/api/app/auth/getInfo": { "/api/app/auth/getInfo": {
"get": { "get": {
"description": "通过 token 获取最新用户信息,包含金币余额、VIP状态等", "description": "按请求头 X-User-Agent 中的 devID 识别用户,返回最新用户信息,包含金币余额、VIP状态等",
"produces": [ "produces": [
"application/json" "application/json"
], ],
@@ -80,89 +80,9 @@
} }
} }
}, },
"/api/app/auth/guest": {
"post": {
"description": "按设备ID创建或找回游客账号;请求头可带 Authorization 复用已有游客会话。需传 X-User-Agent",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "游客登录",
"parameters": [
{
"description": "游客登录参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authser.GuestLoginReq"
}
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"$ref": "#/definitions/authser.LoginResp"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/auth/login": {
"post": {
"description": "账号或邮箱均可作为登录凭证",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "登录",
"parameters": [
{
"description": "登录参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authapi.loginReq"
}
}
],
"responses": {
"200": {
"description": "登录成功,返回 token 及用户基本信息",
"schema": {
"$ref": "#/definitions/authser.LoginResp"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/auth/profile": { "/api/app/auth/profile": {
"post": { "post": {
"description": "用户信息通过 token 获取,无需传账号;nickName、avatar、introduction、oldPassword+newPassword 均为可选,至少提供一项。修改密码时旧密码和新密码必须同时提供。", "description": "按请求头 X-User-Agent 中的 devID 识别用户;nickName、avatar、introduction、privacyMode 均为可选,至少提供一项。",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@@ -172,7 +92,7 @@
"tags": [ "tags": [
"用户认证" "用户认证"
], ],
"summary": "修改用户资料(头像 / 简介 / 密码,可任意组合)", "summary": "修改用户资料(昵称 / 头像 / 简介 / 隐私模式,可任意组合)",
"parameters": [ "parameters": [
{ {
"description": "修改资料参数", "description": "修改资料参数",
@@ -200,86 +120,6 @@
} }
} }
}, },
"/api/app/auth/register": {
"post": {
"description": "传入账号、邮箱、明文密码。请求头带游客 Authorization 时升级该游客为普通用户,否则新建用户",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "注册",
"parameters": [
{
"description": "注册参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authapi.registerReq"
}
}
],
"responses": {
"200": {
"description": "注册成功,返回 token 及用户基本信息",
"schema": {
"$ref": "#/definitions/authser.LoginResp"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/auth/resetPassword": {
"post": {
"description": "通过账号和邮箱双重校验后重置密码,两者必须同时匹配同一用户",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户认证"
],
"summary": "找回密码",
"parameters": [
{
"description": "找回密码参数",
"name": "param",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/authapi.resetPasswordReq"
}
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"type": "string"
}
},
"400": {
"description": "失败",
"schema": {
"type": "string"
}
}
}
}
},
"/api/app/coin/buy": { "/api/app/coin/buy": {
"post": { "post": {
"security": [ "security": [
@@ -2293,87 +2133,6 @@
} }
}, },
"definitions": { "definitions": {
"authapi.loginReq": {
"type": "object",
"required": [
"account",
"password"
],
"properties": {
"account": {
"description": "账号或邮箱",
"type": "string"
},
"channel": {
"description": "渠道码(可选,用户无商区码时写入)",
"type": "string"
},
"devID": {
"description": "设备唯一标示(可选)",
"type": "string"
},
"password": {
"description": "明文密码",
"type": "string"
}
}
},
"authapi.registerReq": {
"type": "object",
"required": [
"accountNo",
"email",
"password"
],
"properties": {
"accountNo": {
"description": "账号",
"type": "string"
},
"agentInviteCode": {
"description": "邀请人的邀请码(可选)",
"type": "string"
},
"channel": {
"description": "渠道码(可选,用户无商区码时写入)",
"type": "string"
},
"devID": {
"description": "设备唯一标示(可选)",
"type": "string"
},
"email": {
"description": "邮箱",
"type": "string"
},
"password": {
"description": "明文密码",
"type": "string"
}
}
},
"authapi.resetPasswordReq": {
"type": "object",
"required": [
"accountNo",
"email",
"newPassword"
],
"properties": {
"accountNo": {
"description": "账号",
"type": "string"
},
"email": {
"description": "邮箱",
"type": "string"
},
"newPassword": {
"description": "新密码",
"type": "string"
}
}
},
"authapi.updateProfileReq": { "authapi.updateProfileReq": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -2385,45 +2144,16 @@
"description": "简介(可选)", "description": "简介(可选)",
"type": "string" "type": "string"
}, },
"newPassword": {
"description": "新密码明文(修改密码时必填)",
"type": "string"
},
"nickName": { "nickName": {
"description": "新昵称(可选)", "description": "新昵称(可选)",
"type": "string" "type": "string"
}, },
"oldPassword": {
"description": "旧密码明文(修改密码时必填)",
"type": "string"
},
"privacyMode": { "privacyMode": {
"description": "隐私模式:true-开启,false-关闭(可选)", "description": "隐私模式:true-开启,false-关闭(可选)",
"type": "boolean" "type": "boolean"
} }
} }
}, },
"authser.GuestLoginReq": {
"type": "object",
"properties": {
"channel": {
"description": "渠道码(可选,用户无商区码时写入 DistrictCode)",
"type": "string"
},
"devID": {
"description": "设备唯一标示(必填)",
"type": "string"
},
"deviceId": {
"description": "备用设备ID(可选,写入 DevV2)",
"type": "string"
},
"mac": {
"description": "设备 Mac(可选)",
"type": "string"
}
}
},
"authser.LoginResp": { "authser.LoginResp": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -2449,10 +2179,6 @@
"description": "邀请码", "description": "邀请码",
"type": "string" "type": "string"
}, },
"isNewUser": {
"description": "本次是否新建游客",
"type": "boolean"
},
"isRegister": { "isRegister": {
"description": "是否已注册", "description": "是否已注册",
"type": "boolean" "type": "boolean"
@@ -2491,9 +2217,6 @@
"status": { "status": {
"$ref": "#/definitions/pubdef.UserStatus" "$ref": "#/definitions/pubdef.UserStatus"
}, },
"token": {
"type": "string"
},
"type": { "type": {
"description": "身份类型:0游客 1普通用户", "description": "身份类型:0游客 1普通用户",
"allOf": [ "allOf": [
@@ -2583,123 +2306,6 @@
"TranTypeAdminAdjust" "TranTypeAdminAdjust"
] ]
}, },
"proto.AdvitiseData": {
"type": "object",
"properties": {
"AList": {
"description": "固定12广告位",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"BList": {
"description": "固定13广告位",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"bottomBanner": {
"description": "底部banner",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"detailTopList": {
"description": "详情页顶部广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"detailbannerList": {
"description": "详情banner",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"dialogList": {
"description": "弹窗广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"downList": {
"description": "底部广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"floatingList": {
"description": "悬浮小方块",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"friendList": {
"description": "友链",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"homeList": {
"description": "首页列表",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"launchScreenList": {
"description": "启动页广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"nineGridList": {
"description": "9宫格",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"pauseyList": {
"description": "暂停广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"playList": {
"description": "播放强制跳转",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"titleList": {
"description": "标题广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoInfoList": {
"description": "视频详情",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
}
}
},
"proto.AnnouncementItem": { "proto.AnnouncementItem": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -2801,7 +2407,7 @@
"description": "广告", "description": "广告",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -3422,7 +3028,7 @@
"description": "广告配置", "description": "广告配置",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -3717,7 +3323,7 @@
"description": "广告", "description": "广告",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -5632,7 +5238,7 @@
"description": "广告", "description": "广告",
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/proto.AdvitiseData" "$ref": "#/definitions/proxy.AdvitiseData"
} }
] ]
}, },
@@ -5773,6 +5379,116 @@
} }
} }
}, },
"proxy.AdvitiseData": {
"type": "object",
"properties": {
"appInfoAList": {
"description": "应用管理广告A",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"appInfoBList": {
"description": "应用管理广告B",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"dialogList": {
"description": "弹窗广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"forcedJumpList": {
"description": "强制跳转广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"friendList": {
"description": "友链",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"homeList": {
"description": "首页列表",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"hotAppList": {
"description": "热门应用",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"mustAppList": {
"description": "必备精品",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"newAppList": {
"description": "最新上架",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"nineGridList": {
"description": "9宫格",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"stopList": {
"description": "暂停广告",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"titleAppList": {
"description": "标题广告(APP名称)",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoDownList": {
"description": "帖子详情(下)",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoList": {
"description": "视频列表",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
},
"videoTopList": {
"description": "帖子详情(上)",
"type": "array",
"items": {
"$ref": "#/definitions/proxy.AdvitiseInfo"
}
}
}
},
"proxy.AdvitiseInfo": { "proxy.AdvitiseInfo": {
"type": "object", "type": "object",
"properties": { "properties": {
+86 -280
View File
@@ -1,64 +1,5 @@
basePath: / basePath: /
definitions: definitions:
authapi.loginReq:
properties:
account:
description: 账号或邮箱
type: string
channel:
description: 渠道码(可选,用户无商区码时写入)
type: string
devID:
description: 设备唯一标示(可选)
type: string
password:
description: 明文密码
type: string
required:
- account
- password
type: object
authapi.registerReq:
properties:
accountNo:
description: 账号
type: string
agentInviteCode:
description: 邀请人的邀请码(可选)
type: string
channel:
description: 渠道码(可选,用户无商区码时写入)
type: string
devID:
description: 设备唯一标示(可选)
type: string
email:
description: 邮箱
type: string
password:
description: 明文密码
type: string
required:
- accountNo
- email
- password
type: object
authapi.resetPasswordReq:
properties:
accountNo:
description: 账号
type: string
email:
description: 邮箱
type: string
newPassword:
description: 新密码
type: string
required:
- accountNo
- email
- newPassword
type: object
authapi.updateProfileReq: authapi.updateProfileReq:
properties: properties:
avatar: avatar:
@@ -67,34 +8,13 @@ definitions:
introduction: introduction:
description: 简介(可选) description: 简介(可选)
type: string type: string
newPassword:
description: 新密码明文(修改密码时必填)
type: string
nickName: nickName:
description: 新昵称(可选) description: 新昵称(可选)
type: string type: string
oldPassword:
description: 旧密码明文(修改密码时必填)
type: string
privacyMode: privacyMode:
description: 隐私模式:true-开启,false-关闭(可选) description: 隐私模式:true-开启,false-关闭(可选)
type: boolean type: boolean
type: object type: object
authser.GuestLoginReq:
properties:
channel:
description: 渠道码(可选,用户无商区码时写入 DistrictCode)
type: string
devID:
description: 设备唯一标示(必填)
type: string
deviceId:
description: 备用设备ID(可选,写入 DevV2)
type: string
mac:
description: 设备 Mac(可选)
type: string
type: object
authser.LoginResp: authser.LoginResp:
properties: properties:
accountNo: accountNo:
@@ -113,9 +33,6 @@ definitions:
inviteCode: inviteCode:
description: 邀请码 description: 邀请码
type: string type: string
isNewUser:
description: 本次是否新建游客
type: boolean
isRegister: isRegister:
description: 是否已注册 description: 是否已注册
type: boolean type: boolean
@@ -142,8 +59,6 @@ definitions:
type: string type: string
status: status:
$ref: '#/definitions/pubdef.UserStatus' $ref: '#/definitions/pubdef.UserStatus'
token:
type: string
type: type:
allOf: allOf:
- $ref: '#/definitions/pubdef.UserType' - $ref: '#/definitions/pubdef.UserType'
@@ -207,89 +122,6 @@ definitions:
- TranTypeDarkAlley - TranTypeDarkAlley
- TranTypeVideoUnlock - TranTypeVideoUnlock
- TranTypeAdminAdjust - TranTypeAdminAdjust
proto.AdvitiseData:
properties:
AList:
description: 固定12广告位
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
BList:
description: 固定13广告位
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
bottomBanner:
description: 底部banner
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
detailTopList:
description: 详情页顶部广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
detailbannerList:
description: 详情banner
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
dialogList:
description: 弹窗广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
downList:
description: 底部广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
floatingList:
description: 悬浮小方块
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
friendList:
description: 友链
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
homeList:
description: 首页列表
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
launchScreenList:
description: 启动页广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
nineGridList:
description: 9宫格
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
pauseyList:
description: 暂停广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
playList:
description: 播放强制跳转
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
titleList:
description: 标题广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
videoInfoList:
description: 视频详情
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
type: object
proto.AnnouncementItem: proto.AnnouncementItem:
properties: properties:
content: content:
@@ -362,7 +194,7 @@ definitions:
properties: properties:
advitise: advitise:
allOf: allOf:
- $ref: '#/definitions/proto.AdvitiseData' - $ref: '#/definitions/proxy.AdvitiseData'
description: 广告 description: 广告
category: category:
allOf: allOf:
@@ -804,7 +636,7 @@ definitions:
properties: properties:
advitise: advitise:
allOf: allOf:
- $ref: '#/definitions/proto.AdvitiseData' - $ref: '#/definitions/proxy.AdvitiseData'
description: 广告配置 description: 广告配置
config: config:
allOf: allOf:
@@ -1001,7 +833,7 @@ definitions:
properties: properties:
advitise: advitise:
allOf: allOf:
- $ref: '#/definitions/proto.AdvitiseData' - $ref: '#/definitions/proxy.AdvitiseData'
description: 广告 description: 广告
bottonTranslations: bottonTranslations:
allOf: allOf:
@@ -2351,7 +2183,7 @@ definitions:
properties: properties:
advitise: advitise:
allOf: allOf:
- $ref: '#/definitions/proto.AdvitiseData' - $ref: '#/definitions/proxy.AdvitiseData'
description: 广告 description: 广告
coverImg: coverImg:
description: 封面 description: 封面
@@ -2448,6 +2280,84 @@ definitions:
description: 总共数量 description: 总共数量
type: integer type: integer
type: object type: object
proxy.AdvitiseData:
properties:
appInfoAList:
description: 应用管理广告A
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
appInfoBList:
description: 应用管理广告B
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
dialogList:
description: 弹窗广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
forcedJumpList:
description: 强制跳转广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
friendList:
description: 友链
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
homeList:
description: 首页列表
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
hotAppList:
description: 热门应用
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
mustAppList:
description: 必备精品
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
newAppList:
description: 最新上架
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
nineGridList:
description: 9宫格
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
stopList:
description: 暂停广告
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
titleAppList:
description: 标题广告(APP名称)
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
videoDownList:
description: 帖子详情(下)
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
videoList:
description: 视频列表
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
videoTopList:
description: 帖子详情(上)
items:
$ref: '#/definitions/proxy.AdvitiseInfo'
type: array
type: object
proxy.AdvitiseInfo: proxy.AdvitiseInfo:
properties: properties:
id: id:
@@ -3144,7 +3054,7 @@ paths:
- 应用列表 - 应用列表
/api/app/auth/getInfo: /api/app/auth/getInfo:
get: get:
description: 通过 token 获取最新用户信息,包含金币余额、VIP状态等 description: 按请求头 X-User-Agent 中的 devID 识别用户,返回最新用户信息,包含金币余额、VIP状态等
produces: produces:
- application/json - application/json
responses: responses:
@@ -3159,64 +3069,12 @@ paths:
summary: 获取当前用户信息 summary: 获取当前用户信息
tags: tags:
- 用户认证 - 用户认证
/api/app/auth/guest:
post:
consumes:
- application/json
description: 按设备ID创建或找回游客账号;请求头可带 Authorization 复用已有游客会话。需传 X-User-Agent
parameters:
- description: 游客登录参数
in: body
name: param
required: true
schema:
$ref: '#/definitions/authser.GuestLoginReq'
produces:
- application/json
responses:
"200":
description: 成功
schema:
$ref: '#/definitions/authser.LoginResp'
"400":
description: 失败
schema:
type: string
summary: 游客登录
tags:
- 用户认证
/api/app/auth/login:
post:
consumes:
- application/json
description: 账号或邮箱均可作为登录凭证
parameters:
- description: 登录参数
in: body
name: param
required: true
schema:
$ref: '#/definitions/authapi.loginReq'
produces:
- application/json
responses:
"200":
description: 登录成功,返回 token 及用户基本信息
schema:
$ref: '#/definitions/authser.LoginResp'
"400":
description: 失败
schema:
type: string
summary: 登录
tags:
- 用户认证
/api/app/auth/profile: /api/app/auth/profile:
post: post:
consumes: consumes:
- application/json - application/json
description: 用户信息通过 token 获取,无需传账号;nickName、avatar、introduction、oldPassword+newPassword description: 按请求头 X-User-Agent 中的 devID 识别用户;nickName、avatar、introduction、privacyMode
均为可选,至少提供一项。修改密码时旧密码和新密码必须同时提供。 均为可选,至少提供一项。
parameters: parameters:
- description: 修改资料参数 - description: 修改资料参数
in: body in: body
@@ -3235,59 +3093,7 @@ paths:
description: 失败 description: 失败
schema: schema:
type: string type: string
summary: 修改用户资料(头像 / 简介 / 密码,可任意组合) summary: 修改用户资料(昵称 / 头像 / 简介 / 隐私模式,可任意组合)
tags:
- 用户认证
/api/app/auth/register:
post:
consumes:
- application/json
description: 传入账号、邮箱、明文密码。请求头带游客 Authorization 时升级该游客为普通用户,否则新建用户
parameters:
- description: 注册参数
in: body
name: param
required: true
schema:
$ref: '#/definitions/authapi.registerReq'
produces:
- application/json
responses:
"200":
description: 注册成功,返回 token 及用户基本信息
schema:
$ref: '#/definitions/authser.LoginResp'
"400":
description: 失败
schema:
type: string
summary: 注册
tags:
- 用户认证
/api/app/auth/resetPassword:
post:
consumes:
- application/json
description: 通过账号和邮箱双重校验后重置密码,两者必须同时匹配同一用户
parameters:
- description: 找回密码参数
in: body
name: param
required: true
schema:
$ref: '#/definitions/authapi.resetPasswordReq'
produces:
- application/json
responses:
"200":
description: 成功
schema:
type: string
"400":
description: 失败
schema:
type: string
summary: 找回密码
tags: tags:
- 用户认证 - 用户认证
/api/app/coin/buy: /api/app/coin/buy:
+23 -109
View File
@@ -3,129 +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/list",
"/api/app/video/detail",
"/api/app/playlet/home",
"/api/app/playlet/recommend/list",
"/api/app/playlet/list",
"/api/app/playlet/operate/list",
"/api/app/playlet/rank",
"/api/app/playlet/today-update",
"/api/app/playlet/tag/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/health/ping",
"/api/app/statcenter/sync",
"/h5/m3u8",
"/enkey",
"/newenkey",
}
)
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)
} }
+11
View File
@@ -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)
}
-4
View File
@@ -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)
} }
} }
+3 -2
View File
@@ -79,14 +79,14 @@ func registeMiddleware(engine *gin.Engine) {
Methods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodHead, http.MethodDelete}, Methods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodHead, http.MethodDelete},
AllowedHeaders: []string{ AllowedHeaders: []string{
"Content-Length", "Content-Type", "Authorization", "X-User-Agent", "Content-Length", "Content-Type", "Authorization", "X-User-Agent",
"device", "api_version", "x-api-key", "device", "api_version", "x-api-key", "channel",
"sid", "sid",
"device_brand", "device-brand", "device_brand", "device-brand",
"device_model", "device-model", "device_model", "device-model",
"system_name", "system-name", "system_name", "system-name",
"system_version", "system-version", "system_version", "system-version",
}, },
ExposedHeaders: []string{"Content-Disposition", "Refresh-Authorization"}, ExposedHeaders: []string{"Content-Disposition"},
OptionsSuccessStatus: http.StatusOK, OptionsSuccessStatus: http.StatusOK,
}), }),
// 必须是此顺序, happens before原则 // 必须是此顺序, happens before原则
@@ -119,6 +119,7 @@ func registeRouter(r *gin.Engine) {
appInfoRouter(r) appInfoRouter(r)
translationRouter(r) translationRouter(r)
statcenterRouter(r) statcenterRouter(r)
adsRouter(r)
r.GET("/notpage", templatecache.WithCache(time.Minute*1), home.PageNotFound) r.GET("/notpage", templatecache.WithCache(time.Minute*1), home.PageNotFound)
} }
+2 -2
View File
@@ -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 -303
View File
@@ -4,22 +4,16 @@ import (
"context" "context"
"strings" "strings"
"time" "time"
"videoweb/app/appg"
"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",
@@ -47,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"`
@@ -65,275 +58,27 @@ 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"` // 隐私模式
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, "账号已存在", "")
}
// 检查邮箱是否已存在
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)
applyChannelIfMissing(setDoc, guest, channel)
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
}
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
}
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)
applyChannelIfMissing(setDoc, user, channel)
_ = usermod.UpdateOneUser(ctx,
bson.M{usermod.FN.User.Id: user.Id},
bson.M{"$set": setDoc},
)
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 {
@@ -364,7 +109,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) {
@@ -390,16 +135,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 {
@@ -421,21 +164,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.OldPassword == nil || req.NewPassword == nil {
return srvdef.New(srvdef.ErrParamError, "修改密码时旧密码和新密码均需提供", "")
}
if !checkPassword(*req.OldPassword, user.Password) {
return srvdef.New(srvdef.AccountErrPasswordError, "旧密码错误", "")
}
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, "至少需要修改一项资料", "")
@@ -446,27 +174,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(),
}},
)
}
+59 -140
View File
@@ -3,12 +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/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"
@@ -16,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)
}
// isGuestUser 是否为可升级的游客身份 // ResolveDeviceUser 按设备ID识别用户:先查缓存,再查库,都没有则自动创建
func isGuestUser(user *usermod.User) bool { func ResolveDeviceUser(ctx context.Context, ua useragent.UA, ip, channel string) (int64, *srvdef.SrvErr) {
if user == nil { devID := strings.TrimSpace(ua.DevID)
return false if devID == "" {
return 0, srvdef.New(srvdef.ErrParamError, "devID不能为空", "")
} }
if user.Type == pubdef.UserTypeNormal { ua.DevID = devID
return false
}
return !user.IsRegister && strings.TrimSpace(user.AccountNo) == ""
}
// GuestLogin 游客登录:按 token / DevID / Mac / DeviceId 查找,不存在则创建游客 cacheKey := redisconst.AppDeviceUserKey(devID)
func GuestLogin(ctx context.Context, userId int64, ip string, req *GuestLoginReq, ua useragent.UA) (*LoginResp, *srvdef.SrvErr) { if v, err := redis.Get(cacheKey); err == nil && v != nil {
if isBotRequest(ctx) { if userId, perr := strconv.ParseInt(*v, 10, 64); perr == nil && userId > 0 {
return crawlerGuestLogin() return userId, nil
} }
if req == nil || strings.TrimSpace(req.DevID) == "" {
return nil, srvdef.New(srvdef.ErrParamError, "devID不能为空", "")
} }
ua.DevID = strings.TrimSpace(req.DevID)
var user *usermod.User user, serr := findOrCreateDeviceUser(ctx, ua, ip, channel)
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,
@@ -93,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
} }
@@ -105,73 +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, req.Channel) 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)
resp.IsNewUser = isNewUser
if isNewUser {
visit.RecordDailyVisit(ctx, user.Id, ua, ip)
}
return resp, nil
} }
func findGuestUser(ctx context.Context, req *GuestLoginReq) (*usermod.User, *srvdef.SrvErr) { func createGuestUser(ctx context.Context, ua useragent.UA, ip, channel string) (*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,
@@ -181,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,
@@ -211,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,
@@ -248,20 +181,6 @@ func hasDistrictCode(code string) bool {
return strings.TrimSpace(code) != "" return strings.TrimSpace(code) != ""
} }
func isBotRequest(ctx context.Context) bool {
gc, ok := ctx.(*gin.Context)
return ok && reptilerecord.IsBot(gc)
}
// crawlerGuestLogin 给爬虫签发可观看的虚拟游客 token,不建用户、不写日活、不上报。
func crawlerGuestLogin() (*LoginResp, *srvdef.SrvErr) {
token, serr := generateCrawlerToken()
if serr != nil {
return nil, serr
}
return CrawlerLoginResp(token), nil
}
func applyChannelIfMissing(setDoc bson.M, user *usermod.User, channel string) { func applyChannelIfMissing(setDoc bson.M, user *usermod.User, channel string) {
if user == nil || hasDistrictCode(user.DistrictCode) { if user == nil || hasDistrictCode(user.DistrictCode) {
return return
+66
View File
@@ -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)
})
}
+88 -72
View File
@@ -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:
resp.DetailTopList = ads data.NineGridList = append(data.NineGridList, info)
case 3: // 横幅 case 3:
resp.NineGridList = ads 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
} }
+2 -4
View File
@@ -8,7 +8,6 @@ import (
"sync" "sync"
"videoweb/app/api/proto" "videoweb/app/api/proto"
"videoweb/app/service/translationser" "videoweb/app/service/translationser"
"videoweb/pub/adcenter"
"videoweb/pub/common/log" "videoweb/pub/common/log"
"videoweb/pub/common/netutil" "videoweb/pub/common/netutil"
"videoweb/pub/common/srvdef" "videoweb/pub/common/srvdef"
@@ -35,7 +34,6 @@ type CacheInfo struct {
Lock sync.RWMutex // 读写锁 Lock sync.RWMutex // 读写锁
Config proto.ConfigInfo // 系统配置缓存 Config proto.ConfigInfo // 系统配置缓存
Advitise proto.AdvitiseData Advitise proto.AdvitiseData
AdvitiseMap map[string]adcenter.AdCacheInfo
TagCategoryList []proto.VideoTagCategoryData TagCategoryList []proto.VideoTagCategoryData
TotalHistory int64 TotalHistory int64
IpBlackMaps map[string]struct{} IpBlackMaps map[string]struct{}
@@ -61,14 +59,14 @@ func init() {
func Start() { func Start() {
ctx := context.Background() ctx := context.Background()
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()
+9 -9
View File
@@ -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) {
@@ -152,7 +152,7 @@ func GetM3U8Ex(ctx *gin.Context) {
log.Any("vipValid", vipValid), log.Any("vipValid", vipValid),
log.E(countErr)) log.E(countErr))
} else if cnt > limit { } else if cnt > limit {
m3u8Name = m3u8RateLimitFallback // m3u8Name = m3u8RateLimitFallback
status = "rate_limited" status = "rate_limited"
log.Warn("GetM3U8Ex daily rate limit, use fallback m3u8", log.Warn("GetM3U8Ex daily rate limit, use fallback m3u8",
log.Any("ip", ip), log.Any("ip", ip),
+79 -2
View File
@@ -2,11 +2,14 @@ package sitemap
import ( import (
"context" "context"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
"videoweb/pub/common/log"
"videoweb/pub/common/utils" "videoweb/pub/common/utils"
"videoweb/pub/models/playletcategorymod" "videoweb/pub/models/playletcategorymod"
"videoweb/pub/models/playletchaptermod"
"videoweb/pub/models/playletmod" "videoweb/pub/models/playletmod"
"videoweb/pub/models/playlettagmod" "videoweb/pub/models/playlettagmod"
"videoweb/pub/models/playletthememod" "videoweb/pub/models/playletthememod"
@@ -19,6 +22,7 @@ type idWithTime struct {
Id int64 Id int64
Slug string Slug string
LastMod time.Time LastMod time.Time
IsOriginal bool // 仅短剧使用:原创剧只算已加水印的剧集
} }
type staticPageEntry struct { type staticPageEntry struct {
@@ -144,7 +148,7 @@ func getURL(sg *SitemapGenerator) {
if urls := buildPlayletPathURLs(webAddr, listed.items, "/detail", "weekly", 0.7); len(urls) > 0 { if urls := buildPlayletPathURLs(webAddr, listed.items, "/detail", "weekly", 0.7); len(urls) > 0 {
_ = sg.writeSitemapFiles("sitemap-playletdetail", urls) _ = sg.writeSitemapFiles("sitemap-playletdetail", urls)
} }
if urls := buildPlayletPathURLs(webAddr, listed.items, "/play", "weekly", 0.6); len(urls) > 0 { if urls := buildPlayletPlayURLs(webAddr, listed.items, firstPlayletChapterIDs(ctx, listed.items), "weekly", 0.6); len(urls) > 0 {
_ = sg.writeSitemapFiles("sitemap-playletplay", urls) _ = sg.writeSitemapFiles("sitemap-playletplay", urls)
} }
} }
@@ -194,6 +198,78 @@ func buildPlayletPathURLs(webAddr string, items []idWithTime, prefix string, cha
return urls return urls
} }
// buildPlayletPlayURLs 播放页直接写第一集的规范地址 /play/{slug}/{chapterId}/,
// 避免 /play/{slug}/ 在 h5 再 301 一次;没有可播放剧集的短剧不写入(h5 会返回 404)。
func buildPlayletPlayURLs(webAddr string, items []idWithTime, firstChapter map[int64]int64, changeFreq string, priority float32) []URL {
urls := make([]URL, 0, len(items))
for _, item := range items {
chapterID := firstChapter[item.Id]
if chapterID <= 0 {
continue
}
lastMod := formatLastMod(item.LastMod)
if lastMod == "" {
lastMod = time.Now().Format(time.DateOnly)
}
urls = append(urls, URL{
Loc: utils.JoinUrlPathKeepSlash(webAddr, entityPath("/play", item.Slug, item.Id)+strconv.FormatInt(chapterID, 10)+"/"),
LastMod: lastMod,
ChangeFreq: changeFreq,
Priority: priority,
})
}
return urls
}
// firstPlayletChapterIDs 取每部短剧的第一集 ID,规则与 app 详情接口的选集列表一致
// (按集号、ID 升序;原创剧只算已加水印的剧集),h5 播放页跳转也取这一集。
func firstPlayletChapterIDs(ctx context.Context, items []idWithTime) map[int64]int64 {
result := make(map[int64]int64, len(items))
original := make(map[int64]bool, len(items))
ids := make([]int64, 0, len(items))
for _, item := range items {
if item.Id > 0 {
ids = append(ids, item.Id)
original[item.Id] = item.IsOriginal
}
}
const batch = 500
for start := 0; start < len(ids); start += batch {
end := start + batch
if end > len(ids) {
end = len(ids)
}
list, err := playletchaptermod.FindManyPlayletChapter(ctx, bson.M{
playletchaptermod.FN.PlayletChapter.PlayletId: bson.M{"$in": ids[start:end]},
}, options.Find().
SetSort(bson.D{
{Key: playletchaptermod.FN.PlayletChapter.PlayletId, Value: 1},
{Key: playletchaptermod.FN.PlayletChapter.CurrentEpisode, Value: 1},
{Key: playletchaptermod.FN.PlayletChapter.Id, Value: 1},
}).
SetProjection(bson.M{
playletchaptermod.FN.PlayletChapter.Id: 1,
playletchaptermod.FN.PlayletChapter.PlayletId: 1,
playletchaptermod.FN.PlayletChapter.CurrentEpisode: 1,
playletchaptermod.FN.PlayletChapter.WatermarkVideoUrl: 1,
}))
if err != nil {
log.Error("sitemap 查询短剧第一集失败", log.E(err))
continue
}
for _, ch := range list {
if ch == nil || ch.Id <= 0 || result[ch.PlayletId] > 0 {
continue
}
if original[ch.PlayletId] && ch.WatermarkVideoUrl == "" {
continue
}
result[ch.PlayletId] = ch.Id
}
}
return result
}
func formatLastMod(t time.Time) string { func formatLastMod(t time.Time) string {
if t.IsZero() { if t.IsZero() {
return "" return ""
@@ -226,6 +302,7 @@ func getPlayletList(ctx context.Context) listedPlaylets {
playletmod.FN.Playlet.ThemeIds: 1, playletmod.FN.Playlet.ThemeIds: 1,
playletmod.FN.Playlet.TagIds: 1, playletmod.FN.Playlet.TagIds: 1,
playletmod.FN.Playlet.CategoryIds: 1, playletmod.FN.Playlet.CategoryIds: 1,
playletmod.FN.Playlet.IsOriginal: 1,
})) }))
for _, info := range list { for _, info := range list {
if info == nil || info.Id <= 0 { if info == nil || info.Id <= 0 {
@@ -235,7 +312,7 @@ func getPlayletList(ctx context.Context) listedPlaylets {
if lastMod.IsZero() { if lastMod.IsZero() {
lastMod = info.OnlineAt lastMod = info.OnlineAt
} }
result.items = append(result.items, idWithTime{Id: info.Id, Slug: info.Slug, LastMod: lastMod}) result.items = append(result.items, idWithTime{Id: info.Id, Slug: info.Slug, LastMod: lastMod, IsOriginal: info.IsOriginal})
addListedIDs(result.themeIDs, info.ThemeIds) addListedIDs(result.themeIDs, info.ThemeIds)
addListedIDs(result.tagIDs, info.TagIds) addListedIDs(result.tagIDs, info.TagIds)
addListedIDs(result.categoryIDs, info.CategoryIds) addListedIDs(result.categoryIDs, info.CategoryIds)
+17
View File
@@ -0,0 +1,17 @@
package sitemap
import "testing"
func TestBuildPlayletPlayURLs(t *testing.T) {
items := []idWithTime{
{Id: 12, Slug: "xionnhge"},
{Id: 13, Slug: "nochapter"},
}
urls := buildPlayletPlayURLs("https://hgaidj.net", items, map[int64]int64{12: 27939}, "weekly", 0.6)
if len(urls) != 1 {
t.Fatalf("got %d urls, want 1 (playlet without chapters must be skipped)", len(urls))
}
if urls[0].Loc != "https://hgaidj.net/play/xionnhge/27939/" {
t.Errorf("Loc = %q", urls[0].Loc)
}
}
+14
View File
@@ -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"
@@ -88,6 +92,16 @@ func AppUserTokenKey(userId int64) string {
return fmt.Sprintf(AppUserToken, userId) return fmt.Sprintf(AppUserToken, 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)
}
func MediaM3U8Key(name string) string { func MediaM3U8Key(name string) string {
return fmt.Sprintf(mediaM3U8Fmt, name) return fmt.Sprintf(mediaM3U8Fmt, name)
} }
+13
View File
@@ -113,6 +113,19 @@ func IsSlugAllDigits(s string) bool {
return true return true
} }
// RandomSlugLength 随机 slug 长度
const RandomSlugLength = 8
// MakeRandomSlug 生成唯一的随机 slug(8 位小写字母);exists 返回 true 表示已被占用。
func MakeRandomSlug(exists func(string) bool) string {
for {
s := strings.ToLower(GetRandomLetters(RandomSlugLength))
if !exists(s) {
return s
}
}
}
// MakeUniqueSlug 生成唯一 slug;exists 返回 true 表示已被占用。生成结果不能全是数字。 // MakeUniqueSlug 生成唯一 slug;exists 返回 true 表示已被占用。生成结果不能全是数字。
func MakeUniqueSlug(source string, exists func(string) bool) string { func MakeUniqueSlug(source string, exists func(string) bool) string {
pinyin := GetSlugInfo(source) pinyin := GetSlugInfo(source)
+24
View File
@@ -156,6 +156,30 @@ func QueryMedia(baseInfo *MediaQueryeReq, domain string) (result *VideoQueryResu
return return
} }
func QueryAdvitise(baseInfo *AppAdvitiseInfoReq, domain string) (result *AdvitiseQuerysResult, err error) {
result = &AdvitiseQuerysResult{}
paramJson, err := json.Marshal(baseInfo)
if err != nil {
return
}
if len(domain) == 0 {
domain = DomainAddressRepair(domain, BucketVideoAddressV2)
}
url := domain
if !strings.Contains(domain, "/media/web/app/advitise") {
url = domain + "/media/web/app/advitise"
}
fr, err := http.Post(url, header, bytes.NewReader(paramJson))
if err != nil {
return
}
if err = json.Unmarshal(fr.Data, result); err != nil {
fmt.Println(err)
return nil, err
}
return
}
func QueryMedias(baseInfo *MediaQueryesReq, domain string) (result *VideoQuerysResult, err error) { func QueryMedias(baseInfo *MediaQueryesReq, domain string) (result *VideoQuerysResult, err error) {
result = &VideoQuerysResult{ result = &VideoQuerysResult{
Data: make([]MediaResp, 0), Data: make([]MediaResp, 0),
+28
View File
@@ -1,6 +1,7 @@
package proxy package proxy
import ( import (
"encoding/json"
"strings" "strings"
"time" "time"
"videoweb/pub/models/videoinformationmod" "videoweb/pub/models/videoinformationmod"
@@ -408,6 +409,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"` // 首页列表
+4
View File
@@ -29,6 +29,10 @@ func UploadImage(ctx context.Context, f *multipart.FileHeader, domain string) (p
return proxy.UploadImg(f.Filename, buffer.Bytes(), domain) return proxy.UploadImg(f.Filename, buffer.Bytes(), domain)
} }
func QueryAdvitiseList(ctx context.Context, in *proxy.AppAdvitiseInfoReq, domain string) (*proxy.AdvitiseQuerysResult, error) {
return proxy.QueryAdvitise(in, domain)
}
func QueryMedias(ctx context.Context, in *proxy.MediaQueryesReq, domain string) (*proxy.VideoQuerysResult, error) { func QueryMedias(ctx context.Context, in *proxy.MediaQueryesReq, domain string) (*proxy.VideoQuerysResult, error) {
return proxy.QueryMedias(in, domain) return proxy.QueryMedias(in, domain)
} }
+1 -1
View File
@@ -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
+30 -20
View File
@@ -1,30 +1,40 @@
redis: redis:
addr: 172.104.181.99:16789 addr: 139.162.47.194:6379
db: 2 db: 1
passwd: "B6vJHlYiTseLj77z" passwd: "Redis@fish2026!"
subscribe: true
mongodb: mongodb:
addr: "mongodb://admin:TESTwfeZYP0kjBdy8DAUdwU@172.104.181.99:57017,103.3.61.140:57020,103.3.61.140:57021/web_91av?replicaSet=yctest&maxPoolSize=200&connectTimeout=30&authSource=admin" addr: "mongodb://webhgdj:lQbmsIanlpZAj6au3Nh5gqWN6GV0@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/webhgdj?replicaSet=fish0&maxPoolSize=200&authSource=admin"
logaddr: "mongodb://admin:TESTwfeZYP0kjBdy8DAUdwU@172.104.181.99:57017,103.3.61.140:57020,103.3.61.140:57021/web_91av_log?replicaSet=yctest&maxPoolSize=200&connectTimeout=30&authSource=admin" logaddr: "mongodb://webhgdj:lQbmsIanlpZAj6au3Nh5gqWN6GV0@172.104.52.130:27017,172.104.52.26:27017,172.104.52.242:27017/webhgdj_log?replicaSet=fish0&maxPoolSize=200&authSource=admin"
es: es:
addr: "http://172.104.181.99:9200" addr: "http://139.162.47.194:9200"
user: "elastic" user: "elastic"
pass: "admin123456" pass: "Es@fish2026!"
httpOptions:
dcCtxTimeOut: 10
jwtKey: "2311b15a4da1c80dc541b99abb622233" jwtKey: "2311b15a4da1c80dc541b99abb622233"
tgToken: "" runMod: "prod"
runMod: "dev" resKey: "vEukA&w15z4VAD3kAY#fkL#rBnU!WDhN"
cdnKey: "vEukAw15z4VAD3kAYfkLrBnUWDhN123"
tsAuthKey: "fT5xSg4hltHpzVy6aV9rVECDJ1J1pN" tsAuthKey: "fT5xSg4hltHpzVy6aV9rVECDJ1J1pN"
tgToken: ""
attack:
enable: false
appkey: "kaFtkDJRcchRMTI9"
h5key: "kaFttDJRcahRMTI7"
windowDurationSeconds: 60
pprof: false pprof: false
host: "172.104.181.99" host: "172.104.166.87"
listenAddr: "25120" listenAddr: "20002"
prefetchSubmitUrl: "http://172.104.171.80:9067/master/submit" origDomain: "https://yuan.bbaazz.me/"
aiCenterAppId: 25311 trustedProxies: ""
aiUndressingCallbackUrl: "https://web_mdcomtest-ht.80sygtm.com/api/web/aiorder/strip/callback" bucketVideoAddressV2: "http://139.162.27.29:19996"
upAppId: 8 upAppId: 8
swagger: adCenter:
host: "172.104.181.99" apiDomain: "https://adopenapi.adcs01.top"
user: "mdc" merchantCode: "1991129808640122880"
pass: "2@6A1#9e%9c2" appCode: "JHA-1009"
bucketVideoAddressV2: "http://139.162.22.207:24996" aesKey: "gD4+rmbX5TS5cLbb3wAN5uEAYp/1j4hkQrS9SzuSjc8"
lsjMediaConf: lsjMediaConf:
appId: "430696" appId: "430696"
apiKey: "ed48e96ce490bc94bd5eb5133dd542d0" apiKey: "ed48e96ce490bc94bd5eb5133dd542d0"
@@ -34,7 +44,7 @@ lsjMediaConf:
m3u8Yuan: "https://zhlsaj.zrr4ij4.site" m3u8Yuan: "https://zhlsaj.zrr4ij4.site"
tsYuan: "https://tssdaa.hlvwcn.cn" tsYuan: "https://tssdaa.hlvwcn.cn"
# 媒资配置 # 媒资配置
mediaResourceDBCfg: mediaResourceDBCfg:
baseUrl: "https://mediav2-api.htycpc.com" baseUrl: "https://mediav2-api.htycpc.com"
merchat: "91porn" merchat: "91porn"
+8 -25
View File
@@ -1,28 +1,11 @@
#!/bin/bash #!/bin/bash
FILE_NAME="web_mdcom_web" echo "开始"
REMOTE_FILE_PATH="/home/server2/web_mdcom/web/" rm -rf ./web_huangguo_web ./web_huangguo_web.tar.gz
TAG_NAME="web_mdcom_web.tar.gz" GOOS=linux GOARCH=amd64 go build -o web_huangguo_web
tar zvcf web_huangguo_web.tar.gz web_huangguo_web
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 scp web_huangguo_web.tar.gz root@172.104.166.87:/data/uzip
if [[ ! "yes" =~ $word ]]; then ssh root@172.104.166.87 "/server/web_huangguo/web/up_app.sh"
echo "终止"
else rm -rf ./web_huangguo_web ./web_huangguo_web.tar.gz
read -e -p "本次更新内容(输入q退出编辑): " -r content
echo "开始"
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
GOOS=linux GOARCH=amd64 go build -o $FILE_NAME
md5sum $FILE_NAME | cut -d ' ' -f1 >yinsemd5.txt
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 -i ~/.ssh/id_rsa -P 22889 ./$TAG_NAME server2@116.212.120.2:$REMOTE_FILE_PATH
send_msg -4791758991 #服务器小组
fi
rm -rf ./$FILE_NAME ./$TAG_NAME ./yinsemd5.txt
-11
View File
@@ -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
+1 -2
View File
@@ -1276,8 +1276,7 @@ func ensureImportedPlayletSlug(ctx context.Context, playlet *playletmod.Playlet)
if playlet == nil { if playlet == nil {
return srvdef.New(srvdef.ErrParamError, "短剧数据为空", "") return srvdef.New(srvdef.ErrParamError, "短剧数据为空", "")
} }
source := utils.SlugSourceFromKeywordsOrTitle(playlet.SeoInfo.Keyworld, playlet.Title) playlet.Slug = utils.MakeRandomSlug(func(slug string) bool {
playlet.Slug = utils.MakeUniqueSlug(source, func(slug string) bool {
exist, _ := playletmod.FindOnePlaylet(ctx, bson.M{ exist, _ := playletmod.FindOnePlaylet(ctx, bson.M{
playletmod.FN.Playlet.Slug: slug, playletmod.FN.Playlet.Slug: slug,
}) })
+3 -30
View File
@@ -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
} }
+4 -24
View File
@@ -48,8 +48,7 @@ func ensureThemeSlug(ctx context.Context, ac *playletthememod.PlayletTheme, excl
} }
return nil return nil
} }
source := utils.SlugSourceFromKeywordsOrTitle(ac.SeoInfo.Keyworld, ac.Name) ac.Slug = utils.MakeRandomSlug(func(slug string) bool {
ac.Slug = utils.MakeUniqueSlug(source, func(slug string) bool {
filter := bson.M{playletthememod.FN.PlayletTheme.Slug: slug} filter := bson.M{playletthememod.FN.PlayletTheme.Slug: slug}
if excludeId > 0 { if excludeId > 0 {
filter[playletthememod.FN.PlayletTheme.Id] = bson.M{"$ne": excludeId} filter[playletthememod.FN.PlayletTheme.Id] = bson.M{"$ne": excludeId}
@@ -81,16 +80,7 @@ func prepareThemeSlugOnUpdate(ctx context.Context, id int64, info *playletthemem
} }
return nil return nil
} }
name := info.Name newSlug := utils.MakeRandomSlug(func(s string) bool {
if req.Name != nil {
name = strings.TrimSpace(*req.Name)
}
keywords := info.SeoInfo.Keyworld
if req.SeoInfo != nil {
keywords = normalizeSeoValue(*req.SeoInfo).Keyworld
}
source := utils.SlugSourceFromKeywordsOrTitle(keywords, name)
newSlug := utils.MakeUniqueSlug(source, func(s string) bool {
exist, _ := playletthememod.FindOnePlayletTheme(ctx, bson.M{ exist, _ := playletthememod.FindOnePlayletTheme(ctx, bson.M{
playletthememod.FN.PlayletTheme.Slug: s, playletthememod.FN.PlayletTheme.Slug: s,
playletthememod.FN.PlayletTheme.Id: bson.M{"$ne": id}, playletthememod.FN.PlayletTheme.Id: bson.M{"$ne": id},
@@ -186,8 +176,7 @@ func ensurePlayletSlug(ctx context.Context, ac *playletmod.Playlet, excludeId in
} }
return nil return nil
} }
source := utils.SlugSourceFromKeywordsOrTitle(ac.SeoInfo.Keyworld, ac.Title) ac.Slug = utils.MakeRandomSlug(func(slug string) bool {
ac.Slug = utils.MakeUniqueSlug(source, func(slug string) bool {
filter := bson.M{playletmod.FN.Playlet.Slug: slug} filter := bson.M{playletmod.FN.Playlet.Slug: slug}
if excludeId > 0 { if excludeId > 0 {
filter[playletmod.FN.Playlet.Id] = bson.M{"$ne": excludeId} filter[playletmod.FN.Playlet.Id] = bson.M{"$ne": excludeId}
@@ -219,16 +208,7 @@ func preparePlayletSlugOnUpdate(ctx context.Context, id int64, info *playletmod.
} }
return nil return nil
} }
title := info.Title newSlug := utils.MakeRandomSlug(func(s string) bool {
if req.Title != nil {
title = strings.TrimSpace(*req.Title)
}
keywords := info.SeoInfo.Keyworld
if req.SeoInfo != nil {
keywords = normalizeSeoValue(*req.SeoInfo).Keyworld
}
source := utils.SlugSourceFromKeywordsOrTitle(keywords, title)
newSlug := utils.MakeUniqueSlug(source, func(s string) bool {
exist, _ := playletmod.FindOnePlaylet(ctx, bson.M{ exist, _ := playletmod.FindOnePlaylet(ctx, bson.M{
playletmod.FN.Playlet.Slug: s, playletmod.FN.Playlet.Slug: s,
playletmod.FN.Playlet.Id: bson.M{"$ne": id}, playletmod.FN.Playlet.Id: bson.M{"$ne": id},