@@ -0,0 +1,291 @@
|
||||
package mdrsdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/httputil"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/web/webg"
|
||||
)
|
||||
|
||||
type findMediaListReq struct {
|
||||
IDs string `json:"ids"`
|
||||
ProId string `json:"pro_id"`
|
||||
Type string `json:"type"`
|
||||
Page string `json:"page"`
|
||||
Size string `json:"size"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Sign string `json:"sign"`
|
||||
MediaType string `json:"filter[media_type],omitempty"` // 媒体类型 0视频 1图文
|
||||
Title string `json:"filter[title],omitempty"`
|
||||
TerminalCdo string `json:"filter[terminal_cdo],omitempty"`
|
||||
TagText string `json:"filter[tags_text],omitempty"`
|
||||
HashId string `json:"filter[hash_id],omitempty"`
|
||||
VloggerId string `json:"filter[vlogger_id],omitempty"`
|
||||
VloggerUserId string `json:"filter[vlogger_user_id],omitempty"`
|
||||
StartTime string `json:"filter[start_time],omitempty"`
|
||||
EndTime string `json:"filter[end_time],omitempty"`
|
||||
SortType string `json:"sort_type" form:"sort_type"` // 0-id倒序 1-id正序
|
||||
MaxTotal string `json:"max_total" form:"max_total"` // 最大列表总数
|
||||
}
|
||||
|
||||
func (f *findMediaListReq) getParam() interface{} {
|
||||
f.Sign = sign(*f)
|
||||
m := make(map[string]string)
|
||||
b, err := json.Marshal(f)
|
||||
if err != nil {
|
||||
return m
|
||||
}
|
||||
_ = json.Unmarshal(b, &m)
|
||||
return m
|
||||
}
|
||||
|
||||
func FindMediaList(ctx context.Context, pageNumber, pageSize, vloggerUserId int64, title, tagText, hashId string, mVia, videoType int, syncType, terminalCdo string, startTime, endTime time.Time, sortType, maxTotal int) (mslist []MediaResource, count int64, err error) {
|
||||
var msgData struct {
|
||||
Data []MediaResource `json:"data"`
|
||||
Pagination Pagination `json:"pagination"`
|
||||
}
|
||||
var retMsg msg
|
||||
var errlog string
|
||||
mt := ""
|
||||
if videoType == 0 {
|
||||
mt = "0"
|
||||
} else if videoType == 2 {
|
||||
mt = "1"
|
||||
}
|
||||
var req = findMediaListReq{
|
||||
ProId: getMerchat(),
|
||||
Type: syncType,
|
||||
Page: strconv.FormatInt(pageNumber, 10),
|
||||
Size: strconv.FormatInt(pageSize, 10),
|
||||
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
HashId: hashId,
|
||||
Title: title,
|
||||
TerminalCdo: terminalCdo,
|
||||
TagText: tagText,
|
||||
MediaType: mt,
|
||||
SortType: strconv.Itoa(sortType),
|
||||
MaxTotal: strconv.Itoa(maxTotal),
|
||||
StartTime: strconv.FormatInt(startTime.Unix(), 10),
|
||||
EndTime: strconv.FormatInt(endTime.Unix(), 10),
|
||||
}
|
||||
if vloggerUserId > 0 {
|
||||
req.VloggerUserId = strconv.FormatInt(vloggerUserId, 10)
|
||||
}
|
||||
switch mVia {
|
||||
case 0:
|
||||
case 1:
|
||||
req.VloggerId = "1,"
|
||||
case 2:
|
||||
req.VloggerId = "0"
|
||||
}
|
||||
var url string
|
||||
if videoType == 0 || videoType == 2 {
|
||||
url = "/services/video/videos/v2"
|
||||
} else {
|
||||
url = "/services/short_video/videos/v2"
|
||||
}
|
||||
code, err := httputil.DefaultClientGetWithResp(&retMsg, common.BindUrl(getOrignUrl(), url), nil, req.getParam())
|
||||
if err != nil {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http GetWithJResp error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
if code != 200 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http code error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
if retMsg.Code != 0 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList retmsg code error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
b, err := json.Marshal(retMsg.Data)
|
||||
if err != nil {
|
||||
errlog := fmt.Sprintf("meadia resource FindMediaList Marshal fail \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(b, &msgData); err != nil {
|
||||
errlog := fmt.Sprintf("meadia resource FindMediaList Unmarshal fail \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
mslist = msgData.Data
|
||||
count = msgData.Pagination.Count
|
||||
return
|
||||
}
|
||||
|
||||
func FindMediaListWithIDs(ctx context.Context, ids []int64, videoType int) (mslist []MediaResource, err error) {
|
||||
var msgData struct {
|
||||
Data []MediaResource `json:"data"`
|
||||
Pagination Pagination `json:"pagination"`
|
||||
}
|
||||
var retMsg msg
|
||||
var errlog string
|
||||
var req = findMediaListReq{
|
||||
ProId: getMerchat(),
|
||||
Type: "all",
|
||||
IDs: sliCovertStr(ids),
|
||||
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
Size: strconv.Itoa(len(ids)),
|
||||
Page: "1",
|
||||
}
|
||||
var url string
|
||||
if videoType == 0 || videoType == 2 {
|
||||
url = "/services/video/videos"
|
||||
} else {
|
||||
url = "/services/short_video/videos"
|
||||
}
|
||||
code, err := httputil.DefaultClientGetWithResp(&retMsg, common.BindUrl(getOrignUrl(), url), nil, req.getParam())
|
||||
if err != nil {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http GetWithJResp error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
if code != 200 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http code error \nerror:%+v;code:%v", err, code)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
if retMsg.Code != 0 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList retmsg code error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
b, err := json.Marshal(retMsg.Data)
|
||||
if err != nil {
|
||||
errlog := fmt.Sprintf("meadia resource FindMediaList Marshal fail \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(b, &msgData); err != nil {
|
||||
errlog := fmt.Sprintf("meadia resource FindMediaList Unmarshal fail \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
err = errors.New(errlog)
|
||||
return
|
||||
}
|
||||
mslist = msgData.Data
|
||||
return
|
||||
}
|
||||
|
||||
type useMediaReq struct {
|
||||
IDs string `json:"ids"`
|
||||
ProId string `json:"pro_id"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
func (this *useMediaReq) getParam() interface{} {
|
||||
this.Sign = sign(*this)
|
||||
b, _ := json.Marshal(this)
|
||||
return b
|
||||
}
|
||||
|
||||
func UseMedia(ctx context.Context, ids []int64, videoType int) error {
|
||||
var retMsg msg
|
||||
var errlog string
|
||||
var p = useMediaReq{
|
||||
ProId: getMerchat(),
|
||||
IDs: sliCovertStr(ids),
|
||||
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
var url string
|
||||
if videoType == 0 || videoType == 2 {
|
||||
url = "/services/video/used"
|
||||
} else {
|
||||
url = "/services/short_video/used"
|
||||
}
|
||||
fmt.Println("-------url", getOrignUrl()+url)
|
||||
code, err := httputil.DefaultClientPostJsonWithResp(&retMsg, common.BindUrl(getOrignUrl(), url), nil, p.getParam())
|
||||
if err != nil {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http POSTJsonWithJResp error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
return errors.New(errlog)
|
||||
}
|
||||
if code != 200 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http code error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
return errors.New(errlog)
|
||||
}
|
||||
if retMsg.Code != 0 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList retmsg code error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
return errors.New(errlog)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ignoreMediaReq struct {
|
||||
IDs string `json:"ids"`
|
||||
ProId string `json:"pro_id"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
func (this *ignoreMediaReq) getParam() interface{} {
|
||||
this.Sign = sign(*this)
|
||||
b, _ := json.Marshal(this)
|
||||
return b
|
||||
}
|
||||
|
||||
func IgnoreMedia(ctx context.Context, ids []int64, videoType int) error {
|
||||
var retMsg msg
|
||||
var errlog string
|
||||
var p = ignoreMediaReq{
|
||||
ProId: getMerchat(),
|
||||
IDs: sliCovertStr(ids),
|
||||
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
var url string
|
||||
if videoType == 0 || videoType == 2 {
|
||||
url = "/services/video/ignored"
|
||||
} else {
|
||||
url = "/services/short_video/ignored"
|
||||
}
|
||||
code, err := httputil.DefaultClientPostJsonWithResp(&retMsg, common.BindUrl(getOrignUrl(), url), nil, p.getParam())
|
||||
if err != nil {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http POSTJsonWithJResp error \nerror:%+v;", err)
|
||||
log.Error(errlog)
|
||||
return errors.New(errlog)
|
||||
}
|
||||
if code != 200 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList http code error \nerror:%+v;code %d", err, code)
|
||||
log.Error(errlog)
|
||||
return errors.New(errlog)
|
||||
}
|
||||
if retMsg.Code != 0 {
|
||||
errlog = fmt.Sprintf("meadia resource FindMediaList retmsg code error \nerror:%+v;res:%+v", err, retMsg)
|
||||
log.Error(errlog)
|
||||
return errors.New(errlog)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getMerchat() string {
|
||||
return webg.Conf.MediaResourceDBCfg.Merchat
|
||||
}
|
||||
|
||||
func getSecret() string {
|
||||
return webg.Conf.MediaResourceDBCfg.Secret
|
||||
}
|
||||
|
||||
func getOrignUrl() string {
|
||||
return webg.Conf.MediaResourceDBCfg.BaseUrl
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package mdrsdb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type MediaResource struct {
|
||||
Id int64 `json:"id"`
|
||||
HashId string `json:"hash_id"`
|
||||
// SetsId int `json:"sets_id"`
|
||||
// Episode int `json:"episode"`
|
||||
MediaType int `json:"media_type"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
VerticalCover string `json:"vertical_cover"`
|
||||
CoverImage string `json:"cover_image"`
|
||||
CoverGif string `json:"cover_gif"`
|
||||
Pics string `json:"pics"`
|
||||
Gifs string `json:"gifs"`
|
||||
Src480 string `json:"src_480"`
|
||||
Src720 string `json:"src_720"`
|
||||
Src1080 string `json:"src_1080"`
|
||||
FileSize480 int64 `json:"file_size_480"`
|
||||
FileSize720 int64 `json:"file_size_720"`
|
||||
FileSize1080 int64 `json:"file_size_1080"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Length uint `json:"length"`
|
||||
PreviewSrc string `json:"preview_src"`
|
||||
PreviewLength int `json:"pre view_length"`
|
||||
// IsVertical int `json:"is_vertical"`
|
||||
Tags string `json:"tags"`
|
||||
Points string `json:"points"`
|
||||
// QualityScore int `json:"quality_score"`
|
||||
// IsHighQuality int `json:"is_high_quality"`
|
||||
LastHeatTime interface{} `json:"last_heat_time"`
|
||||
Status int `json:"status"`
|
||||
// CreateTime string `json:"create_time"`
|
||||
// UpdateTime string `json:"update_time"`
|
||||
EditBy string `json:"edit_by"`
|
||||
TerminalCdo string `json:"terminal_cdo"`
|
||||
Used int64 `json:"used"`
|
||||
Short []interface{} `json:"short"`
|
||||
TagsText string `json:"tags_text"`
|
||||
PointsText string `json:"points_text"`
|
||||
VloggerUserId uint64 `json:"vlogger_user_id"` //up主
|
||||
TagList []string `json:"tagList"` //tag列表
|
||||
SaleCoin int64 `json:"sale_coin"` //售卖金币
|
||||
RichText string `json:"rich_text"` // 富文本内容
|
||||
PreviewStart int `json:"preview_start"`
|
||||
}
|
||||
|
||||
type Pagination struct {
|
||||
IsLastPage int `json:"isPastPage"`
|
||||
Page int `json:"page"`
|
||||
Size int `json:"size"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
type msg struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func sign(p interface{}) string {
|
||||
m := make(map[string]interface{})
|
||||
rawData, _ := json.Marshal(p)
|
||||
_ = json.Unmarshal(rawData, &m)
|
||||
keyStrSli := make([]string, 0)
|
||||
for k := range m {
|
||||
if k == "sign" || m[k] == "" {
|
||||
continue
|
||||
}
|
||||
keyStrSli = append(keyStrSli, k)
|
||||
}
|
||||
sort.Strings(keyStrSli)
|
||||
var buf bytes.Buffer
|
||||
for k := range keyStrSli {
|
||||
buf.WriteString(keyStrSli[k])
|
||||
buf.WriteString("=")
|
||||
buf.WriteString(allToString(m[keyStrSli[k]]))
|
||||
buf.WriteString("&")
|
||||
}
|
||||
buf.WriteString("secret=" + getSecret())
|
||||
s := buf.String()
|
||||
md5Str := strings.ToUpper(md5Sign(s))
|
||||
return md5Str
|
||||
}
|
||||
|
||||
// md5签名
|
||||
func md5Sign(buf string) string {
|
||||
md5Ctx := md5.New()
|
||||
md5Ctx.Write([]byte(buf))
|
||||
cipherStr := md5Ctx.Sum(nil)
|
||||
nsign := hex.EncodeToString(cipherStr)
|
||||
return nsign
|
||||
}
|
||||
|
||||
func allToString(p interface{}) string {
|
||||
switch p := p.(type) {
|
||||
case int, int64:
|
||||
return strconv.FormatInt(p.(int64), 10)
|
||||
case float32, float64:
|
||||
return strconv.FormatFloat(p.(float64), 'f', 2, 64)
|
||||
case string:
|
||||
return p
|
||||
default:
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func sliCovertStr(in []int64) string {
|
||||
var buf bytes.Buffer
|
||||
for i := range in {
|
||||
if i > 0 {
|
||||
buf.WriteString(",")
|
||||
}
|
||||
buf.WriteString(strconv.FormatInt(in[i], 10))
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
Reference in New Issue
Block a user