Compare commits
No commits in common. "main" and "v0.0.3" have entirely different histories.
26
client.go
26
client.go
@ -3,9 +3,6 @@ package xybot
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"slices"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitee.ltd/lxh/xybot/core"
|
"gitee.ltd/lxh/xybot/core"
|
||||||
"gitee.ltd/lxh/xybot/friend"
|
"gitee.ltd/lxh/xybot/friend"
|
||||||
"gitee.ltd/lxh/xybot/group"
|
"gitee.ltd/lxh/xybot/group"
|
||||||
@ -15,9 +12,13 @@ import (
|
|||||||
"gitee.ltd/lxh/xybot/tool"
|
"gitee.ltd/lxh/xybot/tool"
|
||||||
"gitee.ltd/lxh/xybot/user"
|
"gitee.ltd/lxh/xybot/user"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
// 基础URL
|
||||||
|
wxId string
|
||||||
// HTTP客户端
|
// HTTP客户端
|
||||||
httpClient *resty.Client
|
httpClient *resty.Client
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ func NewClient(wxId, baseUrl string, debug bool) (cli *Client, err error) {
|
|||||||
baseUrl = "http://" + baseUrl
|
baseUrl = "http://" + baseUrl
|
||||||
}
|
}
|
||||||
// 设置一下机器人微信Id的值
|
// 设置一下机器人微信Id的值
|
||||||
wxInfo := core.NewInfo(wxId)
|
core.WxId = wxId
|
||||||
|
|
||||||
cli = &Client{}
|
cli = &Client{}
|
||||||
cli.httpClient = resty.New().
|
cli.httpClient = resty.New().
|
||||||
@ -59,13 +60,13 @@ func NewClient(wxId, baseUrl string, debug bool) (cli *Client, err error) {
|
|||||||
SetJSONUnmarshaler(json.Unmarshal).
|
SetJSONUnmarshaler(json.Unmarshal).
|
||||||
OnBeforeRequest(requestPreCheck)
|
OnBeforeRequest(requestPreCheck)
|
||||||
|
|
||||||
cli.Login = login.New(cli.httpClient, wxInfo)
|
cli.Login = login.New(cli.httpClient)
|
||||||
cli.Friend = friend.New(cli.httpClient, wxInfo)
|
cli.Friend = friend.New(cli.httpClient)
|
||||||
cli.Group = group.New(cli.httpClient, wxInfo)
|
cli.Group = group.New(cli.httpClient)
|
||||||
cli.Message = message.New(cli.httpClient, wxInfo)
|
cli.Message = message.New(cli.httpClient)
|
||||||
cli.User = user.New(cli.httpClient, wxInfo)
|
cli.User = user.New(cli.httpClient)
|
||||||
cli.HongBao = hongbao.New(cli.httpClient, wxInfo)
|
cli.HongBao = hongbao.New(cli.httpClient)
|
||||||
cli.Tool = tool.New(cli.httpClient, wxInfo)
|
cli.Tool = tool.New(cli.httpClient)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -82,8 +83,7 @@ func requestPreCheck(_ *resty.Client, req *resty.Request) (err error) {
|
|||||||
// 如果是白名单请求,直接返回
|
// 如果是白名单请求,直接返回
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if core.WxId == "" {
|
||||||
if req.Header.Get("WeChatId") == "" {
|
|
||||||
// 如果WxId为空,直接返回
|
// 如果WxId为空,直接返回
|
||||||
return errors.New("wxId不能为空")
|
return errors.New("wxId不能为空")
|
||||||
}
|
}
|
||||||
|
31
core/info.go
31
core/info.go
@ -1,31 +1,4 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
// RobotInfo
|
// WxId 微信Id,将所有接口调用的wxId值都放到这儿来,方便判断是否可用
|
||||||
// @description: 机器人信息
|
var WxId = ""
|
||||||
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}
|
|
||||||
}
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package friend
|
package friend
|
||||||
|
|
||||||
import (
|
import "github.com/go-resty/resty/v2"
|
||||||
"gitee.ltd/lxh/xybot/core"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
AcceptFriend(scene int, v1, v2 string) (err error) // 接受好友请求
|
AcceptFriend(scene int, v1, v2 string) (err error) // 接受好友请求
|
||||||
@ -13,10 +10,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{client: client}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package friend
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"gitee.ltd/lxh/xybot/base"
|
"gitee.ltd/lxh/xybot/base"
|
||||||
|
"gitee.ltd/lxh/xybot/core"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -17,10 +18,9 @@ import (
|
|||||||
func (s service) AcceptFriend(scene int, v1, v2 string) (err error) {
|
func (s service) AcceptFriend(scene int, v1, v2 string) (err error) {
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Scene": scene,
|
"Scene": scene,
|
||||||
"V1": v1,
|
"V1": v1,
|
||||||
"V2": v2,
|
"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) {
|
func (s service) GetContact(wxIds []string) (contactList []ContactListItem, err error) {
|
||||||
var result base.Response[GetContactResponse]
|
var result base.Response[GetContactResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"RequestWxids": strings.Join(wxIds, ","),
|
"RequestWxids": strings.Join(wxIds, ","),
|
||||||
}).Post("/GetContact")
|
}).Post("/GetContact")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
@ -65,10 +64,9 @@ func (s service) GetContractDetail(wxIds []string) (contactList []ContactListIte
|
|||||||
|
|
||||||
var result base.Response[GetContactResponse]
|
var result base.Response[GetContactResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"RequestWxids": strings.Join(wxIds, ","),
|
"RequestWxids": strings.Join(wxIds, ","),
|
||||||
"Chatroom": "",
|
"Chatroom": "",
|
||||||
}).Post("/GetContractDetail")
|
}).Post("/GetContractDetail")
|
||||||
@ -88,10 +86,9 @@ func (s service) GetContractDetail(wxIds []string) (contactList []ContactListIte
|
|||||||
func (s service) GetContractList(clearSystemAccount bool) (wxIds []string, err error) {
|
func (s service) GetContractList(clearSystemAccount bool) (wxIds []string, err error) {
|
||||||
var result base.Response[GetContractListResponse]
|
var result base.Response[GetContractListResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"CurrentChatroomContactSeq": 0,
|
"CurrentChatroomContactSeq": 0,
|
||||||
"CurrentWxcontactSeq": 0,
|
"CurrentWxcontactSeq": 0,
|
||||||
}).Post("/GetContractList")
|
}).Post("/GetContractList")
|
||||||
|
@ -111,7 +111,7 @@ type ContactListItem struct {
|
|||||||
SmallHeadImgUrl string `json:"SmallHeadImgUrl"`
|
SmallHeadImgUrl string `json:"SmallHeadImgUrl"`
|
||||||
SnsUserInfo struct {
|
SnsUserInfo struct {
|
||||||
SnsBgImgId string `json:"SnsBgimgId"`
|
SnsBgImgId string `json:"SnsBgimgId"`
|
||||||
SnsBgObjectId uint `json:"SnsBgobjectId"`
|
SnsBgObjectId int `json:"SnsBgobjectId"`
|
||||||
SnsFlag int `json:"SnsFlag"`
|
SnsFlag int `json:"SnsFlag"`
|
||||||
SnsFlagEx int `json:"SnsFlagEx"`
|
SnsFlagEx int `json:"SnsFlagEx"`
|
||||||
} `json:"SnsUserInfo"`
|
} `json:"SnsUserInfo"`
|
||||||
|
12
group/api.go
12
group/api.go
@ -1,9 +1,6 @@
|
|||||||
package group
|
package group
|
||||||
|
|
||||||
import (
|
import "github.com/go-resty/resty/v2"
|
||||||
"gitee.ltd/lxh/xybot/core"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
AddChatroomMember(chatroom string, inviteWxId string) (err error) // 添加群聊成员(群聊最多40人)
|
AddChatroomMember(chatroom string, inviteWxId string) (err error) // 添加群聊成员(群聊最多40人)
|
||||||
@ -15,10 +12,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{client: client}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package group
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gitee.ltd/lxh/xybot/base"
|
"gitee.ltd/lxh/xybot/base"
|
||||||
|
"gitee.ltd/lxh/xybot/core"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,10 +15,9 @@ import (
|
|||||||
func (s service) AddChatroomMember(chatroom string, inviteWxId string) (err error) {
|
func (s service) AddChatroomMember(chatroom string, inviteWxId string) (err error) {
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
"InviteWxids": inviteWxId,
|
"InviteWxids": inviteWxId,
|
||||||
}).Post("/AddChatroomMember")
|
}).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) {
|
func (s service) InviteChatroomMember(chatroom string, inviteWxIds []string) (err error) {
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
"InviteWxids": strings.Join(inviteWxIds, ","),
|
"InviteWxids": strings.Join(inviteWxIds, ","),
|
||||||
}).Post("/InviteChatroomMember")
|
}).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) {
|
func (s service) GetChatroomInfo(chatroom string) (info GetChatroomInfoResponse, err error) {
|
||||||
var result base.Response[GetChatroomInfoResponse]
|
var result base.Response[GetChatroomInfoResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
}).Post("/GetChatroomInfo")
|
}).Post("/GetChatroomInfo")
|
||||||
if err = result.CheckError(err); err != nil {
|
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) {
|
func (s service) GetChatroomInfoNoAnnounce(chatroom []string) (info []ChatroomInfoItem, err error) {
|
||||||
var result base.Response[GetChatroomInfoNoAnnounce]
|
var result base.Response[GetChatroomInfoNoAnnounce]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Chatroom": strings.Join(chatroom, ","),
|
"Chatroom": strings.Join(chatroom, ","),
|
||||||
}).Post("/GetChatroomInfoNoAnnounce")
|
}).Post("/GetChatroomInfoNoAnnounce")
|
||||||
if err = result.CheckError(err); err != nil {
|
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) {
|
func (s service) GetChatroomMemberDetail(chatroom string) (members []ChatRoomMemberItem, err error) {
|
||||||
var result base.Response[GetChatroomMemberDetailResponse]
|
var result base.Response[GetChatroomMemberDetailResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
}).Post("/GetChatroomMemberDetail")
|
}).Post("/GetChatroomMemberDetail")
|
||||||
if err = result.CheckError(err); err != nil {
|
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) {
|
func (s service) GetChatroomQRCode(chatroom string) (imgBase64Str, notify string, err error) {
|
||||||
var result base.Response[GetChatroomQRCodeResponse]
|
var result base.Response[GetChatroomQRCodeResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
}).Post("/GetChatroomQRCode")
|
}).Post("/GetChatroomQRCode")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
|
@ -107,9 +107,9 @@ type ChatroomInfoItem struct {
|
|||||||
AlbumStyle int `json:"AlbumStyle"`
|
AlbumStyle int `json:"AlbumStyle"`
|
||||||
AlbumFlag int `json:"AlbumFlag"`
|
AlbumFlag int `json:"AlbumFlag"`
|
||||||
SnsUserInfo struct {
|
SnsUserInfo struct {
|
||||||
SnsFlag int `json:"SnsFlag"`
|
SnsFlag int `json:"SnsFlag"`
|
||||||
SnsBgobjectId uint `json:"SnsBgobjectId"`
|
SnsBgobjectId int `json:"SnsBgobjectId"`
|
||||||
SnsFlagEx int `json:"SnsFlagEx"`
|
SnsFlagEx int `json:"SnsFlagEx"`
|
||||||
} `json:"SnsUserInfo"`
|
} `json:"SnsUserInfo"`
|
||||||
SmallHeadImgUrl string `json:"SmallHeadImgUrl"` // 头像
|
SmallHeadImgUrl string `json:"SmallHeadImgUrl"` // 头像
|
||||||
CustomizedInfo struct {
|
CustomizedInfo struct {
|
||||||
|
@ -1,19 +1,15 @@
|
|||||||
package hongbao
|
package hongbao
|
||||||
|
|
||||||
import (
|
import "github.com/go-resty/resty/v2"
|
||||||
"gitee.ltd/lxh/xybot/core"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
GetHongBaoDetail(xml, encryptKey, encryptUserinfo string) (resp any, err error) // 获取红包详情
|
GetHongBaoDetail(xml, encryptKey, encryptUserinfo string) (resp any, err error) // 获取红包详情
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{client: client}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package hongbao
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gitee.ltd/lxh/xybot/base"
|
"gitee.ltd/lxh/xybot/base"
|
||||||
|
"gitee.ltd/lxh/xybot/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetHongBaoDetail
|
// GetHongBaoDetail
|
||||||
@ -13,12 +14,12 @@ import (
|
|||||||
// @return resp
|
// @return resp
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) GetHongBaoDetail(xml, encryptKey, encryptUserinfo string) (resp any, err error) {
|
func (s service) GetHongBaoDetail(xml, encryptKey, encryptUserinfo string) (resp any, err error) {
|
||||||
|
|
||||||
var result base.Response[any]
|
var result base.Response[any]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Xml": xml,
|
"Xml": xml,
|
||||||
"EncryptKey": encryptKey,
|
"EncryptKey": encryptKey,
|
||||||
"EncryptUserinfo": encryptUserinfo,
|
"EncryptUserinfo": encryptUserinfo,
|
||||||
|
12
login/api.go
12
login/api.go
@ -1,9 +1,6 @@
|
|||||||
package login
|
package login
|
||||||
|
|
||||||
import (
|
import "github.com/go-resty/resty/v2"
|
||||||
"gitee.ltd/lxh/xybot/core"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
GetQRCode(deviceId, deviceName string) (resp GetQRCodeResponse, err error) // 获取登录二维码
|
GetQRCode(deviceId, deviceName string) (resp GetQRCodeResponse, err error) // 获取登录二维码
|
||||||
@ -18,10 +15,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{client: client}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package login
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitee.ltd/lxh/xybot/base"
|
"gitee.ltd/lxh/xybot/base"
|
||||||
|
"gitee.ltd/lxh/xybot/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetQRCode
|
// GetQRCode
|
||||||
@ -34,11 +35,7 @@ func (s service) GetQRCode(deviceId, deviceName string) (resp GetQRCodeResponse,
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) AwakenLogin() (resp AwakenLoginResponse, err error) {
|
func (s service) AwakenLogin() (resp AwakenLoginResponse, err error) {
|
||||||
var result base.Response[AwakenLoginResponse]
|
var result base.Response[AwakenLoginResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AwakenLogin")
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
|
||||||
Post("/AwakenLogin")
|
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -65,7 +62,7 @@ func (s service) CheckUuid(uuid string) (resp CheckUuidResponse, err error) {
|
|||||||
resp = result.Data
|
resp = result.Data
|
||||||
// 这儿做一下处理,在登录成功之后更新一下wxId的值,免得再初始化一次client
|
// 这儿做一下处理,在登录成功之后更新一下wxId的值,免得再初始化一次client
|
||||||
if resp.AcctSectResp.Username != "" {
|
if resp.AcctSectResp.Username != "" {
|
||||||
s.robotInfo.SetId(resp.AcctSectResp.Username)
|
core.WxId = resp.AcctSectResp.Username
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -76,11 +73,7 @@ func (s service) CheckUuid(uuid string) (resp CheckUuidResponse, err error) {
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) AutoHeartbeatStart() (err error) {
|
func (s service) AutoHeartbeatStart() (err error) {
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AutoHeartbeatStart")
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
|
||||||
Post("/AutoHeartbeatStart")
|
|
||||||
err = result.CheckError(err)
|
err = result.CheckError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -92,11 +85,7 @@ func (s service) AutoHeartbeatStart() (err error) {
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) AutoHeartbeatStatus() (running bool, err error) {
|
func (s service) AutoHeartbeatStatus() (running bool, err error) {
|
||||||
var result AutoHeartbeatStatusResponse
|
var result AutoHeartbeatStatusResponse
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AutoHeartbeatStatus")
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
|
||||||
Post("/AutoHeartbeatStatus")
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if !result.Success {
|
if !result.Success {
|
||||||
err = fmt.Errorf("[%d] %s", result.Code, result.Message)
|
err = fmt.Errorf("[%d] %s", result.Code, result.Message)
|
||||||
@ -113,11 +102,7 @@ func (s service) AutoHeartbeatStatus() (running bool, err error) {
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) AutoHeartbeatStop() (err error) {
|
func (s service) AutoHeartbeatStop() (err error) {
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/AutoHeartbeatStop")
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
|
||||||
Post("/AutoHeartbeatStop")
|
|
||||||
err = result.CheckError(err)
|
err = result.CheckError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -128,11 +113,7 @@ func (s service) AutoHeartbeatStop() (err error) {
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) Heartbeat() (err error) {
|
func (s service) Heartbeat() (err error) {
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/Heartbeat")
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
|
||||||
Post("/Heartbeat")
|
|
||||||
err = result.CheckError(err)
|
err = result.CheckError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -144,11 +125,7 @@ func (s service) Heartbeat() (err error) {
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) GetCachedInfo() (resp GetCachedInfoResponse, err error) {
|
func (s service) GetCachedInfo() (resp GetCachedInfoResponse, err error) {
|
||||||
var result base.Response[GetCachedInfoResponse]
|
var result base.Response[GetCachedInfoResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/GetCachedInfo")
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
|
||||||
Post("/GetCachedInfo")
|
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -162,11 +139,7 @@ func (s service) GetCachedInfo() (resp GetCachedInfoResponse, err error) {
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) Logout() (err error) {
|
func (s service) Logout() (err error) {
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().SetResult(&result).SetBody(map[string]any{"Wxid": core.WxId}).Post("/Logout")
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
|
||||||
Post("/Logout")
|
|
||||||
err = result.CheckError(err)
|
err = result.CheckError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package message
|
package message
|
||||||
|
|
||||||
import (
|
import "github.com/go-resty/resty/v2"
|
||||||
"gitee.ltd/lxh/xybot/core"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int) (err error) // 撤回消息
|
RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int) (err error) // 撤回消息
|
||||||
@ -22,10 +19,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{client: client}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package message
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"gitee.ltd/lxh/xybot/base"
|
"gitee.ltd/lxh/xybot/base"
|
||||||
|
"gitee.ltd/lxh/xybot/core"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,12 +16,12 @@ import (
|
|||||||
// @param newMsgId int 返回消息的NewMsgId字段
|
// @param newMsgId int 返回消息的NewMsgId字段
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int) (err error) {
|
func (s service) RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int) (err error) {
|
||||||
|
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"ClientMsgId": clientMsgId,
|
"ClientMsgId": clientMsgId,
|
||||||
"CreateTime": createTime,
|
"CreateTime": createTime,
|
||||||
@ -41,12 +42,12 @@ func (s service) RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int)
|
|||||||
// @return newMsgId int 返回消息的NewMsgId字段
|
// @return newMsgId int 返回消息的NewMsgId字段
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendAppMsg(toWxId, xml string, appMsgType int) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendAppMsg(toWxId, xml string, appMsgType int) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Xml": xml,
|
"Xml": xml,
|
||||||
"Type": appMsgType,
|
"Type": appMsgType,
|
||||||
@ -70,12 +71,12 @@ func (s service) SendAppMsg(toWxId, xml string, appMsgType int) (clientMsgId, cr
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendCDNFileMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendCDNFileMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": xml,
|
"Content": xml,
|
||||||
}).Post("/SendCDNFileMsg")
|
}).Post("/SendCDNFileMsg")
|
||||||
@ -98,12 +99,12 @@ func (s service) SendCDNFileMsg(toWxId, xml string) (clientMsgId, createTime, ne
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendCDNImgMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendCDNImgMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": xml,
|
"Content": xml,
|
||||||
}).Post("/SendCDNImgMsg")
|
}).Post("/SendCDNImgMsg")
|
||||||
@ -126,12 +127,12 @@ func (s service) SendCDNImgMsg(toWxId, xml string) (clientMsgId, createTime, new
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendCDNVideoMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendCDNVideoMsg(toWxId, xml string) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": xml,
|
"Content": xml,
|
||||||
}).Post("/SendCDNVideoMsg")
|
}).Post("/SendCDNVideoMsg")
|
||||||
@ -156,12 +157,12 @@ func (s service) SendCDNVideoMsg(toWxId, xml string) (clientMsgId, createTime, n
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendCardMsg(toWxId, cardWxId, cardNickname, cardAlias string) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendCardMsg(toWxId, cardWxId, cardNickname, cardAlias string) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"CardWxid": cardWxId,
|
"CardWxid": cardWxId,
|
||||||
"CardNickname": cardNickname,
|
"CardNickname": cardNickname,
|
||||||
@ -185,12 +186,12 @@ func (s service) SendCardMsg(toWxId, cardWxId, cardNickname, cardAlias string) (
|
|||||||
// @return resp
|
// @return resp
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendEmojiMsg(toWxId, md5 string, length int) (resp any, err error) {
|
func (s service) SendEmojiMsg(toWxId, md5 string, length int) (resp any, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Md5": md5,
|
"Md5": md5,
|
||||||
"TotalLen": length,
|
"TotalLen": length,
|
||||||
@ -212,12 +213,12 @@ func (s service) SendEmojiMsg(toWxId, md5 string, length int) (resp any, err err
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendImageMsg(toWxId, imgBase64Str string) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendImageMsg(toWxId, imgBase64Str string) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Base64": imgBase64Str,
|
"Base64": imgBase64Str,
|
||||||
}).Post("/SendImageMsg")
|
}).Post("/SendImageMsg")
|
||||||
@ -243,12 +244,12 @@ func (s service) SendImageMsg(toWxId, imgBase64Str string) (clientMsgId, createT
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendShareLink(toWxId, url, title, description, thumbUrl string) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendShareLink(toWxId, url, title, description, thumbUrl string) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Url": url,
|
"Url": url,
|
||||||
"Title": title,
|
"Title": title,
|
||||||
@ -275,12 +276,12 @@ func (s service) SendShareLink(toWxId, url, title, description, thumbUrl string)
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendTextMsg(toWxId, content string, atUser []string) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendTextMsg(toWxId, content string, atUser []string) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": content,
|
"Content": content,
|
||||||
"Type": 1,
|
"Type": 1,
|
||||||
@ -307,12 +308,12 @@ func (s service) SendTextMsg(toWxId, content string, atUser []string) (clientMsg
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendVideoMsg(toWxId, video, cover string, duration int) (clientMsgId, createTime, newMsgId int, err error) {
|
func (s service) SendVideoMsg(toWxId, video, cover string, duration int) (clientMsgId, createTime, newMsgId int, err error) {
|
||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Base64": video,
|
"Base64": video,
|
||||||
"ImageBase64": cover,
|
"ImageBase64": cover,
|
||||||
@ -339,6 +340,7 @@ func (s service) SendVideoMsg(toWxId, video, cover string, duration int) (client
|
|||||||
// @return newMsgId
|
// @return newMsgId
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SendVoiceMsg(toWxId, voice, format string, duration int) (clientMsgId, createTime, newMsgId int, err error) {
|
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}
|
formatMap := map[string]int{"amr": 0, "wav": 4, "mp3": 4}
|
||||||
if _, ok := formatMap[format]; !ok {
|
if _, ok := formatMap[format]; !ok {
|
||||||
err = errors.New("不支持的语音格式")
|
err = errors.New("不支持的语音格式")
|
||||||
@ -347,10 +349,9 @@ func (s service) SendVoiceMsg(toWxId, voice, format string, duration int) (clien
|
|||||||
|
|
||||||
var result base.Response[SendMessageResponse]
|
var result base.Response[SendMessageResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Base64": voice,
|
"Base64": voice,
|
||||||
"VoiceTime": duration,
|
"VoiceTime": duration,
|
||||||
@ -371,12 +372,12 @@ func (s service) SendVoiceMsg(toWxId, voice, format string, duration int) (clien
|
|||||||
// @return msg
|
// @return msg
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) Sync() (msg []SyncMessage, err error) {
|
func (s service) Sync() (msg []SyncMessage, err error) {
|
||||||
|
|
||||||
var result base.Response[SyncResponse]
|
var result base.Response[SyncResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Scene": 0,
|
"Scene": 0,
|
||||||
"Synckey": "",
|
"Synckey": "",
|
||||||
}).Post("/Sync")
|
}).Post("/Sync")
|
||||||
|
12
tool/api.go
12
tool/api.go
@ -1,9 +1,6 @@
|
|||||||
package tool
|
package tool
|
||||||
|
|
||||||
import (
|
import "github.com/go-resty/resty/v2"
|
||||||
"gitee.ltd/lxh/xybot/core"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
CheckDatabaseOK() (running bool, err error) // 检查数据库是否正常
|
CheckDatabaseOK() (running bool, err error) // 检查数据库是否正常
|
||||||
@ -17,10 +14,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{client: client}
|
||||||
}
|
}
|
||||||
|
22
tool/impl.go
22
tool/impl.go
@ -3,6 +3,7 @@ package tool
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitee.ltd/lxh/xybot/base"
|
"gitee.ltd/lxh/xybot/base"
|
||||||
|
"gitee.ltd/lxh/xybot/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckDatabaseOK
|
// CheckDatabaseOK
|
||||||
@ -41,10 +42,9 @@ func (s service) IsRunning() (flag bool, err error) {
|
|||||||
func (s service) CdnDownloadImg(aesKey, cdnMidImgUrl string) (dataBase64Str string, err error) {
|
func (s service) CdnDownloadImg(aesKey, cdnMidImgUrl string) (dataBase64Str string, err error) {
|
||||||
var result base.Response[string]
|
var result base.Response[string]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"AesKey": aesKey,
|
"AesKey": aesKey,
|
||||||
"Cdnmidimgurl": cdnMidImgUrl,
|
"Cdnmidimgurl": cdnMidImgUrl,
|
||||||
}).Post("/CdnDownloadImg")
|
}).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) {
|
func (s service) DownloadAttach(attachId string) (dataBase64Str string, err error) {
|
||||||
var result base.Response[DownloadAttachResponse]
|
var result base.Response[DownloadAttachResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"AttachId": attachId,
|
"AttachId": attachId,
|
||||||
}).Post("/DownloadAttach")
|
}).Post("/DownloadAttach")
|
||||||
if err = result.CheckError(err); err != nil {
|
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]
|
var result base.Response[DownloadAttachResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"MsgId": msgId,
|
"MsgId": msgId,
|
||||||
}).Post("/DownloadVideo")
|
}).Post("/DownloadVideo")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
@ -109,12 +107,12 @@ func (s service) DownloadVideo(msgId int) (dataBase64Str string, err error) {
|
|||||||
// @return dataBase64Str
|
// @return dataBase64Str
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) DownloadVoice(msgId int, voiceUrl string, length int) (dataBase64Str string, err error) {
|
func (s service) DownloadVoice(msgId int, voiceUrl string, length int) (dataBase64Str string, err error) {
|
||||||
|
|
||||||
var result base.Response[DownloadAttachResponse]
|
var result base.Response[DownloadAttachResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"MsgId": msgId,
|
"MsgId": msgId,
|
||||||
"Voiceurl": voiceUrl,
|
"Voiceurl": voiceUrl,
|
||||||
"Length": length,
|
"Length": length,
|
||||||
@ -132,12 +130,12 @@ func (s service) DownloadVoice(msgId int, voiceUrl string, length int) (dataBase
|
|||||||
// @param param
|
// @param param
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SetProxy(param SetProxyRequest) (err error) {
|
func (s service) SetProxy(param SetProxyRequest) (err error) {
|
||||||
|
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"Proxy": map[string]any{
|
"Proxy": map[string]any{
|
||||||
"ProxyIp": fmt.Sprintf("%s:%d", param.Ip, param.Port),
|
"ProxyIp": fmt.Sprintf("%s:%d", param.Ip, param.Port),
|
||||||
"ProxyUser": param.Username,
|
"ProxyUser": param.Username,
|
||||||
@ -157,12 +155,12 @@ func (s service) SetProxy(param SetProxyRequest) (err error) {
|
|||||||
// @param stepCount
|
// @param stepCount
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) SetStep(stepCount int) (err error) {
|
func (s service) SetStep(stepCount int) (err error) {
|
||||||
|
|
||||||
var result base.Response[base.EmptyResponse]
|
var result base.Response[base.EmptyResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
"Wxid": s.robotInfo.GetId(),
|
"Wxid": core.WxId,
|
||||||
"StepCount": stepCount,
|
"StepCount": stepCount,
|
||||||
}).Post("/SetStep")
|
}).Post("/SetStep")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
|
12
user/api.go
12
user/api.go
@ -1,9 +1,6 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import "github.com/go-resty/resty/v2"
|
||||||
"gitee.ltd/lxh/xybot/core"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
GetMyQRCode() (str string, err error) // 获取个人二维码
|
GetMyQRCode() (str string, err error) // 获取个人二维码
|
||||||
@ -11,10 +8,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{client: client}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gitee.ltd/lxh/xybot/base"
|
"gitee.ltd/lxh/xybot/base"
|
||||||
|
"gitee.ltd/lxh/xybot/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetMyQRCode
|
// GetMyQRCode
|
||||||
@ -10,11 +11,11 @@ import (
|
|||||||
// @return str string 图片的base64编码字符串
|
// @return str string 图片的base64编码字符串
|
||||||
// @return err error 错误信息
|
// @return err error 错误信息
|
||||||
func (s service) GetMyQRCode() (str string, err error) {
|
func (s service) GetMyQRCode() (str string, err error) {
|
||||||
|
|
||||||
var result base.Response[GetMyQRCodeResponse]
|
var result base.Response[GetMyQRCodeResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId(), "Style": 0}).
|
SetBody(map[string]any{"Wxid": core.WxId, "Style": 0}).
|
||||||
Post("/GetMyQRCode")
|
Post("/GetMyQRCode")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
return
|
return
|
||||||
@ -29,11 +30,11 @@ func (s service) GetMyQRCode() (str string, err error) {
|
|||||||
// @return resp 用户信息
|
// @return resp 用户信息
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) GetProfile() (resp GetProfileResponse, err error) {
|
func (s service) GetProfile() (resp GetProfileResponse, err error) {
|
||||||
|
|
||||||
var result base.Response[GetProfileResponse]
|
var result base.Response[GetProfileResponse]
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{"Wxid": s.robotInfo.GetId()}).
|
SetBody(map[string]any{"Wxid": core.WxId}).
|
||||||
Post("/GetProfile")
|
Post("/GetProfile")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -69,10 +69,10 @@ type GetProfileResponse struct {
|
|||||||
} `json:"userInfo"`
|
} `json:"userInfo"`
|
||||||
UserInfoExt struct {
|
UserInfoExt struct {
|
||||||
SnsUserInfo struct {
|
SnsUserInfo struct {
|
||||||
SnsFlag int `json:"SnsFlag"`
|
SnsFlag int `json:"SnsFlag"`
|
||||||
SnsBgImgId string `json:"SnsBgimgId"` // 朋友圈背景图地址
|
SnsBgImgId string `json:"SnsBgimgId"` // 朋友圈背景图地址
|
||||||
SnsBgObjectId uint `json:"SnsBgobjectId"`
|
SnsBgObjectId float64 `json:"SnsBgobjectId"`
|
||||||
SnsFlagEx int `json:"SnsFlagEx"`
|
SnsFlagEx int `json:"SnsFlagEx"`
|
||||||
} `json:"SnsUserInfo"`
|
} `json:"SnsUserInfo"`
|
||||||
MyBrandList string `json:"MyBrandList"`
|
MyBrandList string `json:"MyBrandList"`
|
||||||
BigChatRoomSize int `json:"BigChatRoomSize"`
|
BigChatRoomSize int `json:"BigChatRoomSize"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user