Compare commits
No commits in common. "main" and "v0.0.1" have entirely different histories.
73
README.md
73
README.md
@ -1,5 +1,74 @@
|
|||||||
# 一个XYBotV2的Golang语言的Client封装
|
# 一个XYBotV2的Golang语言的Client封装
|
||||||
|
|
||||||
## 使用方法
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
参考example目录下的代码
|
import (
|
||||||
|
"fmt"
|
||||||
|
xybotclient "gitee.ltd/lxh/xybot"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// 创建客户端
|
||||||
|
client, err := xybotclient.NewClient("wxid_n5sg7tjup7f322", "http://10.0.0.78:9001", false)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("创建客户端失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查API是否在运行
|
||||||
|
isRunning, err := client.Tool.IsRunning()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("检查API是否运行失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isRunning {
|
||||||
|
log.Fatalf("微信API服务未启动")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("微信API服务已启动")
|
||||||
|
|
||||||
|
// 获取登录缓存信息
|
||||||
|
loginInfo, err := client.Login.GetCachedInfo()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("获取登录缓存信息失败: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("登录缓存信息: %+v\n", loginInfo)
|
||||||
|
|
||||||
|
// 获取好友列表
|
||||||
|
friends, err := client.Friend.GetContractList(true)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("获取好友列表失败: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("好友列表: %+v\n", friends)
|
||||||
|
|
||||||
|
// 获取群聊详情
|
||||||
|
chatroomInfo, err := client.Group.GetChatroomInfo("20675221672@chatroom")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("获取群聊详情失败: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("群聊详情: %+v\n", chatroomInfo)
|
||||||
|
|
||||||
|
// 获取不含公告的详情
|
||||||
|
chatroomInfoNoNotice, err := client.Group.GetChatroomInfoNoAnnounce([]string{"20675221672@chatroom"})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("获取不含公告的详情失败: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("不含公告的群聊详情: %+v\n", chatroomInfoNoNotice)
|
||||||
|
|
||||||
|
// 获取群聊成员详情
|
||||||
|
chatroomMemberInfo, err := client.Group.GetChatroomMemberDetail("20675221672@chatroom")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("获取群聊成员详情失败: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("群聊成员详情: %+v\n", chatroomMemberInfo)
|
||||||
|
|
||||||
|
// 获取一个二维码试试
|
||||||
|
qrCode, notifyStr, err := client.Group.GetChatroomQRCode("20675221672@chatroom")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("获取群聊二维码失败: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("群聊二维码: %s\n%s\n", qrCode, notifyStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
51
client.go
51
client.go
@ -3,10 +3,6 @@ package xybot
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"slices"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"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"
|
||||||
"gitee.ltd/lxh/xybot/hongbao"
|
"gitee.ltd/lxh/xybot/hongbao"
|
||||||
@ -18,6 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
// 基础URL
|
||||||
|
wxId string
|
||||||
// HTTP客户端
|
// HTTP客户端
|
||||||
httpClient *resty.Client
|
httpClient *resty.Client
|
||||||
|
|
||||||
@ -43,12 +41,10 @@ func NewClient(wxId, baseUrl string, debug bool) (cli *Client, err error) {
|
|||||||
err = errors.New("baseUrl 不得为空,格式为: http://10.0.0.11:9001")
|
err = errors.New("baseUrl 不得为空,格式为: http://10.0.0.11:9001")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 如果URL没有以http://或https://开头,自动添加http://
|
if wxId == "" {
|
||||||
if !strings.HasPrefix(baseUrl, "http://") && !strings.HasPrefix(baseUrl, "https://") {
|
err = errors.New("wxId 不得为空")
|
||||||
baseUrl = "http://" + baseUrl
|
return
|
||||||
}
|
}
|
||||||
// 设置一下机器人微信Id的值
|
|
||||||
wxInfo := core.NewInfo(wxId)
|
|
||||||
|
|
||||||
cli = &Client{}
|
cli = &Client{}
|
||||||
cli.httpClient = resty.New().
|
cli.httpClient = resty.New().
|
||||||
@ -56,36 +52,15 @@ func NewClient(wxId, baseUrl string, debug bool) (cli *Client, err error) {
|
|||||||
SetDebug(debug).
|
SetDebug(debug).
|
||||||
SetHeader("User-Agent", "lxh-xybot-client").
|
SetHeader("User-Agent", "lxh-xybot-client").
|
||||||
SetJSONMarshaler(json.Marshal).
|
SetJSONMarshaler(json.Marshal).
|
||||||
SetJSONUnmarshaler(json.Unmarshal).
|
SetJSONUnmarshaler(json.Unmarshal)
|
||||||
OnBeforeRequest(requestPreCheck)
|
|
||||||
|
|
||||||
cli.Login = login.New(cli.httpClient, wxInfo)
|
cli.Login = login.New(cli.httpClient, wxId)
|
||||||
cli.Friend = friend.New(cli.httpClient, wxInfo)
|
cli.Friend = friend.New(cli.httpClient, wxId)
|
||||||
cli.Group = group.New(cli.httpClient, wxInfo)
|
cli.Group = group.New(cli.httpClient, wxId)
|
||||||
cli.Message = message.New(cli.httpClient, wxInfo)
|
cli.Message = message.New(cli.httpClient, wxId)
|
||||||
cli.User = user.New(cli.httpClient, wxInfo)
|
cli.User = user.New(cli.httpClient, wxId)
|
||||||
cli.HongBao = hongbao.New(cli.httpClient, wxInfo)
|
cli.HongBao = hongbao.New(cli.httpClient, wxId)
|
||||||
cli.Tool = tool.New(cli.httpClient, wxInfo)
|
cli.Tool = tool.New(cli.httpClient, wxId)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// requestPreCheck
|
|
||||||
// @description: 请求前置检查
|
|
||||||
// @param _ *resty.Client
|
|
||||||
// @param req *resty.Request
|
|
||||||
// @return err error
|
|
||||||
func requestPreCheck(_ *resty.Client, req *resty.Request) (err error) {
|
|
||||||
// 在这儿判断指定请求地址的时候WxId是否有值
|
|
||||||
whiteUrls := []string{"/GetQRCode", "/CheckUuid", "/IsRunning", "/CheckDatabaseOK"}
|
|
||||||
if slices.Contains(whiteUrls, req.URL) {
|
|
||||||
// 如果是白名单请求,直接返回
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Header.Get("WeChatId") == "" {
|
|
||||||
// 如果WxId为空,直接返回
|
|
||||||
return errors.New("wxId不能为空")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
31
core/info.go
31
core/info.go
@ -1,31 +0,0 @@
|
|||||||
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}
|
|
||||||
}
|
|
@ -1,11 +1,9 @@
|
|||||||
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 {
|
||||||
|
SendFriendRequest(scene int, v1, v2, verifyContent string) (username string, err error) // 发送好友请求
|
||||||
AcceptFriend(scene int, v1, v2 string) (err error) // 接受好友请求
|
AcceptFriend(scene int, v1, v2 string) (err error) // 接受好友请求
|
||||||
GetContact(wxIds []string) (contactList []ContactListItem, err error) // 通过wxid获取联系人详情
|
GetContact(wxIds []string) (contactList []ContactListItem, err error) // 通过wxid获取联系人详情
|
||||||
GetContractDetail(wxIds []string) (contactList []ContactListItem, err error) // 获取联系人详情
|
GetContractDetail(wxIds []string) (contactList []ContactListItem, err error) // 获取联系人详情
|
||||||
@ -14,9 +12,12 @@ type API interface {
|
|||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
wxId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client, wxId string) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{
|
||||||
|
client: client,
|
||||||
|
wxId: wxId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,19 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SendFriendRequest
|
||||||
|
// @description: 发送好友请求
|
||||||
|
// @receiver s
|
||||||
|
// @param scene
|
||||||
|
// @param v1
|
||||||
|
// @param v2
|
||||||
|
// @param verifyContent
|
||||||
|
// @return username
|
||||||
|
// @return err
|
||||||
|
func (s service) SendFriendRequest(scene int, v1, v2, verifyContent string) (username string, err error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// AcceptFriend
|
// AcceptFriend
|
||||||
// @description: 接受好友请求
|
// @description: 接受好友请求
|
||||||
// @receiver s
|
// @receiver s
|
||||||
@ -17,10 +30,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": s.wxId,
|
||||||
"Scene": scene,
|
"Scene": scene,
|
||||||
"V1": v1,
|
"V1": v1,
|
||||||
"V2": v2,
|
"V2": v2,
|
||||||
@ -38,10 +50,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": s.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 +76,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": s.wxId,
|
||||||
"RequestWxids": strings.Join(wxIds, ","),
|
"RequestWxids": strings.Join(wxIds, ","),
|
||||||
"Chatroom": "",
|
"Chatroom": "",
|
||||||
}).Post("/GetContractDetail")
|
}).Post("/GetContractDetail")
|
||||||
@ -88,10 +98,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": s.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"`
|
||||||
|
14
group/api.go
14
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人)
|
||||||
@ -16,9 +13,12 @@ type API interface {
|
|||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
wxId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client, wxId string) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{
|
||||||
|
client: client,
|
||||||
|
wxId: wxId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,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": s.wxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
"InviteWxids": inviteWxId,
|
"InviteWxids": inviteWxId,
|
||||||
}).Post("/AddChatroomMember")
|
}).Post("/AddChatroomMember")
|
||||||
@ -34,10 +33,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": s.wxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
"InviteWxids": strings.Join(inviteWxIds, ","),
|
"InviteWxids": strings.Join(inviteWxIds, ","),
|
||||||
}).Post("/InviteChatroomMember")
|
}).Post("/InviteChatroomMember")
|
||||||
@ -54,10 +52,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": s.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 +73,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": s.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 +94,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": s.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 +116,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": s.wxId,
|
||||||
"Chatroom": chatroom,
|
"Chatroom": chatroom,
|
||||||
}).Post("/GetChatroomQRCode")
|
}).Post("/GetChatroomQRCode")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
|
@ -108,7 +108,7 @@ type ChatroomInfoItem struct {
|
|||||||
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"` // 头像
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
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) // 获取红包详情
|
||||||
@ -11,9 +8,12 @@ type API interface {
|
|||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
wxId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client, wxId string) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{
|
||||||
|
client: client,
|
||||||
|
wxId: wxId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package hongbao
|
package hongbao
|
||||||
|
|
||||||
import (
|
import "gitee.ltd/lxh/xybot/base"
|
||||||
"gitee.ltd/lxh/xybot/base"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetHongBaoDetail
|
// GetHongBaoDetail
|
||||||
// @description: 获取红包详情
|
// @description: 获取红包详情
|
||||||
@ -15,10 +13,9 @@ import (
|
|||||||
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": s.wxId,
|
||||||
"Xml": xml,
|
"Xml": xml,
|
||||||
"EncryptKey": encryptKey,
|
"EncryptKey": encryptKey,
|
||||||
"EncryptUserinfo": encryptUserinfo,
|
"EncryptUserinfo": encryptUserinfo,
|
||||||
|
14
login/api.go
14
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) // 获取登录二维码
|
||||||
@ -19,9 +16,12 @@ type API interface {
|
|||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
wxId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client, wxId string) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{
|
||||||
|
client: client,
|
||||||
|
wxId: wxId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
// @return err
|
// @return err
|
||||||
func (s service) GetQRCode(deviceId, deviceName string) (resp GetQRCodeResponse, err error) {
|
func (s service) GetQRCode(deviceId, deviceName string) (resp GetQRCodeResponse, err error) {
|
||||||
var result base.Response[GetQRCodeResponse]
|
var result base.Response[GetQRCodeResponse]
|
||||||
|
|
||||||
_, err = s.client.R().
|
_, err = s.client.R().
|
||||||
SetResult(&result).
|
SetResult(&result).
|
||||||
SetBody(map[string]any{
|
SetBody(map[string]any{
|
||||||
@ -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": s.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
|
||||||
}
|
}
|
||||||
@ -63,10 +60,6 @@ func (s service) CheckUuid(uuid string) (resp CheckUuidResponse, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp = result.Data
|
resp = result.Data
|
||||||
// 这儿做一下处理,在登录成功之后更新一下wxId的值,免得再初始化一次client
|
|
||||||
if resp.AcctSectResp.Username != "" {
|
|
||||||
s.robotInfo.SetId(resp.AcctSectResp.Username)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,11 +69,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": s.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 +81,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": s.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 +98,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": s.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 +109,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": s.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 +121,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": s.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 +135,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": s.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) // 撤回消息
|
||||||
@ -23,9 +20,12 @@ type API interface {
|
|||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
wxId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client, wxId string) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{
|
||||||
|
client: client,
|
||||||
|
wxId: wxId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,9 @@ import (
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"ClientMsgId": clientMsgId,
|
"ClientMsgId": clientMsgId,
|
||||||
"CreateTime": createTime,
|
"CreateTime": createTime,
|
||||||
@ -43,10 +42,9 @@ func (s service) RevokeMsg(toWxId string, clientMsgId, createTime, newMsgId int)
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Xml": xml,
|
"Xml": xml,
|
||||||
"Type": appMsgType,
|
"Type": appMsgType,
|
||||||
@ -72,10 +70,9 @@ func (s service) SendAppMsg(toWxId, xml string, appMsgType int) (clientMsgId, cr
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": xml,
|
"Content": xml,
|
||||||
}).Post("/SendCDNFileMsg")
|
}).Post("/SendCDNFileMsg")
|
||||||
@ -100,10 +97,9 @@ func (s service) SendCDNFileMsg(toWxId, xml string) (clientMsgId, createTime, ne
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": xml,
|
"Content": xml,
|
||||||
}).Post("/SendCDNImgMsg")
|
}).Post("/SendCDNImgMsg")
|
||||||
@ -128,10 +124,9 @@ func (s service) SendCDNImgMsg(toWxId, xml string) (clientMsgId, createTime, new
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": xml,
|
"Content": xml,
|
||||||
}).Post("/SendCDNVideoMsg")
|
}).Post("/SendCDNVideoMsg")
|
||||||
@ -158,10 +153,9 @@ func (s service) SendCDNVideoMsg(toWxId, xml string) (clientMsgId, createTime, n
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"CardWxid": cardWxId,
|
"CardWxid": cardWxId,
|
||||||
"CardNickname": cardNickname,
|
"CardNickname": cardNickname,
|
||||||
@ -187,10 +181,9 @@ func (s service) SendCardMsg(toWxId, cardWxId, cardNickname, cardAlias string) (
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Md5": md5,
|
"Md5": md5,
|
||||||
"TotalLen": length,
|
"TotalLen": length,
|
||||||
@ -214,10 +207,9 @@ func (s service) SendEmojiMsg(toWxId, md5 string, length int) (resp any, err 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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Base64": imgBase64Str,
|
"Base64": imgBase64Str,
|
||||||
}).Post("/SendImageMsg")
|
}).Post("/SendImageMsg")
|
||||||
@ -245,10 +237,9 @@ func (s service) SendImageMsg(toWxId, imgBase64Str string) (clientMsgId, createT
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Url": url,
|
"Url": url,
|
||||||
"Title": title,
|
"Title": title,
|
||||||
@ -277,10 +268,9 @@ func (s service) SendShareLink(toWxId, url, title, description, thumbUrl string)
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Content": content,
|
"Content": content,
|
||||||
"Type": 1,
|
"Type": 1,
|
||||||
@ -309,10 +299,9 @@ func (s service) SendTextMsg(toWxId, content string, atUser []string) (clientMsg
|
|||||||
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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Base64": video,
|
"Base64": video,
|
||||||
"ImageBase64": cover,
|
"ImageBase64": cover,
|
||||||
@ -347,10 +336,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": s.wxId,
|
||||||
"ToWxid": toWxId,
|
"ToWxid": toWxId,
|
||||||
"Base64": voice,
|
"Base64": voice,
|
||||||
"VoiceTime": duration,
|
"VoiceTime": duration,
|
||||||
@ -373,10 +361,9 @@ func (s service) SendVoiceMsg(toWxId, voice, format string, duration int) (clien
|
|||||||
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": s.wxId,
|
||||||
"Scene": 0,
|
"Scene": 0,
|
||||||
"Synckey": "",
|
"Synckey": "",
|
||||||
}).Post("/Sync")
|
}).Post("/Sync")
|
||||||
|
14
tool/api.go
14
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) // 检查数据库是否正常
|
||||||
@ -18,9 +15,12 @@ type API interface {
|
|||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
wxId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client, wxId string) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{
|
||||||
|
client: client,
|
||||||
|
wxId: wxId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
19
tool/impl.go
19
tool/impl.go
@ -41,10 +41,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": s.wxId,
|
||||||
"AesKey": aesKey,
|
"AesKey": aesKey,
|
||||||
"Cdnmidimgurl": cdnMidImgUrl,
|
"Cdnmidimgurl": cdnMidImgUrl,
|
||||||
}).Post("/CdnDownloadImg")
|
}).Post("/CdnDownloadImg")
|
||||||
@ -64,10 +63,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": s.wxId,
|
||||||
"AttachId": attachId,
|
"AttachId": attachId,
|
||||||
}).Post("/DownloadAttach")
|
}).Post("/DownloadAttach")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
@ -84,13 +82,11 @@ func (s service) DownloadAttach(attachId string) (dataBase64Str string, err erro
|
|||||||
// @return dataBase64Str
|
// @return dataBase64Str
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) DownloadVideo(msgId int) (dataBase64Str string, err error) {
|
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": s.wxId,
|
||||||
"MsgId": msgId,
|
"MsgId": msgId,
|
||||||
}).Post("/DownloadVideo")
|
}).Post("/DownloadVideo")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
@ -111,10 +107,9 @@ func (s service) DownloadVideo(msgId int) (dataBase64Str string, err error) {
|
|||||||
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": s.wxId,
|
||||||
"MsgId": msgId,
|
"MsgId": msgId,
|
||||||
"Voiceurl": voiceUrl,
|
"Voiceurl": voiceUrl,
|
||||||
"Length": length,
|
"Length": length,
|
||||||
@ -134,10 +129,9 @@ func (s service) DownloadVoice(msgId int, voiceUrl string, length int) (dataBase
|
|||||||
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": s.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,
|
||||||
@ -159,10 +153,9 @@ func (s service) SetProxy(param SetProxyRequest) (err error) {
|
|||||||
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": s.wxId,
|
||||||
"StepCount": stepCount,
|
"StepCount": stepCount,
|
||||||
}).Post("/SetStep")
|
}).Post("/SetStep")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
|
16
user/api.go
16
user/api.go
@ -1,20 +1,20 @@
|
|||||||
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) // 获取个人二维码
|
||||||
GetProfile() (resp GetProfileResponse, err error) // 获取个人信息
|
GetProfile() (resp any, err error) // 获取个人信息
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
robotInfo *core.RobotInfo
|
wxId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *resty.Client, robotInfo *core.RobotInfo) API {
|
func New(client *resty.Client, wxId string) API {
|
||||||
return &service{client: client, robotInfo: robotInfo}
|
return &service{
|
||||||
|
client: client,
|
||||||
|
wxId: wxId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
20
user/impl.go
20
user/impl.go
@ -1,8 +1,6 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import "gitee.ltd/lxh/xybot/base"
|
||||||
"gitee.ltd/lxh/xybot/base"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetMyQRCode
|
// GetMyQRCode
|
||||||
// @description: 获取个人二维码
|
// @description: 获取个人二维码
|
||||||
@ -12,9 +10,8 @@ import (
|
|||||||
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": s.wxId, "Style": 0}).
|
||||||
Post("/GetMyQRCode")
|
Post("/GetMyQRCode")
|
||||||
if err = result.CheckError(err); err != nil {
|
if err = result.CheckError(err); err != nil {
|
||||||
return
|
return
|
||||||
@ -28,17 +25,6 @@ func (s service) GetMyQRCode() (str string, err error) {
|
|||||||
// @receiver s
|
// @receiver s
|
||||||
// @return resp 用户信息
|
// @return resp 用户信息
|
||||||
// @return err
|
// @return err
|
||||||
func (s service) GetProfile() (resp GetProfileResponse, err error) {
|
func (s service) GetProfile() (resp any, 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()}).
|
|
||||||
Post("/GetProfile")
|
|
||||||
if err = result.CheckError(err); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = result.Data
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ type GetProfileResponse 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"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user