506 lines
15 KiB
Go
506 lines
15 KiB
Go
|
|
package req
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"encoding/json"
|
|||
|
|
"strings"
|
|||
|
|
"time"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// 指令参数
|
|||
|
|
// 自动抢红包 101
|
|||
|
|
type AutoRedRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启领取红包机制
|
|||
|
|
Single int32 `example:"1"` // 是否仅抢单个红包(不同时抢多个)
|
|||
|
|
AutoReply int32 `example:"1"` // 是否自动回复感谢
|
|||
|
|
TimeInSeconds int32 `example:"0"` // 延迟回复的时间,单位为秒
|
|||
|
|
ReplyMessages string // 回复内容(多个消息用逗号隔开)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealAutoRed(model *AutoRedRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
if model.Single != 1 {
|
|||
|
|
model.Single = 0
|
|||
|
|
}
|
|||
|
|
if model.AutoReply != 1 {
|
|||
|
|
model.AutoReply = 0
|
|||
|
|
}
|
|||
|
|
// TimeInSeconds 0-60
|
|||
|
|
if model.TimeInSeconds < 0 {
|
|||
|
|
model.TimeInSeconds = 0
|
|||
|
|
} else if model.TimeInSeconds > 60 {
|
|||
|
|
model.TimeInSeconds = 60
|
|||
|
|
}
|
|||
|
|
_, model.ReplyMessages = StringToSlice(model.ReplyMessages)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 自动接收转账 106
|
|||
|
|
type AutoTransferRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启接收转账功能
|
|||
|
|
AutoReply int32 `example:"1"` // 是否开启自动回复
|
|||
|
|
TimeInSeconds int32 `example:"0"` // 延迟回复的时间,单位为秒
|
|||
|
|
ReplyMessage string // 回复内容(仅一条)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealTransfer(model *AutoTransferRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
if model.AutoReply != 1 {
|
|||
|
|
model.AutoReply = 0
|
|||
|
|
}
|
|||
|
|
// TimeInSeconds 0-60
|
|||
|
|
if model.TimeInSeconds < 0 {
|
|||
|
|
model.TimeInSeconds = 0
|
|||
|
|
} else if model.TimeInSeconds > 60 {
|
|||
|
|
model.TimeInSeconds = 60
|
|||
|
|
}
|
|||
|
|
model.ReplyMessage = StringTo1000(model.ReplyMessage)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 延迟领取红包 103
|
|||
|
|
type DelayRedRequestModel struct {
|
|||
|
|
TimeInSeconds int32 `example:"0"` // 延迟领取红包的时间,单位为秒
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealDelayRed(model *DelayRedRequestModel) {
|
|||
|
|
// TimeInSeconds 0-60
|
|||
|
|
if model.TimeInSeconds < 0 {
|
|||
|
|
model.TimeInSeconds = 0
|
|||
|
|
} else if model.TimeInSeconds > 60 {
|
|||
|
|
model.TimeInSeconds = 60
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 延迟接收转账 113
|
|||
|
|
type DelayAutoTransferRequestModel struct {
|
|||
|
|
TimeInSeconds int32 `example:"0"` // 延迟接收转账的时间,单位为秒
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealDelayTransfer(model *DelayAutoTransferRequestModel) {
|
|||
|
|
// TimeInSeconds 0-60
|
|||
|
|
if model.TimeInSeconds < 0 {
|
|||
|
|
model.TimeInSeconds = 0
|
|||
|
|
} else if model.TimeInSeconds > 60 {
|
|||
|
|
model.TimeInSeconds = 60
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 关键字包不抢 118
|
|||
|
|
type KeywordAvoidanceRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启关键字包不抢
|
|||
|
|
Keywords string // 设置关键字(多个用逗号隔开)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealKeywordAvoidance(model *KeywordAvoidanceRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
_, model.Keywords = StringToSlice(model.Keywords)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 自动点赞 401
|
|||
|
|
type AutoLikeRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启自动点赞
|
|||
|
|
StartTime string // 开始时间 // 点赞时间段
|
|||
|
|
EndTime string // 结束时间// 点赞时间段
|
|||
|
|
TimeInSeconds int32 `example:"0"` // 延迟点赞的时间,单位为秒
|
|||
|
|
Mode int32 `example:"1"` // 模式,1-仅点赞分组,0-不点赞分组
|
|||
|
|
Groups string // 设置分组,多个用逗号隔开
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealAutoLike(model *AutoLikeRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
// TimeInSeconds 0-60
|
|||
|
|
if model.TimeInSeconds < 0 {
|
|||
|
|
model.TimeInSeconds = 0
|
|||
|
|
} else if model.TimeInSeconds > 60 {
|
|||
|
|
model.TimeInSeconds = 60
|
|||
|
|
}
|
|||
|
|
if model.Mode != 1 {
|
|||
|
|
model.Mode = 0
|
|||
|
|
}
|
|||
|
|
_, model.Groups = StringToSlice(model.Groups)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 朋友圈跟随转发 402
|
|||
|
|
type AutoForwardRequestModel struct {
|
|||
|
|
EnableAutoForward int32 `example:"1"` // 是否开启跟随转发
|
|||
|
|
IsBlockAuthor int32 `example:"1"` // 是否屏蔽作者
|
|||
|
|
IsBlockGroup int32 `example:"1"` // 是否屏蔽组
|
|||
|
|
Groups string // 设置分组,多个用逗号隔开
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealAutoForward(model *AutoForwardRequestModel) {
|
|||
|
|
if model.EnableAutoForward != 1 {
|
|||
|
|
model.EnableAutoForward = 0
|
|||
|
|
}
|
|||
|
|
if model.IsBlockAuthor != 1 {
|
|||
|
|
model.IsBlockAuthor = 0
|
|||
|
|
}
|
|||
|
|
if model.IsBlockGroup != 1 {
|
|||
|
|
model.IsBlockGroup = 0
|
|||
|
|
}
|
|||
|
|
_, model.Groups = StringToSlice(model.Groups)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 朋友圈收藏转发 403
|
|||
|
|
type FavoriteForwardRequestModel struct {
|
|||
|
|
EnableFavoriteForward int32 `example:"1"` // 是否开启收藏转发
|
|||
|
|
IsBlockAuthor int32 `example:"1"` // 是否屏蔽作者
|
|||
|
|
IsBlockGroup int32 `example:"1"` // 是否屏蔽组
|
|||
|
|
Groups string // 设置分组,多个用逗号隔开
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealFavoriteForward(model *FavoriteForwardRequestModel) {
|
|||
|
|
if model.EnableFavoriteForward != 1 {
|
|||
|
|
model.EnableFavoriteForward = 0
|
|||
|
|
}
|
|||
|
|
if model.IsBlockAuthor != 1 {
|
|||
|
|
model.IsBlockAuthor = 0
|
|||
|
|
}
|
|||
|
|
if model.IsBlockGroup != 1 {
|
|||
|
|
model.IsBlockGroup = 0
|
|||
|
|
}
|
|||
|
|
_, model.Groups = StringToSlice(model.Groups)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 朋友圈自动评论 404
|
|||
|
|
type AutoCommentRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启自动评论
|
|||
|
|
CommentMessages string // 评论内容(多条用逗号隔开)
|
|||
|
|
StartTime string // 评论时间段,开始时间
|
|||
|
|
EndTime string // 评论时间段,结束时间
|
|||
|
|
TimeInSeconds int32 `example:"0"` // 延迟评论的时间,单位为秒
|
|||
|
|
Mode int32 `example:"1"` // 模式,1-仅评论分组,0-不评论分组
|
|||
|
|
Groups string // 设置分组,多个用逗号隔开
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealAutoComment(model *AutoCommentRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
_, model.CommentMessages = StringToSlice(model.CommentMessages)
|
|||
|
|
// TimeInSeconds 0-60
|
|||
|
|
if model.TimeInSeconds < 0 {
|
|||
|
|
model.TimeInSeconds = 0
|
|||
|
|
} else if model.TimeInSeconds > 60 {
|
|||
|
|
model.TimeInSeconds = 60
|
|||
|
|
}
|
|||
|
|
if model.Mode != 1 {
|
|||
|
|
model.Mode = 0
|
|||
|
|
}
|
|||
|
|
_, model.Groups = StringToSlice(model.Groups)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 定时发朋友圈 405
|
|||
|
|
type MomentsRequestModel struct {
|
|||
|
|
MomentType int32 `example:"1"` // 发圈类型,1-文字,3-图片
|
|||
|
|
MomentContent string // 朋友圈内容
|
|||
|
|
MomentImages string // 朋友圈图片(最多上传9张,图片路径或链接用逗号隔开)
|
|||
|
|
IsBlock int32 `example:"1"` // 发圈时屏蔽组
|
|||
|
|
Groups string // 设置分组,多个用逗号隔开
|
|||
|
|
ScheduledTime string // 预约发圈时间
|
|||
|
|
Status int32 `example:"0"` // 状态,0-未发布,1-已发布,-1-发布失败
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealMoments(model *MomentsRequestModel) {
|
|||
|
|
// MomentType must be either 1 or 3
|
|||
|
|
if model.MomentType != 3 {
|
|||
|
|
model.MomentType = 1 // Default to 1 if invalid
|
|||
|
|
}
|
|||
|
|
model.MomentContent = StringTo1000(model.MomentContent)
|
|||
|
|
_, model.MomentImages = StringToSlice(model.MomentImages)
|
|||
|
|
if model.IsBlock != 1 {
|
|||
|
|
model.IsBlock = 0
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
_, model.Groups = StringToSlice(model.Groups)
|
|||
|
|
// Status can remain as is since it is already initialized
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 发大视频朋友圈 406
|
|||
|
|
type MomentsPostRequestModel struct {
|
|||
|
|
Content string // 朋友圈内容
|
|||
|
|
VideoURL string // 视频,最大500M(最多上传1个)
|
|||
|
|
IsBlock int32 `example:"1"` // 发圈时屏蔽组
|
|||
|
|
Groups string // 设置分组,多个用逗号隔开
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealMomentsPost(model *MomentsPostRequestModel) {
|
|||
|
|
model.Content = StringTo1000(model.Content)
|
|||
|
|
model.VideoURL = StringTo1000(model.VideoURL)
|
|||
|
|
if model.IsBlock != 1 {
|
|||
|
|
model.IsBlock = 0
|
|||
|
|
}
|
|||
|
|
_, model.Groups = StringToSlice(model.Groups)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 欢迎新人入群 502
|
|||
|
|
type WelcomeNewMemberRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启欢迎新人入群
|
|||
|
|
WelcomeMsg string // 欢迎语内容(仅一条)
|
|||
|
|
Mode int32 `example:"1"` // 模式,1-仅欢迎设置群,0-不欢迎设置群
|
|||
|
|
Rooms string // 设置的群
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealWelcomeNewMember(model *WelcomeNewMemberRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
model.WelcomeMsg = StringTo1000(model.WelcomeMsg)
|
|||
|
|
if model.Mode != 1 {
|
|||
|
|
model.Mode = 0
|
|||
|
|
}
|
|||
|
|
_, model.Rooms = StringToSlice(model.Rooms)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 关键词自动踢人 503
|
|||
|
|
type KeywordKickRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启关键词踢人
|
|||
|
|
Keywords string // 触发的关键词(多条用逗号分隔)
|
|||
|
|
IsLinkKick int32 `example:"1"` // 是否踢发链接的人
|
|||
|
|
IsCardKick int32 `example:"1"` // 是否踢发名片的人
|
|||
|
|
IsMiniProgramKick int32 `example:"1"` // 是否踢发小程序的人
|
|||
|
|
IsImageQRCodeKick int32 `example:"1"` // 是否踢发图片二维码的人
|
|||
|
|
Mode int32 `example:"1"` // 模式,1-仅踢设置群,0-不踢设置群
|
|||
|
|
Rooms string // 设置的群
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealKeywordKick(model *KeywordKickRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
_, model.Keywords = StringToSlice(model.Keywords)
|
|||
|
|
if model.IsLinkKick != 1 {
|
|||
|
|
model.IsLinkKick = 0
|
|||
|
|
}
|
|||
|
|
if model.IsCardKick != 1 {
|
|||
|
|
model.IsCardKick = 0
|
|||
|
|
}
|
|||
|
|
if model.IsMiniProgramKick != 1 {
|
|||
|
|
model.IsMiniProgramKick = 0
|
|||
|
|
}
|
|||
|
|
if model.IsImageQRCodeKick != 1 {
|
|||
|
|
model.IsImageQRCodeKick = 0
|
|||
|
|
}
|
|||
|
|
if model.Mode != 1 {
|
|||
|
|
model.Mode = 0
|
|||
|
|
}
|
|||
|
|
_, model.Rooms = StringToSlice(model.Rooms)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 关键词自动回复 504
|
|||
|
|
type ReplyKeywordsItem struct {
|
|||
|
|
Keyword string // 触发的关键词
|
|||
|
|
Content string // 回复的内容
|
|||
|
|
NewMsgId string // 新消息ID 引用了文件助手某条消息时用这个字段
|
|||
|
|
MsgType int32 // 收到消息时的类型:1-文本 3-图片 24-笔记 33-小程序 42-名片 49-链接
|
|||
|
|
SendType int32 // 回复的类型,发送类型 1-文本 3-图片 49-笔记|链接 2002-小程序 42-名片
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
type KeywordAutoReplyRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启关键词自动回复
|
|||
|
|
PrivateReply int32 `example:"1"` // 是否回复私聊
|
|||
|
|
Mode int32 `example:"1"` // 模式,1-仅回复设置群,0-不回复设置群
|
|||
|
|
Rooms string // 设置的群
|
|||
|
|
Keywords []ReplyKeywordsItem // 关键词设置
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealKeywordAutoReply(model *KeywordAutoReplyRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
if model.PrivateReply != 1 {
|
|||
|
|
model.PrivateReply = 0
|
|||
|
|
}
|
|||
|
|
if model.Mode != 1 {
|
|||
|
|
model.Mode = 0
|
|||
|
|
}
|
|||
|
|
_, model.Rooms = StringToSlice(model.Rooms)
|
|||
|
|
|
|||
|
|
for i := range model.Keywords {
|
|||
|
|
model.Keywords[i].Keyword = StringTo1000(model.Keywords[i].Keyword)
|
|||
|
|
model.Keywords[i].Content = StringTo1000(model.Keywords[i].Content)
|
|||
|
|
// MsgType and SendType are assumed to be validated outside this function
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 万群同步 505
|
|||
|
|
type MessageForwardingRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启消息转发
|
|||
|
|
MainRoom string // 设置的主讲群
|
|||
|
|
Lecturers string // 添加的讲师
|
|||
|
|
ForwardRooms string // 设置的转发群
|
|||
|
|
StartTime string // 转发时间段,开始时间
|
|||
|
|
EndTime string // 转发时间段,结束时间
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealMessageForwarding(model *MessageForwardingRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
model.MainRoom = StringTo1000(model.MainRoom)
|
|||
|
|
model.Lecturers = StringTo1000(model.Lecturers)
|
|||
|
|
_, model.ForwardRooms = StringToSlice(model.ForwardRooms)
|
|||
|
|
// StartTime and EndTime are assumed to be valid formats validated outside this function
|
|||
|
|
startTime, endTime := DealTimeRange(model.StartTime, model.EndTime)
|
|||
|
|
model.StartTime = startTime
|
|||
|
|
model.EndTime = endTime
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 自动通过好友 801
|
|||
|
|
type AutoApproveRequestModel struct {
|
|||
|
|
Enable int32 `example:"1"` // 是否开启自动通过验证
|
|||
|
|
AutoReply int32 `example:"1"` // 是否通过验证后自动回复
|
|||
|
|
ReplyMessage string // 回复内容(仅一条)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func DealAutoApprove(model *AutoApproveRequestModel) {
|
|||
|
|
if model.Enable != 1 {
|
|||
|
|
model.Enable = 0
|
|||
|
|
}
|
|||
|
|
if model.AutoReply != 1 {
|
|||
|
|
model.AutoReply = 0
|
|||
|
|
}
|
|||
|
|
model.ReplyMessage = StringTo1000(model.ReplyMessage)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 中文逗号转为英文逗号,清理换行符,过滤空字符串,返回字符串数组和字符串表示
|
|||
|
|
func StringToSlice(str string) ([]string, string) {
|
|||
|
|
// 清理换行符(包括 \n 和 \r)
|
|||
|
|
str = strings.ReplaceAll(str, "\r", "")
|
|||
|
|
|
|||
|
|
// 回车符转成分隔付(逗号)
|
|||
|
|
str = strings.ReplaceAll(str, "\n", ",")
|
|||
|
|
|
|||
|
|
// 将中文逗号替换为英文逗号
|
|||
|
|
str = strings.ReplaceAll(str, ",", ",")
|
|||
|
|
|
|||
|
|
// 按英文逗号分割成字符串数组
|
|||
|
|
strArr := strings.Split(str, ",")
|
|||
|
|
var result []string
|
|||
|
|
var finalString string = ""
|
|||
|
|
|
|||
|
|
// 过滤掉空字符串,清理头尾空格
|
|||
|
|
for _, v := range strArr {
|
|||
|
|
v = strings.TrimSpace(v) // 去掉前后空格
|
|||
|
|
if v != "" {
|
|||
|
|
// 判断不能大于 1000 个字符
|
|||
|
|
if len(finalString+","+v) > 1000 {
|
|||
|
|
continue
|
|||
|
|
}
|
|||
|
|
if finalString != "" {
|
|||
|
|
finalString += ","
|
|||
|
|
}
|
|||
|
|
finalString += v
|
|||
|
|
result = append(result, v)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 将数组转成字符串格式
|
|||
|
|
// finalString := strings.Join(result, ",")
|
|||
|
|
|
|||
|
|
// 返回字符串数组和字符串
|
|||
|
|
return result, finalString
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 判断字符串不能大于 1000 个字符,大于则截取前 1000 个字符
|
|||
|
|
func StringTo1000(str string) string {
|
|||
|
|
str = strings.TrimSpace(str) // 去掉前后空格
|
|||
|
|
// 只取 前 1000 个字符
|
|||
|
|
if len(str) > 1000 {
|
|||
|
|
str = str[:1000]
|
|||
|
|
}
|
|||
|
|
return str
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 处理开始时间和结束时间,如果输入格式不正确,则使用默认值
|
|||
|
|
func DealTimeRange(startTime string, endTime string) (string, string) {
|
|||
|
|
const timeFormat = "15:04"
|
|||
|
|
// 解析 StartTime
|
|||
|
|
start, errStart := time.Parse(timeFormat, startTime)
|
|||
|
|
if errStart != nil {
|
|||
|
|
start = time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC) // 设置为 00:00
|
|||
|
|
startTime = start.Format(timeFormat)
|
|||
|
|
} else {
|
|||
|
|
startTime = start.Format(timeFormat)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 解析 EndTime
|
|||
|
|
end, errEnd := time.Parse(timeFormat, endTime)
|
|||
|
|
if errEnd != nil {
|
|||
|
|
end = time.Date(0, 1, 1, 23, 59, 0, 0, time.UTC) // 设置为 23:59
|
|||
|
|
endTime = end.Format(timeFormat)
|
|||
|
|
} else {
|
|||
|
|
endTime = end.Format(timeFormat)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 如果 EndTime 小于 StartTime,则将 EndTime 设置为 StartTime
|
|||
|
|
if end.Before(start) {
|
|||
|
|
end = start
|
|||
|
|
endTime = end.Format(timeFormat)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return startTime, endTime
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ToJSON 将任意结构体转换为 JSON 字符串
|
|||
|
|
func ToJSONStr(input interface{}) (string, error) {
|
|||
|
|
// 使用 json.Marshal 将对象转换为 JSON 字节数组
|
|||
|
|
bytes, err := json.Marshal(input)
|
|||
|
|
if err != nil {
|
|||
|
|
// 如果转换失败,返回错误提示
|
|||
|
|
return "", err
|
|||
|
|
}
|
|||
|
|
// 将字节数组转换为字符串并返回
|
|||
|
|
return string(bytes), nil
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// FromJSONS 将 JSON 字符串转换为任意结构体
|
|||
|
|
func FromJSONS(input string, output interface{}) error {
|
|||
|
|
if len(input) == 0 {
|
|||
|
|
// 将空字符串替换为一个空 JSON 对象
|
|||
|
|
input = "{}"
|
|||
|
|
}
|
|||
|
|
err := json.Unmarshal([]byte(input), output)
|
|||
|
|
return err
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 定时任务执行函数 true 可以执行,false 不执行
|
|||
|
|
func IsInTimeRange(StartTime string, EndTime string) bool {
|
|||
|
|
// 获取系统当前时间(HH:mm 格式)
|
|||
|
|
now := time.Now()
|
|||
|
|
layout := "15:04"
|
|||
|
|
currentTime, err := time.Parse(layout, now.Format(layout)) // 将当前时间转换为 HH:mm 格式
|
|||
|
|
if err != nil {
|
|||
|
|
// 如果解析失败,执行任务即可
|
|||
|
|
return true
|
|||
|
|
}
|
|||
|
|
// 解析 StartTime 和 EndTime
|
|||
|
|
startTime, err := time.Parse(layout, StartTime)
|
|||
|
|
if err != nil {
|
|||
|
|
// 如果解析失败,执行任务即可
|
|||
|
|
return true
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
endTime, err := time.Parse(layout, EndTime)
|
|||
|
|
|
|||
|
|
if err != nil {
|
|||
|
|
// 如果解析失败,执行任务即可
|
|||
|
|
return true
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 判断当前时间是否在范围内
|
|||
|
|
if (currentTime.After(startTime) || currentTime.Equal(startTime)) && (currentTime.Before(endTime) || currentTime.Equal(endTime)) {
|
|||
|
|
// 执行任务
|
|||
|
|
return true
|
|||
|
|
} else {
|
|||
|
|
// 不执行
|
|||
|
|
return false
|
|||
|
|
}
|
|||
|
|
}
|