Compare commits

..

No commits in common. "main" and "v0.0.2" have entirely different histories.
main ... v0.0.2

19 changed files with 116 additions and 210 deletions

View File

@ -3,9 +3,6 @@ package xybot
import (
"encoding/json"
"errors"
"slices"
"strings"
"gitee.ltd/lxh/xybot/core"
"gitee.ltd/lxh/xybot/friend"
"gitee.ltd/lxh/xybot/group"
@ -15,9 +12,12 @@ import (
"gitee.ltd/lxh/xybot/tool"
"gitee.ltd/lxh/xybot/user"
"github.com/go-resty/resty/v2"
"slices"
)
type Client struct {
// 基础URL
wxId string
// HTTP客户端
httpClient *resty.Client
@ -43,12 +43,8 @@ func NewClient(wxId, baseUrl string, debug bool) (cli *Client, err error) {
err = errors.New("baseUrl 不得为空,格式为: http://10.0.0.11:9001")
return
}
// 如果URL没有以http://或https://开头自动添加http://
if !strings.HasPrefix(baseUrl, "http://") && !strings.HasPrefix(baseUrl, "https://") {
baseUrl = "http://" + baseUrl
}
// 设置一下机器人微信Id的值
wxInfo := core.NewInfo(wxId)
core.WxId = wxId
cli = &Client{}
cli.httpClient = resty.New().
@ -59,13 +55,13 @@ func NewClient(wxId, baseUrl string, debug bool) (cli *Client, err error) {
SetJSONUnmarshaler(json.Unmarshal).
OnBeforeRequest(requestPreCheck)
cli.Login = login.New(cli.httpClient, wxInfo)
cli.Friend = friend.New(cli.httpClient, wxInfo)
cli.Group = group.New(cli.httpClient, wxInfo)
cli.Message = message.New(cli.httpClient, wxInfo)
cli.User = user.New(cli.httpClient, wxInfo)
cli.HongBao = hongbao.New(cli.httpClient, wxInfo)
cli.Tool = tool.New(cli.httpClient, wxInfo)
cli.Login = login.New(cli.httpClient)
cli.Friend = friend.New(cli.httpClient)
cli.Group = group.New(cli.httpClient)
cli.Message = message.New(cli.httpClient)
cli.User = user.New(cli.httpClient)
cli.HongBao = hongbao.New(cli.httpClient)
cli.Tool = tool.New(cli.httpClient)
return
}
@ -82,8 +78,7 @@ func requestPreCheck(_ *resty.Client, req *resty.Request) (err error) {
// 如果是白名单请求,直接返回
return nil
}
if req.Header.Get("WeChatId") == "" {
if core.WxId == "" {
// 如果WxId为空直接返回
return errors.New("wxId不能为空")
}

View File

@ -1,31 +1,4 @@
package core
// RobotInfo
// @description: 机器人信息
type RobotInfo struct {
wxId string // 机器人微信Id
}
// SetId
// @description: 设置机器人Id
// @receiver i
// @param wxId
func (i *RobotInfo) SetId(wxId string) {
i.wxId = wxId
}
// GetId
// @description: 获取机器人Id
// @receiver i
// @return string
func (i *RobotInfo) GetId() string {
return i.wxId
}
// NewInfo
// @description: 创建机器人信息
// @param wxId
// @return *RobotInfo
func NewInfo(wxId string) *RobotInfo {
return &RobotInfo{wxId: wxId}
}
// WxId 微信Id将所有接口调用的wxId值都放到这儿来方便判断是否可用
var WxId = ""

View File

@ -1,9 +1,6 @@
package friend
import (
"gitee.ltd/lxh/xybot/core"
"github.com/go-resty/resty/v2"
)
import "github.com/go-resty/resty/v2"
type API interface {
AcceptFriend(scene int, v1, v2 string) (err error) // 接受好友请求
@ -13,10 +10,9 @@ type API interface {
}
type service struct {
client *resty.Client
robotInfo *core.RobotInfo
client *resty.Client
}
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
return &service{client: client, robotInfo: robotInfo}
func New(client *resty.Client) API {
return &service{client: client}
}

View File

@ -3,6 +3,7 @@ package friend
import (
"errors"
"gitee.ltd/lxh/xybot/base"
"gitee.ltd/lxh/xybot/core"
"slices"
"strings"
)
@ -17,10 +18,9 @@ import (
func (s service) AcceptFriend(scene int, v1, v2 string) (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Scene": scene,
"V1": v1,
"V2": v2,
@ -38,10 +38,9 @@ func (s service) AcceptFriend(scene int, v1, v2 string) (err error) {
func (s service) GetContact(wxIds []string) (contactList []ContactListItem, err error) {
var result base.Response[GetContactResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"RequestWxids": strings.Join(wxIds, ","),
}).Post("/GetContact")
if err = result.CheckError(err); err != nil {
@ -65,10 +64,9 @@ func (s service) GetContractDetail(wxIds []string) (contactList []ContactListIte
var result base.Response[GetContactResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"RequestWxids": strings.Join(wxIds, ","),
"Chatroom": "",
}).Post("/GetContractDetail")
@ -88,10 +86,9 @@ func (s service) GetContractDetail(wxIds []string) (contactList []ContactListIte
func (s service) GetContractList(clearSystemAccount bool) (wxIds []string, err error) {
var result base.Response[GetContractListResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"CurrentChatroomContactSeq": 0,
"CurrentWxcontactSeq": 0,
}).Post("/GetContractList")

View File

@ -111,7 +111,7 @@ type ContactListItem struct {
SmallHeadImgUrl string `json:"SmallHeadImgUrl"`
SnsUserInfo struct {
SnsBgImgId string `json:"SnsBgimgId"`
SnsBgObjectId uint `json:"SnsBgobjectId"`
SnsBgObjectId int `json:"SnsBgobjectId"`
SnsFlag int `json:"SnsFlag"`
SnsFlagEx int `json:"SnsFlagEx"`
} `json:"SnsUserInfo"`

View File

@ -1,9 +1,6 @@
package group
import (
"gitee.ltd/lxh/xybot/core"
"github.com/go-resty/resty/v2"
)
import "github.com/go-resty/resty/v2"
type API interface {
AddChatroomMember(chatroom string, inviteWxId string) (err error) // 添加群聊成员(群聊最多40人)
@ -15,10 +12,9 @@ type API interface {
}
type service struct {
client *resty.Client
robotInfo *core.RobotInfo
client *resty.Client
}
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
return &service{client: client, robotInfo: robotInfo}
func New(client *resty.Client) API {
return &service{client: client}
}

View File

@ -2,6 +2,7 @@ package group
import (
"gitee.ltd/lxh/xybot/base"
"gitee.ltd/lxh/xybot/core"
"strings"
)
@ -14,10 +15,9 @@ import (
func (s service) AddChatroomMember(chatroom string, inviteWxId string) (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Chatroom": chatroom,
"InviteWxids": inviteWxId,
}).Post("/AddChatroomMember")
@ -34,10 +34,9 @@ func (s service) AddChatroomMember(chatroom string, inviteWxId string) (err erro
func (s service) InviteChatroomMember(chatroom string, inviteWxIds []string) (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Chatroom": chatroom,
"InviteWxids": strings.Join(inviteWxIds, ","),
}).Post("/InviteChatroomMember")
@ -54,10 +53,9 @@ func (s service) InviteChatroomMember(chatroom string, inviteWxIds []string) (er
func (s service) GetChatroomInfo(chatroom string) (info GetChatroomInfoResponse, err error) {
var result base.Response[GetChatroomInfoResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Chatroom": chatroom,
}).Post("/GetChatroomInfo")
if err = result.CheckError(err); err != nil {
@ -76,10 +74,9 @@ func (s service) GetChatroomInfo(chatroom string) (info GetChatroomInfoResponse,
func (s service) GetChatroomInfoNoAnnounce(chatroom []string) (info []ChatroomInfoItem, err error) {
var result base.Response[GetChatroomInfoNoAnnounce]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Chatroom": strings.Join(chatroom, ","),
}).Post("/GetChatroomInfoNoAnnounce")
if err = result.CheckError(err); err != nil {
@ -98,10 +95,9 @@ func (s service) GetChatroomInfoNoAnnounce(chatroom []string) (info []ChatroomIn
func (s service) GetChatroomMemberDetail(chatroom string) (members []ChatRoomMemberItem, err error) {
var result base.Response[GetChatroomMemberDetailResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Chatroom": chatroom,
}).Post("/GetChatroomMemberDetail")
if err = result.CheckError(err); err != nil {
@ -121,10 +117,9 @@ func (s service) GetChatroomMemberDetail(chatroom string) (members []ChatRoomMem
func (s service) GetChatroomQRCode(chatroom string) (imgBase64Str, notify string, err error) {
var result base.Response[GetChatroomQRCodeResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Chatroom": chatroom,
}).Post("/GetChatroomQRCode")
if err = result.CheckError(err); err != nil {

View File

@ -107,9 +107,9 @@ type ChatroomInfoItem struct {
AlbumStyle int `json:"AlbumStyle"`
AlbumFlag int `json:"AlbumFlag"`
SnsUserInfo struct {
SnsFlag int `json:"SnsFlag"`
SnsBgobjectId uint `json:"SnsBgobjectId"`
SnsFlagEx int `json:"SnsFlagEx"`
SnsFlag int `json:"SnsFlag"`
SnsBgobjectId int `json:"SnsBgobjectId"`
SnsFlagEx int `json:"SnsFlagEx"`
} `json:"SnsUserInfo"`
SmallHeadImgUrl string `json:"SmallHeadImgUrl"` // 头像
CustomizedInfo struct {

View File

@ -1,19 +1,15 @@
package hongbao
import (
"gitee.ltd/lxh/xybot/core"
"github.com/go-resty/resty/v2"
)
import "github.com/go-resty/resty/v2"
type API interface {
GetHongBaoDetail(xml, encryptKey, encryptUserinfo string) (resp any, err error) // 获取红包详情
}
type service struct {
client *resty.Client
robotInfo *core.RobotInfo
client *resty.Client
}
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
return &service{client: client, robotInfo: robotInfo}
func New(client *resty.Client) API {
return &service{client: client}
}

View File

@ -2,6 +2,7 @@ package hongbao
import (
"gitee.ltd/lxh/xybot/base"
"gitee.ltd/lxh/xybot/core"
)
// GetHongBaoDetail
@ -13,12 +14,12 @@ import (
// @return resp
// @return err
func (s service) GetHongBaoDetail(xml, encryptKey, encryptUserinfo string) (resp any, err error) {
var result base.Response[any]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Xml": xml,
"EncryptKey": encryptKey,
"EncryptUserinfo": encryptUserinfo,

View File

@ -1,9 +1,6 @@
package login
import (
"gitee.ltd/lxh/xybot/core"
"github.com/go-resty/resty/v2"
)
import "github.com/go-resty/resty/v2"
type API interface {
GetQRCode(deviceId, deviceName string) (resp GetQRCodeResponse, err error) // 获取登录二维码
@ -18,10 +15,9 @@ type API interface {
}
type service struct {
client *resty.Client
robotInfo *core.RobotInfo
client *resty.Client
}
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
return &service{client: client, robotInfo: robotInfo}
func New(client *resty.Client) API {
return &service{client: client}
}

View File

@ -3,6 +3,7 @@ package login
import (
"fmt"
"gitee.ltd/lxh/xybot/base"
"gitee.ltd/lxh/xybot/core"
)
// GetQRCode
@ -34,11 +35,7 @@ func (s service) GetQRCode(deviceId, deviceName string) (resp GetQRCodeResponse,
// @return err
func (s service) AwakenLogin() (resp AwakenLoginResponse, err error) {
var result base.Response[AwakenLoginResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
Post("/AwakenLogin")
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AwakenLogin")
if err = result.CheckError(err); err != nil {
return
}
@ -65,7 +62,7 @@ func (s service) CheckUuid(uuid string) (resp CheckUuidResponse, err error) {
resp = result.Data
// 这儿做一下处理在登录成功之后更新一下wxId的值免得再初始化一次client
if resp.AcctSectResp.Username != "" {
s.robotInfo.SetId(resp.AcctSectResp.Username)
core.WxId = resp.AcctSectResp.Username
}
return
}
@ -76,11 +73,7 @@ func (s service) CheckUuid(uuid string) (resp CheckUuidResponse, err error) {
// @return err
func (s service) AutoHeartbeatStart() (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
Post("/AutoHeartbeatStart")
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AutoHeartbeatStart")
err = result.CheckError(err)
return
}
@ -92,11 +85,7 @@ func (s service) AutoHeartbeatStart() (err error) {
// @return err
func (s service) AutoHeartbeatStatus() (running bool, err error) {
var result AutoHeartbeatStatusResponse
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
Post("/AutoHeartbeatStatus")
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AutoHeartbeatStatus")
if err == nil {
if !result.Success {
err = fmt.Errorf("[%d] %s", result.Code, result.Message)
@ -113,11 +102,7 @@ func (s service) AutoHeartbeatStatus() (running bool, err error) {
// @return err
func (s service) AutoHeartbeatStop() (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
Post("/AutoHeartbeatStop")
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AutoHeartbeatStop")
err = result.CheckError(err)
return
}
@ -128,11 +113,7 @@ func (s service) AutoHeartbeatStop() (err error) {
// @return err
func (s service) Heartbeat() (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
Post("/Heartbeat")
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/Heartbeat")
err = result.CheckError(err)
return
}
@ -144,11 +125,7 @@ func (s service) Heartbeat() (err error) {
// @return err
func (s service) GetCachedInfo() (resp GetCachedInfoResponse, err error) {
var result base.Response[GetCachedInfoResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
Post("/GetCachedInfo")
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/GetCachedInfo")
if err = result.CheckError(err); err != nil {
return
}
@ -162,11 +139,7 @@ func (s service) GetCachedInfo() (resp GetCachedInfoResponse, err error) {
// @return err
func (s service) Logout() (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
Post("/Logout")
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/Logout")
err = result.CheckError(err)
return
}

View File

@ -1,9 +1,6 @@
package message
import (
"gitee.ltd/lxh/xybot/core"
"github.com/go-resty/resty/v2"
)
import "github.com/go-resty/resty/v2"
type API interface {
RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int) (err error) // 撤回消息
@ -22,10 +19,9 @@ type API interface {
}
type service struct {
client *resty.Client
robotInfo *core.RobotInfo
client *resty.Client
}
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
return &service{client: client, robotInfo: robotInfo}
func New(client *resty.Client) API {
return &service{client: client}
}

View File

@ -3,6 +3,7 @@ package message
import (
"errors"
"gitee.ltd/lxh/xybot/base"
"gitee.ltd/lxh/xybot/core"
"strings"
)
@ -15,12 +16,12 @@ import (
// @param newMsgId int 返回消息的NewMsgId字段
// @return err
func (s service) RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int) (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"ClientMsgId": clientMsgId,
"CreateTime": createTime,
@ -41,12 +42,12 @@ func (s service) RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int)
// @return newMsgId int 返回消息的NewMsgId字段
// @return err
func (s service) SendAppMsg(toWxId, xml string, appMsgType int) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Xml": xml,
"Type": appMsgType,
@ -70,12 +71,12 @@ func (s service) SendAppMsg(toWxId, xml string, appMsgType int) (clientMsgId, cr
// @return newMsgId
// @return err
func (s service) SendCDNFileMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Content": xml,
}).Post("/SendCDNFileMsg")
@ -98,12 +99,12 @@ func (s service) SendCDNFileMsg(toWxId, xml string) (clientMsgId, createTime, ne
// @return newMsgId
// @return err
func (s service) SendCDNImgMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Content": xml,
}).Post("/SendCDNImgMsg")
@ -126,12 +127,12 @@ func (s service) SendCDNImgMsg(toWxId, xml string) (clientMsgId, createTime, new
// @return newMsgId
// @return err
func (s service) SendCDNVideoMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Content": xml,
}).Post("/SendCDNVideoMsg")
@ -156,12 +157,12 @@ func (s service) SendCDNVideoMsg(toWxId, xml string) (clientMsgId, createTime, n
// @return newMsgId
// @return err
func (s service) SendCardMsg(toWxId, cardWxId, cardNickname, cardAlias string) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"CardWxid": cardWxId,
"CardNickname": cardNickname,
@ -185,12 +186,12 @@ func (s service) SendCardMsg(toWxId, cardWxId, cardNickname, cardAlias string) (
// @return resp
// @return err
func (s service) SendEmojiMsg(toWxId, md5 string, length int) (resp any, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Md5": md5,
"TotalLen": length,
@ -212,12 +213,12 @@ func (s service) SendEmojiMsg(toWxId, md5 string, length int) (resp any, err err
// @return newMsgId
// @return err
func (s service) SendImageMsg(toWxId, imgBase64Str string) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Base64": imgBase64Str,
}).Post("/SendImageMsg")
@ -243,12 +244,12 @@ func (s service) SendImageMsg(toWxId, imgBase64Str string) (clientMsgId, createT
// @return newMsgId
// @return err
func (s service) SendShareLink(toWxId, url, title, description, thumbUrl string) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Url": url,
"Title": title,
@ -275,12 +276,12 @@ func (s service) SendShareLink(toWxId, url, title, description, thumbUrl string)
// @return newMsgId
// @return err
func (s service) SendTextMsg(toWxId, content string, atUser []string) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Content": content,
"Type": 1,
@ -307,12 +308,12 @@ func (s service) SendTextMsg(toWxId, content string, atUser []string) (clientMsg
// @return newMsgId
// @return err
func (s service) SendVideoMsg(toWxId, video, cover string, duration int) (clientMsgId, createTime, newMsgId int, err error) {
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Base64": video,
"ImageBase64": cover,
@ -339,6 +340,7 @@ func (s service) SendVideoMsg(toWxId, video, cover string, duration int) (client
// @return newMsgId
// @return err
func (s service) SendVoiceMsg(toWxId, voice, format string, duration int) (clientMsgId, createTime, newMsgId int, err error) {
formatMap := map[string]int{"amr": 0, "wav": 4, "mp3": 4}
if _, ok := formatMap[format]; !ok {
err = errors.New("不支持的语音格式")
@ -347,10 +349,9 @@ func (s service) SendVoiceMsg(toWxId, voice, format string, duration int) (clien
var result base.Response[SendMessageResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"ToWxid": toWxId,
"Base64": voice,
"VoiceTime": duration,
@ -371,12 +372,12 @@ func (s service) SendVoiceMsg(toWxId, voice, format string, duration int) (clien
// @return msg
// @return err
func (s service) Sync() (msg []SyncMessage, err error) {
var result base.Response[SyncResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Scene": 0,
"Synckey": "",
}).Post("/Sync")

View File

@ -1,9 +1,6 @@
package tool
import (
"gitee.ltd/lxh/xybot/core"
"github.com/go-resty/resty/v2"
)
import "github.com/go-resty/resty/v2"
type API interface {
CheckDatabaseOK() (running bool, err error) // 检查数据库是否正常
@ -17,10 +14,9 @@ type API interface {
}
type service struct {
client *resty.Client
robotInfo *core.RobotInfo
client *resty.Client
}
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
return &service{client: client, robotInfo: robotInfo}
func New(client *resty.Client) API {
return &service{client: client}
}

View File

@ -3,6 +3,7 @@ package tool
import (
"fmt"
"gitee.ltd/lxh/xybot/base"
"gitee.ltd/lxh/xybot/core"
)
// CheckDatabaseOK
@ -41,10 +42,9 @@ func (s service) IsRunning() (flag bool, err error) {
func (s service) CdnDownloadImg(aesKey, cdnMidImgUrl string) (dataBase64Str string, err error) {
var result base.Response[string]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"AesKey": aesKey,
"Cdnmidimgurl": cdnMidImgUrl,
}).Post("/CdnDownloadImg")
@ -64,10 +64,9 @@ func (s service) CdnDownloadImg(aesKey, cdnMidImgUrl string) (dataBase64Str stri
func (s service) DownloadAttach(attachId string) (dataBase64Str string, err error) {
var result base.Response[DownloadAttachResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"AttachId": attachId,
}).Post("/DownloadAttach")
if err = result.CheckError(err); err != nil {
@ -87,10 +86,9 @@ func (s service) DownloadVideo(msgId int) (dataBase64Str string, err error) {
var result base.Response[DownloadAttachResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"MsgId": msgId,
}).Post("/DownloadVideo")
if err = result.CheckError(err); err != nil {
@ -109,12 +107,12 @@ func (s service) DownloadVideo(msgId int) (dataBase64Str string, err error) {
// @return dataBase64Str
// @return err
func (s service) DownloadVoice(msgId int, voiceUrl string, length int) (dataBase64Str string, err error) {
var result base.Response[DownloadAttachResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"MsgId": msgId,
"Voiceurl": voiceUrl,
"Length": length,
@ -132,12 +130,12 @@ func (s service) DownloadVoice(msgId int, voiceUrl string, length int) (dataBase
// @param param
// @return err
func (s service) SetProxy(param SetProxyRequest) (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"Proxy": map[string]any{
"ProxyIp": fmt.Sprintf("%s:%d", param.Ip, param.Port),
"ProxyUser": param.Username,
@ -157,12 +155,12 @@ func (s service) SetProxy(param SetProxyRequest) (err error) {
// @param stepCount
// @return err
func (s service) SetStep(stepCount int) (err error) {
var result base.Response[base.EmptyResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{
"Wxid": s.robotInfo.GetId(),
"Wxid": core.WxId,
"StepCount": stepCount,
}).Post("/SetStep")
if err = result.CheckError(err); err != nil {

View File

@ -1,9 +1,6 @@
package user
import (
"gitee.ltd/lxh/xybot/core"
"github.com/go-resty/resty/v2"
)
import "github.com/go-resty/resty/v2"
type API interface {
GetMyQRCode() (str string, err error) // 获取个人二维码
@ -11,10 +8,9 @@ type API interface {
}
type service struct {
client *resty.Client
robotInfo *core.RobotInfo
client *resty.Client
}
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
return &service{client: client, robotInfo: robotInfo}
func New(client *resty.Client) API {
return &service{client: client}
}

View File

@ -2,6 +2,7 @@ package user
import (
"gitee.ltd/lxh/xybot/base"
"gitee.ltd/lxh/xybot/core"
)
// GetMyQRCode
@ -10,11 +11,11 @@ import (
// @return str string 图片的base64编码字符串
// @return err error 错误信息
func (s service) GetMyQRCode() (str string, err error) {
var result base.Response[GetMyQRCodeResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId(), "Style": 0}).
SetBody(map[string]any{"Wxid": core.WxId, "Style": 0}).
Post("/GetMyQRCode")
if err = result.CheckError(err); err != nil {
return
@ -29,11 +30,11 @@ func (s service) GetMyQRCode() (str string, err error) {
// @return resp 用户信息
// @return err
func (s service) GetProfile() (resp GetProfileResponse, err error) {
var result base.Response[GetProfileResponse]
_, err = s.client.R().
SetHeader("WeChatId", s.robotInfo.GetId()).
SetResult(&result).
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
SetBody(map[string]any{"Wxid": core.WxId}).
Post("/GetProfile")
if err = result.CheckError(err); err != nil {
return

View File

@ -69,10 +69,10 @@ type GetProfileResponse struct {
} `json:"userInfo"`
UserInfoExt struct {
SnsUserInfo struct {
SnsFlag int `json:"SnsFlag"`
SnsBgImgId string `json:"SnsBgimgId"` // 朋友圈背景图地址
SnsBgObjectId uint `json:"SnsBgobjectId"`
SnsFlagEx int `json:"SnsFlagEx"`
SnsFlag int `json:"SnsFlag"`
SnsBgImgId string `json:"SnsBgimgId"` // 朋友圈背景图地址
SnsBgObjectId float64 `json:"SnsBgobjectId"`
SnsFlagEx int `json:"SnsFlagEx"`
} `json:"SnsUserInfo"`
MyBrandList string `json:"MyBrandList"`
BigChatRoomSize int `json:"BigChatRoomSize"`