2024-12-05 01:00:07 +08:00
|
|
|
|
package core
|
2024-11-28 15:20:29 +08:00
|
|
|
|
|
|
|
|
|
import (
|
2024-12-07 17:16:44 +08:00
|
|
|
|
"ProjectWIND/LOG"
|
2025-02-23 16:42:27 +08:00
|
|
|
|
"ProjectWIND/database"
|
2024-12-07 17:16:44 +08:00
|
|
|
|
"ProjectWIND/wba"
|
|
|
|
|
"crypto/rand"
|
|
|
|
|
"fmt"
|
2025-02-23 16:10:51 +08:00
|
|
|
|
"strings"
|
2024-11-28 15:20:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
type apiInfo struct{}
|
|
|
|
|
|
2024-12-14 17:51:09 +08:00
|
|
|
|
//一、Protocol模块
|
|
|
|
|
|
2024-12-03 09:21:00 +08:00
|
|
|
|
/*
|
2024-12-14 17:51:09 +08:00
|
|
|
|
关于Protocol模块的说明
|
2024-11-28 15:20:29 +08:00
|
|
|
|
|
2024-12-03 09:21:00 +08:00
|
|
|
|
1.所有API请求按照OneBot11标准,使用JSON格式进行数据交换。api命名为由原文档中蛇形命名法改为双驼峰命名法。
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
2.无响应的API请求使用ws协议处理,有响应的API需添加echo字段。
|
2024-12-03 09:21:00 +08:00
|
|
|
|
|
|
|
|
|
3.wind会从配置文件中读取API请求的url,请确保正确填写。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//1.无响应API,使用ws协议处理
|
2024-11-28 15:20:29 +08:00
|
|
|
|
|
2025-02-23 16:10:51 +08:00
|
|
|
|
// UnsafelySendMsg 发送消息(自动判断消息类型)
|
|
|
|
|
func (a *apiInfo) UnsafelySendMsg(messageType string, groupId int64, userId int64, message string, autoEscape bool) {
|
2025-02-13 13:32:24 +08:00
|
|
|
|
// 构建发送消息的JSON数据
|
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
messageData.Action = "send_msg"
|
|
|
|
|
switch messageType {
|
|
|
|
|
case "private":
|
|
|
|
|
{
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
case "group":
|
|
|
|
|
{
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
{
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("发送消息(UnsafelySendMsg)时,消息类型错误: %v", messageType)
|
2025-02-13 13:32:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
messageData.Params.Message = message
|
|
|
|
|
messageData.Params.AutoEscape = autoEscape
|
|
|
|
|
// 发送消息
|
|
|
|
|
_, err := wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("发送消息时,发送失败: %v", err)
|
2025-02-13 13:32:24 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("发送消息(UnsafelySendMsg)(至:%v-%v:%v):%v", messageType, groupId, userId, message)
|
2025-02-13 13:32:24 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 16:10:51 +08:00
|
|
|
|
// UnsafelySendPrivateMsg 发送私聊消息
|
|
|
|
|
func (a *apiInfo) UnsafelySendPrivateMsg(userId int64, message string, autoEscape bool) {
|
2025-02-13 13:32:24 +08:00
|
|
|
|
// 构建发送消息的JSON数据
|
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
messageData.Action = "send_private_msg"
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.Message = message
|
|
|
|
|
messageData.Params.AutoEscape = autoEscape
|
|
|
|
|
// 发送消息
|
|
|
|
|
_, err := wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("发送私聊消息(UnsafelySendPrivateMsg)时,发送失败: %v", err)
|
2025-02-13 13:32:24 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("发送私聊消息(UnsafelySendPrivateMsg)(至:%v):%v", userId, message)
|
2025-02-13 13:32:24 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 16:10:51 +08:00
|
|
|
|
// UnsafelySendGroupMsg 发送群消息
|
|
|
|
|
func (a *apiInfo) UnsafelySendGroupMsg(groupId int64, message string, autoEscape bool) {
|
2025-02-13 13:32:24 +08:00
|
|
|
|
// 构建发送消息的JSON数据
|
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
messageData.Action = "send_group_msg"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.Message = message
|
|
|
|
|
messageData.Params.AutoEscape = autoEscape
|
|
|
|
|
// 发送消息
|
|
|
|
|
_, err := wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("发送群消息(UnsafelySendGroupMsg)时,发送失败: %v", err)
|
2025-02-13 13:32:24 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("发送群消息(UnsafelySendGroupMsg)(至:%v):%v", groupId, message)
|
2025-02-13 13:32:24 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 16:10:51 +08:00
|
|
|
|
// SendMsg 回复消息(自动判断消息类型)
|
|
|
|
|
func (a *apiInfo) SendMsg(msg wba.MessageEventInfo, message string, autoEscape bool) {
|
2024-11-28 15:20:29 +08:00
|
|
|
|
// 构建发送消息的JSON数据
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
|
|
|
|
|
messageType := msg.MessageType
|
|
|
|
|
|
2024-11-28 15:20:29 +08:00
|
|
|
|
messageData.Action = "send_msg"
|
|
|
|
|
switch messageType {
|
|
|
|
|
case "private":
|
2024-12-03 09:21:00 +08:00
|
|
|
|
{
|
|
|
|
|
messageData.Params.UserId = msg.UserId
|
|
|
|
|
break
|
|
|
|
|
}
|
2024-11-28 15:20:29 +08:00
|
|
|
|
case "group":
|
2024-12-03 09:21:00 +08:00
|
|
|
|
{
|
|
|
|
|
messageData.Params.GroupId = msg.GroupId
|
|
|
|
|
break
|
|
|
|
|
}
|
2024-11-28 15:20:29 +08:00
|
|
|
|
default:
|
2024-12-03 09:21:00 +08:00
|
|
|
|
{
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("回复消息(SendMsg)时,消息类型错误: %v", messageType)
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
messageData.Params.Message = message
|
|
|
|
|
messageData.Params.AutoEscape = autoEscape
|
|
|
|
|
// 发送消息
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("回复消息时,发送失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("回复消息(SendMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 16:10:51 +08:00
|
|
|
|
// SendPrivateMsg 回复私聊消息
|
|
|
|
|
func (a *apiInfo) SendPrivateMsg(msg wba.MessageEventInfo, message string, autoEscape bool) {
|
2024-12-03 09:21:00 +08:00
|
|
|
|
// 构建发送消息的JSON数据
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "send_private_msg"
|
|
|
|
|
messageData.Params.UserId = msg.UserId
|
|
|
|
|
messageData.Params.Message = message
|
|
|
|
|
messageData.Params.AutoEscape = autoEscape
|
|
|
|
|
// 发送消息
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("回复消息(SendPrivateMsg)时,发送失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("回复消息(SendPrivateMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 16:10:51 +08:00
|
|
|
|
// SendGroupMsg 回复群消息
|
|
|
|
|
func (a *apiInfo) SendGroupMsg(msg wba.MessageEventInfo, message string, autoEscape bool) {
|
2024-12-03 09:21:00 +08:00
|
|
|
|
// 构建发送消息的JSON数据
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "send_group_msg"
|
|
|
|
|
messageData.Params.GroupId = msg.GroupId
|
2024-11-28 15:20:29 +08:00
|
|
|
|
messageData.Params.Message = message
|
|
|
|
|
messageData.Params.AutoEscape = autoEscape
|
|
|
|
|
// 发送消息
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("回复消息(SendGroupMsg)时,发送失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("回复消息(SendGroupMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UnsafelyDeleteMsg 撤回消息
|
|
|
|
|
func (a *apiInfo) UnsafelyDeleteMsg(messageId int32) {
|
|
|
|
|
// 构建删除消息的JSON数据
|
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
messageData.Action = "delete_msg"
|
|
|
|
|
messageData.Params.MessageId = messageId
|
|
|
|
|
_, err := wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
LOG.Error("撤回消息(UnsafeDeleteMsg)时,发送失败: %v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
LOG.Info("撤回消息(UnsafeDeleteMsg):[id:%v]", messageId)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// DeleteMsg 撤回消息
|
|
|
|
|
func (a *apiInfo) DeleteMsg(msg wba.MessageEventInfo) {
|
2024-12-03 09:21:00 +08:00
|
|
|
|
// 构建删除消息的JSON数据
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "delete_msg"
|
|
|
|
|
messageData.Params.MessageId = msg.MessageId
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("撤回消息(DeleteMsg)时,发送失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("撤回消息(DeleteMsg):[id:%v]%v", msg.MessageId, msg.RawMessage)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SendLike 发送赞
|
|
|
|
|
func (a *apiInfo) SendLike(userId int64, times int) {
|
2024-12-03 09:21:00 +08:00
|
|
|
|
// 构建发送赞的JSON数据
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "send_like"
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.Times = times
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("发送赞(SendLike)时,发送失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("发送赞(SendLike)(至:%v):%v", userId, times)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupKick 将指定用户移出群聊(需要群主或管理员权限)
|
|
|
|
|
func (a *apiInfo) SetGroupKick(groupId int64, userId int64, rejectAddRequest bool) {
|
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_kick"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.RejectAddRequest = rejectAddRequest
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("移出群聊(SetGroupKick)时,发送失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("移出群聊(SetGroupKick)(从:%v-%v):%v", groupId, userId, rejectAddRequest)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupBan 将指定用户禁言(需要群主或管理员权限)
|
|
|
|
|
func (a *apiInfo) SetGroupBan(groupId int64, userId int64, duration int32) {
|
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_ban"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.Duration = duration
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-03 09:21:00 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("禁言群成员(SetGroupBan)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("禁言群成员(SetGroupBan)(在:%v-%v):%v", groupId, userId, duration)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupWholeBan 设置全员禁言(需要群主或管理员权限)
|
|
|
|
|
func (a *apiInfo) SetGroupWholeBan(groupId int64, enable bool) {
|
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_whole_ban"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.Enable = enable
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("设置全员禁言(SetGroupWholeBan)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("设置全员禁言(SetGroupWholeBan)(在:%v):%v", groupId, enable)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupAdmin 设置群管理员(需要群主权限)
|
|
|
|
|
func (a *apiInfo) SetGroupAdmin(groupId int64, userId int64, enable bool) {
|
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_admin"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.Enable = enable
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-03 09:21:00 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("设置群管理员(SetGroupAdmin)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("设置群管理员(SetGroupAdmin)(在:%v-%v):%v", groupId, userId, enable)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupCard 设置群名片(需要群主或管理员权限)
|
|
|
|
|
func (a *apiInfo) SetGroupCard(groupId int64, userId int64, card string) {
|
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_card"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.Card = card
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("设置群名片(SetGroupCard)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("设置群名片(SetGroupCard)(在:%v-%v):%v", groupId, userId, card)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupName 设置群名称(可能需要群主或管理员权限)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
func (a *apiInfo) SetGroupName(groupId int64, groupName string) {
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_name"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.GroupName = groupName
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("设置群名称(SetGroupName)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("设置群名称(SetGroupName)(在:%v):%v", groupId, groupName)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupLeave 退出群聊
|
2024-12-14 17:51:09 +08:00
|
|
|
|
func (a *apiInfo) SetGroupLeave(groupId int64, isDismiss bool) {
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_leave"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.IsDismiss = isDismiss
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("退出群聊(SetGroupLeave)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("退出群聊(SetGroupLeave)(在:%v):%v", groupId, isDismiss)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupSpecialTitle 设置群专属头衔(需要群主权限)
|
2025-02-23 16:10:51 +08:00
|
|
|
|
func (a *apiInfo) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle string) {
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_group_special_title"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.SpecialTitle = specialTitle
|
2025-02-23 16:10:51 +08:00
|
|
|
|
messageData.Params.Duration = -1
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("设置群特殊头衔(SetGroupSpecialTitle)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("设置群特殊头衔(SetGroupSpecialTitle)(在:%v-%v):%v-%v", groupId, userId, specialTitle)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetFriendAddRequest 处理加好友请求
|
2024-12-14 17:51:09 +08:00
|
|
|
|
func (a *apiInfo) SetFriendAddRequest(flag string, approve bool, remark string) {
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
2024-12-03 09:21:00 +08:00
|
|
|
|
messageData.Action = "set_friend_add_request"
|
|
|
|
|
messageData.Params.Flag = flag
|
|
|
|
|
messageData.Params.Approve = approve
|
|
|
|
|
messageData.Params.Remark = remark
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("处理加好友请求(SetFriendAddRequest)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("处理加好友请求(SetFriendAddRequest)(在:%v):%v-%v-%v", flag, approve, remark)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
// SetGroupAddRequest 处理加群请求/邀请
|
2024-12-14 17:51:09 +08:00
|
|
|
|
func (a *apiInfo) SetGroupAddRequest(flag string, subType string, approve bool, reason string) {
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
messageData.Action = "set_group_add_request"
|
|
|
|
|
messageData.Params.Flag = flag
|
|
|
|
|
messageData.Params.SubType = subType
|
|
|
|
|
messageData.Params.Approve = approve
|
|
|
|
|
messageData.Params.Reason = reason
|
2024-12-13 22:04:56 +08:00
|
|
|
|
_, err := wsAPI(messageData)
|
2024-12-03 09:21:00 +08:00
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("处理加群请求/邀请(SetGroupAddRequest)时,执行失败: %v", err)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
2024-12-03 09:21:00 +08:00
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("处理加群请求/邀请(SetGroupAddRequest)(在:%v-%v-%v):%v", flag, subType, approve, reason)
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-14 17:51:09 +08:00
|
|
|
|
// SetRestart 重启
|
|
|
|
|
func (a *apiInfo) SetRestart(delay int32) {
|
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
messageData.Action = "set_restart"
|
|
|
|
|
messageData.Params.Delay = delay
|
|
|
|
|
_, err := wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("设置重启(SetRestart)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("设置重启(SetRestart):%v", delay)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CleanCache 清理缓存
|
|
|
|
|
func (a *apiInfo) CleanCache() {
|
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
messageData.Action = "clean_cache"
|
|
|
|
|
_, err := wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("清理缓存(CleanCache)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("清理缓存(CleanCache)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 15:11:31 +08:00
|
|
|
|
// 2.有响应API,需添加echo字段
|
|
|
|
|
|
2024-12-14 17:51:09 +08:00
|
|
|
|
// GetLoginInfo 获取登录信息
|
|
|
|
|
func (a *apiInfo) GetLoginInfo() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取登录信息(GetLoginInfo)")
|
2024-12-13 22:04:56 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_login_info"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取登录信息(GetLoginInfo)时,生成UUID失败: %v", err)
|
2024-12-13 22:04:56 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取登录信息(GetLoginInfo)时,执行失败: %v", err)
|
2024-12-13 22:04:56 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
2024-12-12 15:11:31 +08:00
|
|
|
|
}
|
2024-12-07 17:16:44 +08:00
|
|
|
|
|
2024-12-14 17:51:09 +08:00
|
|
|
|
// GetVersionInfo 获取协议信息
|
|
|
|
|
func (a *apiInfo) GetVersionInfo() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取协议信息(GetVersionInfo)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_version_info"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取协议信息(GetVersionInfo)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取登录信息(GetVersionInfo)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetMsg 获取消息
|
|
|
|
|
func (a *apiInfo) GetMsg(messageId int32) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取消息(GetMsg)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_msg"
|
|
|
|
|
messageData.Params.MessageId = messageId
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取消息(GetMsg)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取消息(GetMsg)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetForwardMsg 获取合并转发消息
|
|
|
|
|
func (a *apiInfo) GetForwardMsg(id string) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取合并转发消息(GetForwardMsg)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_forward_msg"
|
|
|
|
|
messageData.Params.Id = id
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取合并转发消息(GetForwardMsg)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取合并转发消息(GetForwardMsg)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetStrangerInfo 获取陌生人信息
|
|
|
|
|
func (a *apiInfo) GetStrangerInfo(userId int64, noCache bool) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取陌生人信息(GetStrangerInfo)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_stranger_info"
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.NoCache = noCache
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取陌生人信息(GetStrangerInfo)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取陌生人信息(GetStrangerInfo)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetFriendList 获取好友列表
|
|
|
|
|
func (a *apiInfo) GetFriendList() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取好友列表(GetFriendList)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_friend_list"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取好友列表(GetFriendList)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取好友列表(GetFriendList)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGroupList 获取群列表
|
|
|
|
|
func (a *apiInfo) GetGroupList() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取群列表(GetGroupList)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_group_list"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群列表(GetGroupList)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群列表(GetGroupList)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGroupInfo 获取群信息
|
|
|
|
|
func (a *apiInfo) GetGroupInfo(groupId int64, noCache bool) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取群信息(GetGroupInfo)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_group_info"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.NoCache = noCache
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群信息(GetGroupInfo)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群信息(GetGroupInfo)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGroupMemberInfo 获取群成员信息
|
|
|
|
|
func (a *apiInfo) GetGroupMemberInfo(groupId int64, userId int64, noCache bool) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取群成员信息(GetGroupMemberInfo)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_group_member_info"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Params.UserId = userId
|
|
|
|
|
messageData.Params.NoCache = noCache
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群成员信息(GetGroupMemberInfo)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群成员信息(GetGroupMemberInfo)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGroupMemberList 获取群成员列表
|
|
|
|
|
func (a *apiInfo) GetGroupMemberList(groupId int64) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取群成员列表(GetGroupMemberList)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_group_member_list"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群成员列表(GetGroupMemberList)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群成员列表(GetGroupMemberList)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGroupHonorInfo 获取群荣誉信息
|
2024-12-27 15:56:59 +08:00
|
|
|
|
func (a *apiInfo) GetGroupHonorInfo(groupId int64, Type string) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取群荣誉信息(GetGroupHonorInfo)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_group_honor_info"
|
|
|
|
|
messageData.Params.GroupId = groupId
|
2024-12-27 15:56:59 +08:00
|
|
|
|
messageData.Params.Type = Type
|
2024-12-14 17:51:09 +08:00
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群荣誉信息(GetGroupHonorInfo)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取群荣誉信息(GetGroupHonorInfo)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCookies 获取Cookies
|
|
|
|
|
func (a *apiInfo) GetCookies(domain string) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取Cookies(GetCookies)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_cookies"
|
|
|
|
|
messageData.Params.Domain = domain
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取Cookies(GetCookies)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取Cookies(GetCookies)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCSRFToken 获取CSRF Token
|
|
|
|
|
func (a *apiInfo) GetCSRFToken() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取CSRF Token(GetCSRFToken)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_csrf_token"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取CSRF Token(GetCSRFToken)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取CSRF Token(GetCSRFToken)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCredentials 获取登录令牌
|
|
|
|
|
func (a *apiInfo) GetCredentials(domain string) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取登录令牌(GetCredentials)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_credentials"
|
|
|
|
|
messageData.Params.Domain = domain
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取登录令牌(GetCredentials)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取登录令牌(GetCredentials)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetRecord 获取语音
|
|
|
|
|
func (a *apiInfo) GetRecord(file string, outFormat string) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取语音(GetRecord)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_record"
|
|
|
|
|
messageData.Params.File = file
|
|
|
|
|
messageData.Params.OutFormat = outFormat
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取语音(GetRecord)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取语音(GetRecord)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetImage 获取图片
|
|
|
|
|
func (a *apiInfo) GetImage(file string) (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取图片(GetImage)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_image"
|
|
|
|
|
messageData.Params.File = file
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取图片(GetImage)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取图片(GetImage)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CanSendImage 检查是否可以发送图片
|
|
|
|
|
func (a *apiInfo) CanSendImage() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("检查是否可以发送图片(CanSendImage)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "can_send_image"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("检查是否可以发送图片(CanSendImage)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("检查是否可以发送图片(CanSendImage)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CanSendRecord 检查是否可以发送语音
|
|
|
|
|
func (a *apiInfo) CanSendRecord() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("检查是否可以发送语音(CanSendRecord)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "can_send_record"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("检查是否可以发送语音(CanSendRecord)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("检查是否可以发送语音(CanSendRecord)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetStatus 获取状态
|
|
|
|
|
func (a *apiInfo) GetStatus() (Response wba.APIResponseInfo) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info("获取状态(GetStatus)")
|
2024-12-14 17:51:09 +08:00
|
|
|
|
var messageData wba.APIRequestInfo
|
|
|
|
|
var err error
|
|
|
|
|
messageData.Action = "get_status"
|
|
|
|
|
messageData.Echo, err = GenerateUUID()
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取状态(GetStatus)时,生成UUID失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
Response, err = wsAPI(messageData)
|
|
|
|
|
if err != nil {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Error("获取状态(GetStatus)时,执行失败: %v", err)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return wba.APIResponseInfo{}
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//二、LOG模块
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
关于LOG模块的说明
|
|
|
|
|
|
2025-02-23 16:10:51 +08:00
|
|
|
|
1.日志模块使用go-logging库,日志级别分为DEBUG、Info、Warn、Error。
|
2024-12-14 17:51:09 +08:00
|
|
|
|
|
|
|
|
|
2.日志模块提供LogWith方法,可以自定义日志级别,调用级别为DEBUG时,会打印输出调用者的文件名、函数名、行号。
|
|
|
|
|
|
|
|
|
|
3.日志模块提供Log方法,默认日志级别为INFO。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) LogWith(level string, content string, args ...interface{}) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
level = strings.ToLower(level)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
switch level {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
case "trace":
|
|
|
|
|
LOG.Trace(content, args...)
|
|
|
|
|
return
|
|
|
|
|
case "debug":
|
|
|
|
|
LOG.Debug(content, args...)
|
|
|
|
|
return
|
|
|
|
|
case "notice":
|
|
|
|
|
LOG.Notice(content, args...)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
2025-02-23 16:10:51 +08:00
|
|
|
|
case "warn":
|
|
|
|
|
LOG.Warn(content, args...)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
2025-02-23 16:10:51 +08:00
|
|
|
|
case "error":
|
|
|
|
|
LOG.Error(content, args...)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
|
|
|
|
default:
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info(content, args...)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) Log(content string, args ...interface{}) {
|
2025-02-23 16:10:51 +08:00
|
|
|
|
LOG.Info(content, args...)
|
2024-12-14 17:51:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//database模块
|
2025-02-23 16:42:27 +08:00
|
|
|
|
//数据库部分允许字符串变量的读写操作,允许获取配置项操作
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) VarSet(app wba.AppInfo, datamap string, unit string, id string, key string, value string) {
|
|
|
|
|
database.Set(app, datamap, unit, id, key, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) VarGet(app wba.AppInfo, datamap string, unit string, id string, key string) (string, bool) {
|
|
|
|
|
res, ok := database.Get(app, datamap, unit, id, key, false)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
resStr, ok := res.(string)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
return resStr, true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) GetIntConfig(app wba.AppInfo, datamap string, key string) (int64, bool) {
|
|
|
|
|
res, ok := database.Get(app, datamap, "config", "number", key, true)
|
|
|
|
|
if !ok {
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
resInt, ok := res.(int64)
|
|
|
|
|
if !ok {
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
return resInt, true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) GetStringConfig(app wba.AppInfo, datamap string, key string) (string, bool) {
|
|
|
|
|
res, ok := database.Get(app, datamap, "config", "string", key, true)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
resStr, ok := res.(string)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
return resStr, true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) GetFloatConfig(app wba.AppInfo, datamap string, key string) (float64, bool) {
|
|
|
|
|
res, ok := database.Get(app, datamap, "config", "float", key, true)
|
|
|
|
|
if !ok {
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
resFloat, ok := res.(float64)
|
|
|
|
|
if !ok {
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
return resFloat, true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) GetIntSliceConfig(app wba.AppInfo, datamap string, key string) ([]int64, bool) {
|
|
|
|
|
res, ok := database.Get(app, datamap, "config", "number_slice", key, true)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, false
|
|
|
|
|
}
|
|
|
|
|
resSlice, ok := res.([]int64)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, false
|
|
|
|
|
}
|
|
|
|
|
return resSlice, true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *apiInfo) GetStringSliceConfig(app wba.AppInfo, datamap string, key string) ([]string, bool) {
|
|
|
|
|
res, ok := database.Get(app, datamap, "config", "string_slice", key, true)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, false
|
|
|
|
|
}
|
|
|
|
|
resSlice, ok := res.([]string)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, false
|
|
|
|
|
}
|
|
|
|
|
return resSlice, true
|
|
|
|
|
}
|
2024-12-14 17:51:09 +08:00
|
|
|
|
|
2024-12-27 15:56:59 +08:00
|
|
|
|
// 文件管理模块
|
|
|
|
|
//TODO: 文件管理模块待实现
|
|
|
|
|
|
|
|
|
|
//终端连接模块
|
|
|
|
|
//TODO: 终端模块待实现
|
|
|
|
|
|
|
|
|
|
//核心信息调用模块
|
|
|
|
|
|
2024-12-07 17:16:44 +08:00
|
|
|
|
var AppApi apiInfo
|
|
|
|
|
|
|
|
|
|
func GenerateUUID() (string, error) {
|
|
|
|
|
uuid := make([]byte, 16)
|
|
|
|
|
_, err := rand.Read(uuid)
|
2024-11-28 15:20:29 +08:00
|
|
|
|
if err != nil {
|
2024-12-07 17:16:44 +08:00
|
|
|
|
return "", err
|
2024-11-28 15:20:29 +08:00
|
|
|
|
}
|
2024-12-07 17:16:44 +08:00
|
|
|
|
|
|
|
|
|
// 设置UUID版本号(版本4),将第6字节的高4位设置为0100
|
|
|
|
|
uuid[6] = (uuid[6] & 0x0F) | 0x40
|
|
|
|
|
// 设置UUID变体(RFC 4122规范定义的变体),将第8字节的高4位设置为10
|
|
|
|
|
uuid[8] = (uuid[8] & 0x3F) | 0x80
|
|
|
|
|
|
|
|
|
|
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
|
2024-11-28 15:20:29 +08:00
|
|
|
|
}
|