openwechat

package module
v0.0.0-...-88e4205 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

README

openwechat

Go Doc Release Go Report Card Stars Forks Sourcegraph

golang版个人微信号API, 突破登录限制,类似开发公众号一样,开发个人微信号

微信机器人😈,利用微信号完成一些功能的定制化开发⭐

  • 模块简单易用,易于扩展
  • 支持定制化开发,如日志记录,自动回复
  • 突破登录限制📣
  • 无需重复扫码登录
  • 支持多个微信号同时登陆
安装
go get -u github.com/eatmoreapple/openwechat
快速开始
package main

import (
	"fmt"
	"github.com/eatmoreapple/openwechat"
)

func main() {
	bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式

	// 注册消息处理函数
	bot.MessageHandler = func(msg *openwechat.Message) {
		if msg.IsText() && msg.Content == "ping" {
			msg.ReplyText("pong")
		}
	}
	// 注册登陆二维码回调
	bot.UUIDCallback = openwechat.PrintlnQrcodeUrl

	// 登陆
	if err := bot.Login(); err != nil {
		fmt.Println(err)
		return
	}

	// 获取登陆的用户
	self, err := bot.GetCurrentUser()
	if err != nil {
		fmt.Println(err)
		return
	}

	// 获取所有的好友
	friends, err := self.Friends()
	fmt.Println(friends, err)

	// 获取所有的群组
	groups, err := self.Groups()
	fmt.Println(groups, err)

	// 阻塞主goroutine, 直到发生异常或者用户主动退出
	bot.Block()
}
支持功能
  • 消息回复、给指定对象(好友、群组)发送文本、图片、文件、emoji表情等消息
  • 热登陆(无需重复扫码登录)、自定义消息处理、文件下载、消息防撤回
  • 获取对象信息、设置好友备注、拉好友进群等
  • 更多功能请查看文档
文档

点击查看

项目主页

https://github.com/eatmoreapple/openwechat

Thanks

JetBrains

添加微信(eatmoreapple)🍎(备注: openwechat),进群交流😈

** 如果喜欢的话,可以请作者吃包辣条。谢谢支持 😄 **

Documentation

Index

Examples

Constants

View Source
const (
	MALE   = 1
	FEMALE = 2
)

性别

View Source
const ALL = 0

ALL 跟search函数搭配

friends.Search(openwechat.ALL, )
View Source
const (
	AppMessage = 6
)

消息类型

View Source
const FileHelper = "filehelper"

FileHelper 文件传输助手

View Source
const TimeFormat = "Mon Jan 02 2006 15:04:05 GMT+0800 (中国标准时间)"

Variables

View Source
var (
	// Normal 网页版微信模式
	Normal = withMode(normal)

	// Desktop 桌面微信模式
	Desktop = withMode(desktop)
)

btw, 这两个变量已经变了4回了, 但是为了兼容以前的代码, 还是得想着法儿让用户无感知的更新

View Source
var (
	// ErrForbidden 禁止当前账号登录
	ErrForbidden = errors.New("login forbidden")

	// ErrInvalidStorage define invalid storage error
	ErrInvalidStorage = errors.New("invalid storage")

	// NetworkErr define wechat network error
	NetworkErr = errors.New("wechat network error")

	// ErrNoSuchUserFoundError define no such user found error
	ErrNoSuchUserFoundError = errors.New("no such user found")

	// ErrLoginTimeout define login timeout error
	ErrLoginTimeout = errors.New("login timeout")

	// ErrWebWxDataTicketNotFound define webwx_data_ticket not found error
	ErrWebWxDataTicketNotFound = errors.New("webwx_data_ticket not found")

	// ErrUserLogout define user logout error
	ErrUserLogout = errors.New("user logout")
)
View Source
var DoNothingBotLoginOption = &BaseBotLoginOption{}

DoNothingBotLoginOption 是一个空的 BotLoginOption,表示不做任何操作

View Source
var Emoji = struct {
	Smile        string
	Grimace      string
	Drool        string
	Scowl        string
	CoolGuy      string
	Sob          string
	Shy          string
	Silent       string
	Sleep        string
	Cry          string
	Awkward      string
	Angry        string
	Tongue       string
	Grin         string
	Surprise     string
	Frown        string
	Ruthless     string
	Blush        string
	Scream       string
	Puke         string
	Chuckle      string
	Joyful       string
	Slight       string
	Smug         string
	Hungry       string
	Drowsy       string
	Panic        string
	Sweat        string
	Laugh        string
	Commando     string
	Determined   string
	Scold        string
	Shocked      string
	Shhh         string
	Dizzy        string
	Tormented    string
	Toasted      string
	Skull        string
	Hammer       string
	Wave         string
	Speechless   string
	NosePick     string
	Clap         string
	Shame        string
	Trick        string
	BahL         string
	BahR         string
	Yawn         string
	PoohPooh     string
	Shrunken     string
	TearingUp    string
	Sly          string
	Kiss         string
	Wrath        string
	Whimper      string
	Cleaver      string
	Watermelon   string
	Beer         string
	Basketball   string
	PingPong     string
	Coffee       string
	Rice         string
	Pig          string
	Rose         string
	Wilt         string
	Lips         string
	Heart        string
	BrokenHeart  string
	Cake         string
	Lightning    string
	Bomb         string
	Dagger       string
	Soccer       string
	Ladybug      string
	Poop         string
	Moon         string
	Sun          string
	Gift         string
	Hug          string
	ThumbsUp     string
	ThumbsDown   string
	Shake        string
	Peace        string
	Fight        string
	Beckon       string
	Fist         string
	Pinky        string
	RockOn       string
	Nuhuh        string
	OK           string
	InLove       string
	Blowkiss     string
	Waddle       string
	Tremble      string
	Aaagh        string
	Twirl        string
	Kotow        string
	Dramatic     string
	JumpRope     string
	Surrender    string
	Hooray       string
	Meditate     string
	Smooch       string
	TaiChiL      string
	TaiChiR      string
	Hey          string
	Facepalm     string
	Smirk        string
	Smart        string
	Moue         string
	Yeah         string
	Tea          string
	Packet       string
	Candle       string
	Blessing     string
	Chick        string
	Onlooker     string
	GoForIt      string
	Sweats       string
	OMG          string
	Emm          string
	Respect      string
	Doge         string
	NoProb       string
	MyBad        string
	KeepFighting string
	Wow          string
	Rich         string
	Broken       string
	Hurt         string
	Sigh         string
	LetMeSee     string
	Awesome      string
	Boring       string

}{}/* 134 elements not displayed */

Emoji 表情 字段太多了,污染命名空间,封装成struct返回

Functions

func FormatEmoji

func FormatEmoji(text string) string

func GetFileContentType

func GetFileContentType(file io.Reader) (string, error)

GetFileContentType 获取文件上传的类型

func GetQrcodeUrl

func GetQrcodeUrl(uuid string) string

GetQrcodeUrl 通过uuid获取登录二维码的url

func GetRandomDeviceId

func GetRandomDeviceId() string

GetRandomDeviceId 获取随机设备id

func IgnoreNetworkError

func IgnoreNetworkError(errHandler func(err error)) func(error)

IgnoreNetworkError 忽略网络请求的错误

func IsNetworkError

func IsNetworkError(err error) bool

func NewFileAppMessage

func NewFileAppMessage(stat os.FileInfo, attachId string) *appmsg

func NewFileHotReloadStorage

func NewFileHotReloadStorage(filename string) io.ReadWriteCloser

NewFileHotReloadStorage implements HotReloadStorage

func NewJsonFileHotReloadStorage deprecated

func NewJsonFileHotReloadStorage(filename string) io.ReadWriteCloser

Deprecated: use NewFileHotReloadStorage instead 不再单纯以json的格式存储,支持了用户自定义序列化方式

func PrintlnQrcodeUrl

func PrintlnQrcodeUrl(uuid string)

PrintlnQrcodeUrl 打印登录二维码

Types

type AppMessageData

type AppMessageData struct {
	XMLName xml.Name `xml:"msg"`
	AppMsg  struct {
		Appid             string         `xml:"appid,attr"`
		SdkVer            string         `xml:"sdkver,attr"`
		Title             string         `xml:"title"`
		Des               string         `xml:"des"`
		Action            string         `xml:"action"`
		Type              AppMessageType `xml:"type"`
		ShowType          string         `xml:"showtype"`
		Content           string         `xml:"content"`
		URL               string         `xml:"url"`
		DataUrl           string         `xml:"dataurl"`
		LowUrl            string         `xml:"lowurl"`
		LowDataUrl        string         `xml:"lowdataurl"`
		RecordItem        string         `xml:"recorditem"`
		ThumbUrl          string         `xml:"thumburl"`
		MessageAction     string         `xml:"messageaction"`
		Md5               string         `xml:"md5"`
		ExtInfo           string         `xml:"extinfo"`
		SourceUsername    string         `xml:"sourceusername"`
		SourceDisplayName string         `xml:"sourcedisplayname"`
		CommentUrl        string         `xml:"commenturl"`
		AppAttach         struct {
			TotalLen          string `xml:"totallen"`
			AttachId          string `xml:"attachid"`
			EmoticonMd5       string `xml:"emoticonmd5"`
			FileExt           string `xml:"fileext"`
			FileUploadToken   string `xml:"fileuploadtoken"`
			OverwriteNewMsgId string `xml:"overwrite_newmsgid"`
			FileKey           string `xml:"filekey"`
			CdnAttachUrl      string `xml:"cdnattachurl"`
			AesKey            string `xml:"aeskey"`
			EncryVer          string `xml:"encryver"`
		} `xml:"appattach"`
		WeAppInfo struct {
			PagePath       string `xml:"pagepath"`
			Username       string `xml:"username"`
			Appid          string `xml:"appid"`
			AppServiceType string `xml:"appservicetype"`
		} `xml:"weappinfo"`
		WebSearch string `xml:"websearch"`
	} `xml:"appmsg"`
	FromUsername string `xml:"fromusername"`
	Scene        string `xml:"scene"`
	AppInfo      struct {
		Version string `xml:"version"`
		AppName string `xml:"appname"`
	} `xml:"appinfo"`
	CommentUrl string `xml:"commenturl"`
}

AppMessageData 获取APP消息的正文 See https://github.com/eatmoreapple/openwechat/issues/62

func (*AppMessageData) IsArticle

func (a *AppMessageData) IsArticle() bool

IsArticle 判断当前的消息类型是否为文章

func (AppMessageData) IsFile

func (a AppMessageData) IsFile() bool

IsFile 判断当前的消息类型是否为文件

func (*AppMessageData) IsFromApplet

func (a *AppMessageData) IsFromApplet() bool

IsFromApplet 判断当前的消息类型是否来自小程序

type AppMessageType

type AppMessageType int

AppMessageType 以Go惯用形式定义了PC微信所有的官方App消息类型。

const (
	AppMsgTypeText                  AppMessageType = 1      // 文本消息
	AppMsgTypeImg                   AppMessageType = 2      // 图片消息
	AppMsgTypeAudio                 AppMessageType = 3      // 语音消息
	AppMsgTypeVideo                 AppMessageType = 4      // 视频消息
	AppMsgTypeUrl                   AppMessageType = 5      // 文章消息
	AppMsgTypeAttach                AppMessageType = 6      // 附件消息
	AppMsgTypeOpen                  AppMessageType = 7      // Open
	AppMsgTypeEmoji                 AppMessageType = 8      // 表情消息
	AppMsgTypeVoiceRemind           AppMessageType = 9      // VoiceRemind
	AppMsgTypeScanGood              AppMessageType = 10     // ScanGood
	AppMsgTypeGood                  AppMessageType = 13     // Good
	AppMsgTypeEmotion               AppMessageType = 15     // Emotion
	AppMsgTypeCardTicket            AppMessageType = 16     // 名片消息
	AppMsgTypeRealtimeShareLocation AppMessageType = 17     // 地理位置消息
	AppMsgTypeTransfers             AppMessageType = 2000   // 转账消息
	AppMsgTypeRedEnvelopes          AppMessageType = 2001   // 红包消息
	AppMsgTypeReaderType            AppMessageType = 100001 //自定义的消息
)

func (AppMessageType) String

func (i AppMessageType) String() string

type BaseBotLoginOption

type BaseBotLoginOption struct{}

func (BaseBotLoginOption) OnError

func (BaseBotLoginOption) OnError(_ *Bot, err error) error

func (BaseBotLoginOption) OnSuccess

func (BaseBotLoginOption) OnSuccess(_ *Bot) error

func (BaseBotLoginOption) Prepare

func (BaseBotLoginOption) Prepare(_ *Bot)

type BaseRequest

type BaseRequest struct {
	Uin                 int64
	Sid, Skey, DeviceID string
}

BaseRequest 初始的请求信息 几乎所有的请求都要携带该参数

type BaseResponse

type BaseResponse struct {
	Ret    Ret
	ErrMsg string
}

BaseResponse 大部分返回对象都携带该信息

func (BaseResponse) Err

func (b BaseResponse) Err() error

func (BaseResponse) Ok

func (b BaseResponse) Ok() bool

type Bot

type Bot struct {
	ScanCallBack        func(body CheckLoginResponse) // 扫码回调,可获取扫码用户的头像
	LoginCallBack       func(body CheckLoginResponse) // 登陆回调
	LogoutCallBack      func(bot *Bot)                // 退出回调
	UUIDCallback        func(uuid string)             // 获取UUID的回调函数
	SyncCheckCallback   func(resp SyncCheckResponse)  // 心跳回调
	MessageHandler      MessageHandler                // 获取消息成功的handle
	MessageErrorHandler MessageErrorHandler           // 获取消息发生错误的handle, 返回err == nil 则尝试继续监听
	Serializer          Serializer                    // 序列化器, 默认为json
	Caller              *Caller
	Storage             *Session
	// contains filtered or unexported fields
}

func Default

func Default(prepares ...BotPreparer) *Bot

func DefaultBot

func DefaultBot(prepares ...BotPreparer) *Bot

DefaultBot 默认的Bot的构造方法, mode不传入默认为 openwechat.Normal,详情见mode

bot := openwechat.DefaultBot(openwechat.Desktop)

func New

func New(ctx context.Context) *Bot

func NewBot

func NewBot(c context.Context) *Bot

NewBot Bot的构造方法 接收外部的 context.Context,用于控制Bot的存活

func (*Bot) Alive

func (b *Bot) Alive() bool

Alive 判断当前用户是否正常在线

func (*Bot) Block

func (b *Bot) Block() error

Block 当消息同步发生了错误或者用户主动在手机上退出,该方法会立即返回,否则会一直阻塞

func (*Bot) Context

func (b *Bot) Context() context.Context

Context returns current context of bot

func (*Bot) CrashReason

func (b *Bot) CrashReason() error

CrashReason 获取当前Bot崩溃的原因

func (*Bot) DumpHotReloadStorage

func (b *Bot) DumpHotReloadStorage() error

DumpHotReloadStorage 写入HotReloadStorage

func (*Bot) DumpTo

func (b *Bot) DumpTo(writer io.Writer) error

DumpTo 将热登录需要的数据写入到指定的 io.Writer 中 注: 写之前最好先清空之前的数据

func (*Bot) Exit

func (b *Bot) Exit()

Exit 主动退出,让 Block 不在阻塞

func (*Bot) ExitWith

func (b *Bot) ExitWith(err error)

ExitWith 主动退出并且设置退出原因, 可以通过 `CrashReason` 获取退出原因

func (*Bot) GetCurrentUser

func (b *Bot) GetCurrentUser() (*Self, error)

GetCurrentUser 获取当前的用户

self, err := bot.GetCurrentUser()
if err != nil {
	return
}
fmt.Println(self.NickName)

func (*Bot) HotLogin

func (b *Bot) HotLogin(storage HotReloadStorage, opts ...BotLoginOption) error

HotLogin 热登录,可实现在单位时间内免重复扫码登录 热登录需要先扫码登录一次才可以进行热登录

func (*Bot) IsHot

func (b *Bot) IsHot() bool

IsHot returns true if is hot login otherwise false

func (*Bot) Login

func (b *Bot) Login() error

Login 用户登录

func (*Bot) Logout

func (b *Bot) Logout() error

Logout 用户退出

func (*Bot) PushLogin

func (b *Bot) PushLogin(storage HotReloadStorage, opts ...BotLoginOption) error

PushLogin 免扫码登录 免扫码登录需要先扫码登录一次才可以进行扫码登录

func (*Bot) UUID

func (b *Bot) UUID() string

UUID returns current UUID of bot

type BotLogin

type BotLogin interface {
	Login(bot *Bot) error
}

BotLogin 定义了一个Login的接口

type BotLoginOption

type BotLoginOption interface {
	BotPreparer
	OnError(*Bot, error) error
	OnSuccess(*Bot) error
}

func HotLoginWithRetry deprecated

func HotLoginWithRetry(flag bool) BotLoginOption

Deprecated: 请使用 NewRetryLoginOption 代替 HotLoginWithRetry 热登录模式,如果登录失败会重试

func NewRetryLoginOption

func NewRetryLoginOption() BotLoginOption

func PushLoginWithRetry deprecated

func PushLoginWithRetry(flag bool) BotLoginOption

Deprecated: 请使用 NewRetryLoginOption 代替 PushLoginWithRetry 免扫码登录模式,如果登录失败会重试

type BotOptionGroup

type BotOptionGroup []BotLoginOption

BotOptionGroup 是一个 BotLoginOption 的集合 用于将多个 BotLoginOption 组合成一个 BotLoginOption

func (BotOptionGroup) OnError

func (g BotOptionGroup) OnError(b *Bot, err error) error

OnError 实现了 BotLoginOption 接口

func (BotOptionGroup) OnSuccess

func (g BotOptionGroup) OnSuccess(b *Bot) error

OnSuccess 实现了 BotLoginOption 接口

func (BotOptionGroup) Prepare

func (g BotOptionGroup) Prepare(bot *Bot)

Prepare 实现了 BotLoginOption 接口

type BotPreparer

type BotPreparer interface {
	Prepare(*Bot)
}

func WithContextOption

func WithContextOption(ctx context.Context) BotPreparer

WithContextOption 是一个 BotPreparerFunc,用于设置 Bot 的 context

func WithDeviceID

func WithDeviceID(deviceId string) BotPreparer

WithDeviceID 是一个 BotPreparerFunc,用于设置 Bot 的 设备 id

func WithUUIDOption

func WithUUIDOption(uuid string) BotPreparer

WithUUIDOption 是一个 BotPreparerFunc,用于设置 Bot 的 登录 uuid

type BotPreparerFunc

type BotPreparerFunc func(*Bot)

func (BotPreparerFunc) Prepare

func (f BotPreparerFunc) Prepare(b *Bot)

type Caller

type Caller struct {
	Client *Client
}

Caller 调用请求和解析请求 上层模块可以直接获取封装后的请求结果

func DefaultCaller

func DefaultCaller() *Caller

DefaultCaller Default Constructor for Caller

func NewCaller

func NewCaller(client *Client) *Caller

NewCaller Constructor for Caller

func (*Caller) AddFriendIntoChatRoom

func (c *Caller) AddFriendIntoChatRoom(ctx context.Context, opt *CallerAddFriendIntoChatRoomOptions) error

AddFriendIntoChatRoom 拉好友入群

func (*Caller) CheckLogin

func (c *Caller) CheckLogin(ctx context.Context, uuid, tip string) (CheckLoginResponse, error)

CheckLogin 检查是否登录成功

func (*Caller) GetLoginInfo

func (c *Caller) GetLoginInfo(ctx context.Context, path *url.URL) (*LoginInfo, error)

GetLoginInfo 获取登录信息

func (*Caller) GetLoginUUID

func (c *Caller) GetLoginUUID(ctx context.Context) (string, error)

GetLoginUUID 获取登录的uuid

func (*Caller) Logout

func (c *Caller) Logout(ctx context.Context, info *LoginInfo) error

Logout 用户退出

func (*Caller) RemoveFriendFromChatRoom

func (c *Caller) RemoveFriendFromChatRoom(ctx context.Context, opt *CallerRemoveFriendFromChatRoomOptions) error

RemoveFriendFromChatRoom 从群聊中移除用户

func (*Caller) SyncCheck

SyncCheck 异步获取是否有新的消息

func (*Caller) UploadMedia

func (c *Caller) UploadMedia(ctx context.Context, opt *CallerUploadMediaOptions) (*UploadResponse, error)

func (*Caller) WebInit

func (c *Caller) WebInit(ctx context.Context, request *BaseRequest) (*WebInitResponse, error)

WebInit 获取初始化信息

func (*Caller) WebWxBatchGetContact

func (c *Caller) WebWxBatchGetContact(ctx context.Context, members Members, request *BaseRequest) (Members, error)

WebWxBatchGetContact 获取联系人的详情 注: Members参数的长度不要大于50

func (*Caller) WebWxCreateChatRoom

func (c *Caller) WebWxCreateChatRoom(ctx context.Context, opt *CallerWebWxCreateChatRoomOptions) (*Group, error)

WebWxCreateChatRoom 创建群聊

func (*Caller) WebWxGetContact

func (c *Caller) WebWxGetContact(ctx context.Context, info *LoginInfo) (Members, error)

WebWxGetContact 获取所有的联系人

func (*Caller) WebWxOplog

func (c *Caller) WebWxOplog(ctx context.Context, opt *CallerWebWxOplogOptions) error

WebWxOplog 修改用户备注接口

func (*Caller) WebWxPushLogin

func (c *Caller) WebWxPushLogin(ctx context.Context, uin int64) (*PushLoginResponse, error)

WebWxPushLogin 免扫码登陆接口

func (*Caller) WebWxRelationPin

func (c *Caller) WebWxRelationPin(ctx context.Context, opt *CallerWebWxRelationPinOptions) error

WebWxRelationPin 将联系人是否置顶

func (*Caller) WebWxRenameChatRoom

func (c *Caller) WebWxRenameChatRoom(ctx context.Context, opt *CallerWebWxRenameChatRoomOptions) error

WebWxRenameChatRoom 群组重命名

func (*Caller) WebWxRevokeMsg

func (c *Caller) WebWxRevokeMsg(ctx context.Context, msg *SentMessage, request *BaseRequest) error

WebWxRevokeMsg 撤回消息操作

func (*Caller) WebWxSendAppMsg

func (c *Caller) WebWxSendAppMsg(ctx context.Context, msg *SendMessage, req *BaseRequest) (*SentMessage, error)

WebWxSendAppMsg 发送媒体消息

func (*Caller) WebWxSendFile

func (c *Caller) WebWxSendFile(ctx context.Context, opt *CallerWebWxSendFileOptions) (*SentMessage, error)

func (*Caller) WebWxSendImageMsg

func (c *Caller) WebWxSendImageMsg(ctx context.Context, opt *CallerWebWxSendImageMsgOptions) (*SentMessage, error)

WebWxSendImageMsg 发送图片消息接口

func (*Caller) WebWxSendMsg

func (c *Caller) WebWxSendMsg(ctx context.Context, opt *CallerWebWxSendMsgOptions) (*SentMessage, error)

WebWxSendMsg 发送消息接口

func (*Caller) WebWxSendVideoMsg

func (c *Caller) WebWxSendVideoMsg(ctx context.Context, opt *CallerWebWxSendAppMsgOptions) (*SentMessage, error)

func (*Caller) WebWxStatusAsRead

func (c *Caller) WebWxStatusAsRead(ctx context.Context, opt *CallerWebWxStatusAsReadOptions) error

WebWxStatusAsRead 将消息设置为已读

func (*Caller) WebWxStatusNotify

func (c *Caller) WebWxStatusNotify(ctx context.Context, opt *CallerWebWxStatusNotifyOptions) error

WebWxStatusNotify 通知手机已登录

func (*Caller) WebWxSync

WebWxSync 获取新的消息接口

func (*Caller) WebWxVerifyUser

func (c *Caller) WebWxVerifyUser(ctx context.Context, opt *CallerWebWxVerifyUserOptions) error

WebWxVerifyUser 同意加好友请求

type CallerAddFriendIntoChatRoomOptions

type CallerAddFriendIntoChatRoomOptions struct {
	BaseRequest *BaseRequest
	LoginInfo   *LoginInfo
	Group       *Group
	GroupLength int
	Friends     []*Friend
}

type CallerCommonOptions

type CallerCommonOptions struct {
	BaseRequest     *BaseRequest
	WebInitResponse *WebInitResponse
	LoginInfo       *LoginInfo
}

type CallerRemoveFriendFromChatRoomOptions

type CallerRemoveFriendFromChatRoomOptions struct {
	BaseRequest *BaseRequest
	LoginInfo   *LoginInfo
	Group       *Group
	Members     []*User
}

type CallerSyncCheckOptions

type CallerSyncCheckOptions CallerCommonOptions

type CallerUploadMediaCommonOptions

type CallerUploadMediaCommonOptions struct {
	FromUserName string
	ToUserName   string
	Reader       io.Reader
	BaseRequest  *BaseRequest
	LoginInfo    *LoginInfo
}

type CallerUploadMediaOptions

type CallerUploadMediaOptions struct {
	FromUserName string
	ToUserName   string
	File         *os.File
	BaseRequest  *BaseRequest
	LoginInfo    *LoginInfo
}

type CallerWebWxCreateChatRoomOptions

type CallerWebWxCreateChatRoomOptions struct {
	BaseRequest *BaseRequest
	LoginInfo   *LoginInfo
	Topic       string
	Friends     Friends
}

type CallerWebWxOplogOptions

type CallerWebWxOplogOptions struct {
	RemarkName  string
	ToUserName  string
	BaseRequest *BaseRequest
}

type CallerWebWxRelationPinOptions

type CallerWebWxRelationPinOptions struct {
	BaseRequest *BaseRequest
	User        *User
	Op          uint8
}

type CallerWebWxRenameChatRoomOptions

type CallerWebWxRenameChatRoomOptions struct {
	NewTopic    string
	BaseRequest *BaseRequest
	LoginInfo   *LoginInfo
	Group       *Group
}

type CallerWebWxSendAppMsgOptions

type CallerWebWxSendAppMsgOptions CallerUploadMediaCommonOptions

type CallerWebWxSendFileOptions

type CallerWebWxSendFileOptions CallerUploadMediaCommonOptions

type CallerWebWxSendImageMsgOptions

type CallerWebWxSendImageMsgOptions CallerUploadMediaCommonOptions

type CallerWebWxSendMsgOptions

type CallerWebWxSendMsgOptions struct {
	LoginInfo   *LoginInfo
	BaseRequest *BaseRequest
	Message     *SendMessage
}

type CallerWebWxStatusAsReadOptions

type CallerWebWxStatusAsReadOptions struct {
	BaseRequest *BaseRequest
	LoginInfo   *LoginInfo
	Message     *Message
}

type CallerWebWxStatusNotifyOptions

type CallerWebWxStatusNotifyOptions CallerCommonOptions

type CallerWebWxSyncOptions

type CallerWebWxSyncOptions CallerCommonOptions

type CallerWebWxVerifyUserOptions

type CallerWebWxVerifyUserOptions struct {
	VerifyContent string
	RecommendInfo RecommendInfo
	BaseRequest   *BaseRequest
	LoginInfo     *LoginInfo
}

type Card

type Card struct {
	XMLName                 xml.Name `xml:"msg"`
	ImageStatus             int      `xml:"imagestatus,attr"`
	Scene                   int      `xml:"scene,attr"`
	Sex                     int      `xml:"sex,attr"`
	Certflag                int      `xml:"certflag,attr"`
	BigHeadImgUrl           string   `xml:"bigheadimgurl,attr"`
	SmallHeadImgUrl         string   `xml:"smallheadimgurl,attr"`
	UserName                string   `xml:"username,attr"`
	NickName                string   `xml:"nickname,attr"`
	ShortPy                 string   `xml:"shortpy,attr"`
	Alias                   string   `xml:"alias,attr"` // Note: 这个是名片用户的微信号
	Province                string   `xml:"province,attr"`
	City                    string   `xml:"city,attr"`
	Sign                    string   `xml:"sign,attr"`
	Certinfo                string   `xml:"certinfo,attr"`
	BrandIconUrl            string   `xml:"brandIconUrl,attr"`
	BrandHomeUr             string   `xml:"brandHomeUr,attr"`
	BrandSubscriptConfigUrl string   `xml:"brandSubscriptConfigUrl,attr"`
	BrandFlags              string   `xml:"brandFlags,attr"`
	RegionCode              string   `xml:"regionCode,attr"`
}

Card 名片消息内容

type CheckLoginResponse

type CheckLoginResponse []byte

CheckLoginResponse 检查登录状态的响应body

func (CheckLoginResponse) Avatar

func (c CheckLoginResponse) Avatar() (string, error)

Avatar 获取扫码后的用户头像, base64编码

func (CheckLoginResponse) Code

func (c CheckLoginResponse) Code() (LoginCode, error)

Code 获取当前的登录检查状态的代码

func (CheckLoginResponse) RedirectURL

func (c CheckLoginResponse) RedirectURL() (*url.URL, error)

RedirectURL 重定向的URL

type Client

type Client struct {

	// Domain 微信服务器请求域名
	// 这个参数会在登录成功后被赋值
	// 之后所有的请求都会使用这个域名
	// 在登录热登录和扫码登录时会被重新赋值
	Domain WechatDomain

	// HttpHooks 请求上下文钩子
	HttpHooks HttpHooks

	// MaxRetryTimes 最大重试次数
	MaxRetryTimes int
	// contains filtered or unexported fields
}

Client http请求客户端 客户端需要维持Session会话

func DefaultClient

func DefaultClient() *Client

DefaultClient 自动存储cookie 设置客户端不自动跳转

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient 创建一个新的客户端

func (*Client) AddHttpHook

func (c *Client) AddHttpHook(hooks ...HttpHook)

AddHttpHook 添加一个请求上下文钩子

func (*Client) AddMemberIntoChatRoom

func (c *Client) AddMemberIntoChatRoom(ctx context.Context, opt *ClientAddMemberIntoChatRoomOption) (*http.Response, error)

AddMemberIntoChatRoom 添加用户进群聊

func (*Client) CheckLogin

func (c *Client) CheckLogin(ctx context.Context, uuid, tip string) (*http.Response, error)

CheckLogin 检查是否登录

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) GetLoginInfo

func (c *Client) GetLoginInfo(ctx context.Context, path *url.URL) (*http.Response, error)

GetLoginInfo 请求获取LoginInfo

func (*Client) GetLoginQrcode

func (c *Client) GetLoginQrcode(ctx context.Context, uuid string) (*http.Response, error)

GetLoginQrcode 获取登录的二维吗

func (*Client) GetLoginUUID

func (c *Client) GetLoginUUID(ctx context.Context) (*http.Response, error)

GetLoginUUID 获取登录的uuid

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient 返回http.Client 用于自定义http.Client的行为,如设置超时时间、设置代理、设置TLS配置等

func (*Client) InviteMemberIntoChatRoom

func (c *Client) InviteMemberIntoChatRoom(ctx context.Context, opt *ClientAddMemberIntoChatRoomOption) (*http.Response, error)

InviteMemberIntoChatRoom 邀请用户进群聊

func (*Client) Jar

func (c *Client) Jar() http.CookieJar

Jar 返回当前client的 http.CookieJar this http.CookieJar must be *Jar type

func (*Client) Logout

func (c *Client) Logout(ctx context.Context, info *LoginInfo) (*http.Response, error)

Logout 用户退出

func (*Client) RemoveMemberFromChatRoom

func (c *Client) RemoveMemberFromChatRoom(ctx context.Context, opt *ClientRemoveMemberFromChatRoomOption) (*http.Response, error)

RemoveMemberFromChatRoom 从群聊中移除用户

func (*Client) SetCookieJar

func (c *Client) SetCookieJar(jar *Jar)

SetCookieJar 设置cookieJar 这里限制了cookieJar必须是Jar类型 否则进行cookie序列化的时候因为字段的私有性无法进行所有字段的导出

func (*Client) SetMode

func (c *Client) SetMode(mode Mode)

SetMode 设置Client的模式

func (*Client) SyncCheck

func (c *Client) SyncCheck(ctx context.Context, opt *ClientSyncCheckOptions) (*http.Response, error)

SyncCheck 异步检查是否有新的消息返回

func (*Client) WebInit

func (c *Client) WebInit(ctx context.Context, request *BaseRequest) (*http.Response, error)

WebInit 请求获取初始化信息

func (*Client) WebWxBatchGetContact

func (c *Client) WebWxBatchGetContact(ctx context.Context, members Members, request *BaseRequest) (*http.Response, error)

WebWxBatchGetContact 获取联系人详情

func (*Client) WebWxCreateChatRoom

func (c *Client) WebWxCreateChatRoom(ctx context.Context, opt *ClientWebWxCreateChatRoomOption) (*http.Response, error)

WebWxCreateChatRoom 创建群聊

func (*Client) WebWxGetContact

func (c *Client) WebWxGetContact(ctx context.Context, sKey string, reqs int64) (*http.Response, error)

WebWxGetContact 获取联系人信息

func (*Client) WebWxGetHeadImg

func (c *Client) WebWxGetHeadImg(ctx context.Context, user *User) (*http.Response, error)

WebWxGetHeadImg 获取用户的头像

func (*Client) WebWxGetMedia

func (c *Client) WebWxGetMedia(ctx context.Context, msg *Message, info *LoginInfo) (*http.Response, error)

WebWxGetMedia 获取文件消息的文件响应

func (*Client) WebWxGetMsgImg

func (c *Client) WebWxGetMsgImg(ctx context.Context, msg *Message, info *LoginInfo) (*http.Response, error)

WebWxGetMsgImg 获取图片消息的图片响应

func (*Client) WebWxGetVideo

func (c *Client) WebWxGetVideo(ctx context.Context, msg *Message, info *LoginInfo) (*http.Response, error)

WebWxGetVideo 获取视频消息的视频响应

func (*Client) WebWxGetVoice

func (c *Client) WebWxGetVoice(ctx context.Context, msg *Message, info *LoginInfo) (*http.Response, error)

WebWxGetVoice 获取语音消息的语音响应

func (*Client) WebWxOplog

func (c *Client) WebWxOplog(ctx context.Context, opt *ClientWebWxOplogOption) (*http.Response, error)

WebWxOplog 用户重命名接口

func (*Client) WebWxPushLogin

func (c *Client) WebWxPushLogin(ctx context.Context, uin int64) (*http.Response, error)

WebWxPushLogin 免扫码登陆接口

func (*Client) WebWxRelationPin

func (c *Client) WebWxRelationPin(ctx context.Context, opt *ClientWebWxRelationPinOption) (*http.Response, error)

WebWxRelationPin 联系人置顶接口

func (*Client) WebWxRenameChatRoom

func (c *Client) WebWxRenameChatRoom(ctx context.Context, opt *ClientWebWxRenameChatRoomOption) (*http.Response, error)

WebWxRenameChatRoom 群组重命名接口

func (*Client) WebWxRevokeMsg

func (c *Client) WebWxRevokeMsg(ctx context.Context, msg *SentMessage, request *BaseRequest) (*http.Response, error)

WebWxRevokeMsg 撤回消息

func (*Client) WebWxSendAppMsg

func (c *Client) WebWxSendAppMsg(ctx context.Context, msg *SendMessage, request *BaseRequest) (*http.Response, error)

WebWxSendAppMsg 发送文件信息

func (*Client) WebWxSendMsg

func (c *Client) WebWxSendMsg(ctx context.Context, opt *ClientWebWxSendMsgOptions) (*http.Response, error)

WebWxSendMsg 发送文本消息

func (*Client) WebWxSendMsgImg

func (c *Client) WebWxSendMsgImg(ctx context.Context, opt *ClientWebWxSendMsgOptions) (*http.Response, error)

WebWxSendMsgImg 发送图片 这个接口依赖上传文件的接口 发送的图片必须是已经成功上传的图片

func (*Client) WebWxSendVideoMsg

func (c *Client) WebWxSendVideoMsg(ctx context.Context, request *BaseRequest, msg *SendMessage) (*http.Response, error)

WebWxSendVideoMsg 发送视频消息接口

func (*Client) WebWxStatusAsRead

func (c *Client) WebWxStatusAsRead(ctx context.Context, opt *ClientWebWxStatusAsReadOption) (*http.Response, error)

func (*Client) WebWxStatusNotify

func (c *Client) WebWxStatusNotify(ctx context.Context, opt *ClientWebWxStatusNotifyOptions) (*http.Response, error)

WebWxStatusNotify 通知手机已登录

func (*Client) WebWxSync

func (c *Client) WebWxSync(ctx context.Context, opt *ClientWebWxSyncOptions) (*http.Response, error)

WebWxSync 获取消息接口

func (*Client) WebWxUploadMediaByChunk

func (c *Client) WebWxUploadMediaByChunk(ctx context.Context, opt *ClientWebWxUploadMediaByChunkOptions) (*http.Response, error)

WebWxUploadMediaByChunk 分块上传文件 TODO 优化掉这个函数

func (*Client) WebWxVerifyUser

func (c *Client) WebWxVerifyUser(ctx context.Context, opt *ClientWebWxVerifyUserOption) (*http.Response, error)

WebWxVerifyUser 添加用户为好友接口

type ClientAddMemberIntoChatRoomOption

type ClientAddMemberIntoChatRoomOption struct {
	Group            string
	GroupLength      int
	InviteMemberList []string
	BaseRequest      *BaseRequest
	LoginInfo        *LoginInfo
}

type ClientCommonOptions

type ClientCommonOptions struct {
	BaseRequest     *BaseRequest
	WebInitResponse *WebInitResponse
	LoginInfo       *LoginInfo
}

type ClientRemoveMemberFromChatRoomOption

type ClientRemoveMemberFromChatRoomOption struct {
	Group         string
	DelMemberList []string
	BaseRequest   *BaseRequest
	LoginInfo     *LoginInfo
}

type ClientSyncCheckOptions

type ClientSyncCheckOptions ClientCommonOptions

type ClientWebWxCreateChatRoomOption

type ClientWebWxCreateChatRoomOption struct {
	Request   *BaseRequest
	LoginInfo *LoginInfo
	Topic     string
	Friends   []string
}

type ClientWebWxOplogOption

type ClientWebWxOplogOption struct {
	RemarkName  string
	UserName    string
	BaseRequest *BaseRequest
}

type ClientWebWxRelationPinOption

type ClientWebWxRelationPinOption struct {
	Request    *BaseRequest
	Op         uint8
	RemarkName string
	UserName   string
}

type ClientWebWxRenameChatRoomOption

type ClientWebWxRenameChatRoomOption struct {
	Request   *BaseRequest
	LoginInfo *LoginInfo
	NewTopic  string
	Group     string
}

type ClientWebWxSendMsgOptions

type ClientWebWxSendMsgOptions struct {
	LoginInfo   *LoginInfo
	BaseRequest *BaseRequest
	Message     *SendMessage
}

type ClientWebWxStatusAsReadOption

type ClientWebWxStatusAsReadOption struct {
	LoginInfo *LoginInfo
	Request   *BaseRequest
	Message   *Message
}

type ClientWebWxStatusNotifyOptions

type ClientWebWxStatusNotifyOptions ClientCommonOptions

type ClientWebWxSyncOptions

type ClientWebWxSyncOptions ClientCommonOptions

type ClientWebWxUploadMediaByChunkOptions

type ClientWebWxUploadMediaByChunkOptions struct {
	FromUserName string
	ToUserName   string
	File         *os.File
	BaseRequest  *BaseRequest
	LoginInfo    *LoginInfo
}

type ClientWebWxVerifyUserOption

type ClientWebWxVerifyUserOption struct {
	RecommendInfo RecommendInfo
	VerifyContent string
	BaseRequest   *BaseRequest
	LoginInfo     *LoginInfo
}

type CookieGroup

type CookieGroup []*http.Cookie

CookieGroup is a group of cookies

func (CookieGroup) GetByName

func (c CookieGroup) GetByName(cookieName string) (cookie *http.Cookie, exist bool)

type Friend

type Friend struct{ *User }

func NewFriendHelper

func NewFriendHelper(self *Self) *Friend

NewFriendHelper 创建一个文件传输助手 文件传输助手的微信身份标识符永远是filehelper

func (*Friend) AddIntoGroup

func (f *Friend) AddIntoGroup(groups ...*Group) error

AddIntoGroup 拉该好友入群

func (*Friend) SendFile

func (f *Friend) SendFile(file io.Reader) (*SentMessage, error)

SendFile 发送文件消息

func (*Friend) SendImage

func (f *Friend) SendImage(file io.Reader) (*SentMessage, error)

SendImage 发送图片消息

func (*Friend) SendText

func (f *Friend) SendText(content string) (*SentMessage, error)

SendText 发送文本消息

func (*Friend) SendVideo

func (f *Friend) SendVideo(file io.Reader) (*SentMessage, error)

SendVideo 发送视频消息

func (*Friend) SetRemarkName

func (f *Friend) SetRemarkName(name string) error

SetRemarkName 重命名当前好友 Deprecated

func (*Friend) String

func (f *Friend) String() string

implement fmt.Stringer

type FriendAddMessage

type FriendAddMessage struct {
	XMLName           xml.Name `xml:"msg"`
	Shortpy           string   `xml:"shortpy,attr"`
	ImageStatus       int      `xml:"imagestatus,attr"`
	Scene             int      `xml:"scene,attr"`
	PerCard           int      `xml:"percard,attr"`
	Sex               int      `xml:"sex,attr"`
	AlbumFlag         int      `xml:"albumflag,attr"`
	AlbumStyle        int      `xml:"albumstyle,attr"`
	SnsFlag           int      `xml:"snsflag,attr"`
	Opcode            int      `xml:"opcode,attr"`
	FromUserName      string   `xml:"fromusername,attr"`
	EncryptUserName   string   `xml:"encryptusername,attr"`
	FromNickName      string   `xml:"fromnickname,attr"`
	Content           string   `xml:"content,attr"`
	Country           string   `xml:"country,attr"`
	Province          string   `xml:"province,attr"`
	City              string   `xml:"city,attr"`
	Sign              string   `xml:"sign,attr"`
	Alias             string   `xml:"alias,attr"`
	WeiBo             string   `xml:"weibo,attr"`
	AlbumBgImgId      string   `xml:"albumbgimgid,attr"`
	SnsBgImgId        string   `xml:"snsbgimgid,attr"`
	SnsBgObjectId     string   `xml:"snsbgobjectid,attr"`
	MHash             string   `xml:"mhash,attr"`
	MFullHash         string   `xml:"mfullhash,attr"`
	BigHeadImgUrl     string   `xml:"bigheadimgurl,attr"`
	SmallHeadImgUrl   string   `xml:"smallheadimgurl,attr"`
	Ticket            string   `xml:"ticket,attr"`
	GoogleContact     string   `xml:"googlecontact,attr"`
	QrTicket          string   `xml:"qrticket,attr"`
	ChatRoomUserName  string   `xml:"chatroomusername,attr"`
	SourceUserName    string   `xml:"sourceusername,attr"`
	ShareCardUserName string   `xml:"sharecardusername,attr"`
	ShareCardNickName string   `xml:"sharecardnickname,attr"`
	CardVersion       string   `xml:"cardversion,attr"`
	BrandList         struct {
		Count int   `xml:"count,attr"`
		Ver   int64 `xml:"ver,attr"`
	} `xml:"brandlist"`
}

FriendAddMessage 好友添加消息信息内容

type Friends

type Friends []*Friend

func (Friends) AsMembers

func (f Friends) AsMembers() Members

AsMembers 将群组转换为用户列表

func (Friends) BroadcastTextToFriendsByRandomTime

func (f Friends) BroadcastTextToFriendsByRandomTime(msg string) error

BroadcastTextToFriendsByRandomTime 向所有好友随机时间间隔发送消息。

func (Friends) Count

func (f Friends) Count() int

Count 获取好友的数量

func (Friends) First

func (f Friends) First() *Friend

First 获取第一个好友

func (Friends) GetByNickName

func (f Friends) GetByNickName(nickname string) *Friend

GetByNickName 根据nickname查询一个Friend

func (Friends) GetByRemarkName

func (f Friends) GetByRemarkName(remarkName string) *Friend

GetByRemarkName 根据remarkName查询一个Friend

func (Friends) GetByUsername

func (f Friends) GetByUsername(username string) *Friend

GetByUsername 根据username查询一个Friend

func (Friends) Last

func (f Friends) Last() *Friend

Last 获取最后一个好友

func (Friends) Search

func (f Friends) Search(limit int, searchFuncList ...func(friend *Friend) bool) (results Friends)

Search 根据自定义条件查找好友

func (Friends) SearchByID

func (f Friends) SearchByID(id string) Friends

SearchByID 根据ID查找好友

func (Friends) SearchByNickName

func (f Friends) SearchByNickName(limit int, nickName string) (results Friends)

SearchByNickName 根据昵称查找好友

func (Friends) SearchByRemarkName

func (f Friends) SearchByRemarkName(limit int, remarkName string) (results Friends)

SearchByRemarkName 根据备注查找好友

func (Friends) SearchByUserName

func (f Friends) SearchByUserName(limit int, username string) (results Friends)

SearchByUserName 根据用户名查找好友

func (Friends) SendFile

func (f Friends) SendFile(file io.Reader, delay ...time.Duration) error

SendFile 群发文件

func (Friends) SendImage

func (f Friends) SendImage(file io.Reader, delays ...time.Duration) error

SendImage 向slice的好友依次发送图片消息

func (Friends) SendText

func (f Friends) SendText(text string, delays ...time.Duration) error

SendText 向slice的好友依次发送文本消息

func (Friends) Sort

func (f Friends) Sort() Friends

Sort 对好友进行排序

func (Friends) Uniq

func (f Friends) Uniq() Friends

Uniq 对好友进行去重

type Group

type Group struct{ *User }

func (*Group) AddFriendsIn

func (g *Group) AddFriendsIn(friends ...*Friend) error

AddFriendsIn 拉好友入群

func (*Group) Members

func (g *Group) Members() (Members, error)

Members 获取所有的群成员

func (*Group) RemoveMembers

func (g *Group) RemoveMembers(members Members) error

RemoveMembers 从群聊中移除用户 Deprecated 无论是网页版,还是程序上都不起作用

func (*Group) Rename

func (g *Group) Rename(name string) error

Rename 群组重命名 Deprecated

func (*Group) SearchMemberByUsername

func (g *Group) SearchMemberByUsername(username string) (*User, error)

SearchMemberByUsername 根据用户名查找群成员

func (*Group) SendFile

func (g *Group) SendFile(file io.Reader) (*SentMessage, error)

SendFile 发送文件给当前的群组

func (*Group) SendImage

func (g *Group) SendImage(file io.Reader) (*SentMessage, error)

SendImage 发行图片消息给当前的群组

func (*Group) SendText

func (g *Group) SendText(content string) (*SentMessage, error)

SendText 发行文本消息给当前的群组

func (*Group) SendVideo

func (g *Group) SendVideo(file io.Reader) (*SentMessage, error)

SendVideo 发行视频消息给当前的群组

func (*Group) String

func (g *Group) String() string

implement fmt.Stringer

type Groups

type Groups []*Group

func (Groups) AsMembers

func (g Groups) AsMembers() Members

AsMembers 将群组列表转换为用户列表

func (Groups) Count

func (g Groups) Count() int

Count 获取群组数量

func (Groups) First

func (g Groups) First() *Group

First 获取第一个群组

func (Groups) GetByNickName

func (g Groups) GetByNickName(nickname string) *Group

GetByNickName 根据nickname查询一个Group

func (Groups) GetByUsername

func (g Groups) GetByUsername(username string) *Group

GetByUsername 根据username查询一个Group

func (Groups) Last

func (g Groups) Last() *Group

Last 获取最后一个群组

func (Groups) Search

func (g Groups) Search(limit int, searchFuncList ...func(group *Group) bool) (results Groups)

Search 根据自定义条件查找群组

func (Groups) SearchByID

func (g Groups) SearchByID(id string) Groups

SearchByID 根据ID查找群组

func (Groups) SearchByNickName

func (g Groups) SearchByNickName(limit int, nickName string) (results Groups)

SearchByNickName 根据昵称查找群组

func (Groups) SearchByUserName

func (g Groups) SearchByUserName(limit int, username string) (results Groups)

SearchByUserName 根据用户名查找群组

func (Groups) SendFile

func (g Groups) SendFile(file io.Reader, delay ...time.Duration) error

SendFile 向群组依次发送文件消息, 支持发送延迟

func (Groups) SendImage

func (g Groups) SendImage(file io.Reader, delay ...time.Duration) error

SendImage 向群组依次发送图片消息, 支持发送延迟

func (Groups) SendText

func (g Groups) SendText(text string, delay ...time.Duration) error

SendText 向群组依次发送文本消息, 支持发送延迟

func (Groups) Sort

func (g Groups) Sort() Groups

Sort 对群组进行排序

func (Groups) Uniq

func (g Groups) Uniq() Groups

Uniq 对群组进行去重

type HotLogin

type HotLogin struct {
	// contains filtered or unexported fields
}

HotLogin 热登录模式

func (*HotLogin) Login

func (h *HotLogin) Login(bot *Bot) error

Login 实现了 BotLogin 接口

type HotReloadStorage

type HotReloadStorage io.ReadWriter

HotReloadStorage 热登陆存储接口

type HotReloadStorageItem

type HotReloadStorageItem struct {
	Jar          *Jar
	BaseRequest  *BaseRequest
	LoginInfo    *LoginInfo
	WechatDomain WechatDomain
	SyncKey      *SyncKey
	UUID         string
}

type HttpHook

type HttpHook interface {
	// BeforeRequest 将在请求之前调用
	BeforeRequest(req *http.Request)

	// AfterRequest 将在请求之后调用,无论请求成功与否
	AfterRequest(response *http.Response, err error)
}

HttpHook 请求上下文钩子

type HttpHooks

type HttpHooks []HttpHook

HttpHooks 请求上下文钩子列表

func (HttpHooks) AfterRequest

func (h HttpHooks) AfterRequest(response *http.Response, err error)

AfterRequest 将在请求之后调用,无论请求成功与否

func (HttpHooks) BeforeRequest

func (h HttpHooks) BeforeRequest(req *http.Request)

BeforeRequest 将在请求之前调用

type Jar

type Jar struct {
	PsList cookiejar.PublicSuffixList

	// Entries is a set of entries, keyed by their eTLD+1 and subkeyed by
	// their name/Domain/path.
	Entries map[string]map[string]entry

	// nextSeqNum is the next sequence number assigned to a new cookie
	// created SetCookies.
	NextSeqNum uint64
	// contains filtered or unexported fields
}

Jar is a struct which as same as cookiejar.Jar cookiejar.Jar's fields are private, so we can't use it directly

func NewJar

func NewJar() *Jar

func (*Jar) AsCookieJar

func (j *Jar) AsCookieJar() http.CookieJar

AsCookieJar unsafe convert to http.CookieJar

type JsonSerializer

type JsonSerializer struct{}

JsonSerializer is a serializer for json.

func (JsonSerializer) Decode

func (j JsonSerializer) Decode(reader io.Reader, v interface{}) error

Decode decodes data from reader to v.

func (JsonSerializer) Encode

func (j JsonSerializer) Encode(writer io.Writer, v interface{}) error

Encode encodes v to writer.

type LoginChecker

type LoginChecker struct {
	Bot           *Bot
	Tip           string
	UUIDCallback  func(uuid string)
	LoginCallBack func(body CheckLoginResponse)
	ScanCallBack  func(body CheckLoginResponse)
}

func (*LoginChecker) CheckLogin

func (l *LoginChecker) CheckLogin() error

type LoginCode

type LoginCode string

LoginCode 定义登录状态码

const (
	// LoginCodeSuccess 登录成功
	LoginCodeSuccess LoginCode = "200"
	// LoginCodeScanned 已扫码
	LoginCodeScanned LoginCode = "201"
	// LoginCodeTimeout 登录超时
	LoginCodeTimeout LoginCode = "400"
	// LoginCodeWait 等待扫码
	LoginCodeWait LoginCode = "408"
)

func (LoginCode) String

func (l LoginCode) String() string

type LoginInfo

type LoginInfo struct {
	Ret         int    `xml:"ret"`
	WxUin       int64  `xml:"wxuin"`
	IsGrayScale int    `xml:"isgrayscale"`
	Message     string `xml:"message"`
	SKey        string `xml:"skey"`
	WxSid       string `xml:"wxsid"`
	PassTicket  string `xml:"pass_ticket"`
}

LoginInfo 登录信息

func (LoginInfo) Err

func (l LoginInfo) Err() error

func (LoginInfo) Ok

func (l LoginInfo) Ok() bool

type MPArticle

type MPArticle struct {
	Title  string
	Cover  string
	Digest string
	Url    string
}

type MPSubscribeMsg

type MPSubscribeMsg struct {
	MPArticleCount int
	Time           int64
	UserName       string
	NickName       string
	MPArticleList  []*MPArticle
}

MPSubscribeMsg 公众号的订阅信息

type MatchFunc

type MatchFunc func(*Message) bool

MatchFunc 消息匹配函数,返回为true则表示匹配

func MatchFuncList

func MatchFuncList(matchFuncs ...MatchFunc) MatchFunc

MatchFuncList 将多个MatchFunc封装成一个MatchFunc

func SenderFriendRequired

func SenderFriendRequired() MatchFunc

SenderFriendRequired 只匹配好友

func SenderGroupRequired

func SenderGroupRequired() MatchFunc

SenderGroupRequired 只匹配群组

func SenderMatchFunc

func SenderMatchFunc(matchFuncs ...MessageSenderMatchFunc) MatchFunc

SenderMatchFunc 抽象的匹配发送者特征的处理函数

    dispatcher := NewMessageMatchDispatcher()
	   matchFuncList := MatchFuncList(SenderFriendRequired(), SenderNickNameContainsMatchFunc("多吃点苹果"))
	   dispatcher.RegisterHandler(matchFuncList, func(ctx *MessageContext) {
		     do your own business
	   })

func SenderMpRequired

func SenderMpRequired() MatchFunc

SenderMpRequired 只匹配公众号

func SenderNickNameContainsMatchFunc

func SenderNickNameContainsMatchFunc(nickname string) MatchFunc

SenderNickNameContainsMatchFunc 根据用户昵称是否包含指定字符串的匹配函数

func SenderNickNameEqualMatchFunc

func SenderNickNameEqualMatchFunc(nickname string) MatchFunc

SenderNickNameEqualMatchFunc 根据用户昵称是否等于指定字符串的匹配函数

func SenderRemakeNameContainsFunc

func SenderRemakeNameContainsFunc(remakeName string) MatchFunc

SenderRemakeNameContainsFunc 根据用户备注名是否包含指定字符串的匹配函数

func SenderRemarkNameEqualMatchFunc

func SenderRemarkNameEqualMatchFunc(remarkName string) MatchFunc

SenderRemarkNameEqualMatchFunc 根据用户备注是否等于指定字符串的匹配函数

type Members

type Members []*User

Members 抽象的用户组

func (Members) Append

func (m Members) Append(user *User) (results Members)

Append 追加联系人

func (Members) Count

func (m Members) Count() int

Count 统计数量

func (Members) Detail

func (m Members) Detail() error

Detail 获取当前 Members 的详情

func (Members) First

func (m Members) First() *User

First 获取第一个

func (Members) Friends

func (m Members) Friends() Friends

func (Members) GetByNickName

func (m Members) GetByNickName(nickname string) (*User, bool)

GetByNickName 根据nickname查找用户

func (Members) GetByRemarkName

func (m Members) GetByRemarkName(remarkName string) (*User, bool)

GetByRemarkName 根据remarkName查找用户

func (Members) GetByUserName

func (m Members) GetByUserName(username string) (*User, bool)

GetByUserName 根据username查找用户

func (Members) Groups

func (m Members) Groups() Groups

func (Members) Last

func (m Members) Last() *User

Last 获取最后一个

func (Members) MPs

func (m Members) MPs() Mps

func (Members) Search

func (m Members) Search(limit int, searchFuncList ...func(user *User) bool) (results Members)

Search 根据自定义条件查找

func (Members) SearchByNickName

func (m Members) SearchByNickName(limit int, nickName string) (results Members)

SearchByNickName 根据昵称查找

func (Members) SearchByRemarkName

func (m Members) SearchByRemarkName(limit int, remarkName string) (results Members)

SearchByRemarkName 根据备注查找

func (Members) SearchByUserName

func (m Members) SearchByUserName(limit int, username string) (results Members)

SearchByUserName 根据用户名查找

func (Members) Sort

func (m Members) Sort() Members

Sort 对联系人进行排序

func (Members) Uniq

func (m Members) Uniq() Members

Uniq Members 去重

type Message

type Message struct {
	AppInfo struct {
		Type  int
		AppID string
	}
	AppMsgType           AppMessageType
	HasProductId         int
	ImgHeight            int
	ImgStatus            int
	ImgWidth             int
	ForwardFlag          int
	MsgType              MessageType
	Status               int
	StatusNotifyCode     int
	SubMsgType           int
	VoiceLength          int
	CreateTime           int64
	NewMsgId             int64
	PlayLength           int64
	MediaId              string
	MsgId                string
	EncryFileName        string
	FileName             string
	FileSize             string
	Content              string
	FromUserName         string
	OriContent           string
	StatusNotifyUserName string
	Ticket               string
	ToUserName           string
	Url                  string

	RecommendInfo RecommendInfo

	Raw        []byte `json:"-"`
	RawContent string `json:"-"` // 消息原始内容
	// contains filtered or unexported fields
}

func (*Message) Agree

func (m *Message) Agree(verifyContents ...string) (*Friend, error)

Agree 同意好友的请求

func (*Message) AsRead

func (m *Message) AsRead() error

AsRead 将消息设置为已读

func (*Message) Bot

func (m *Message) Bot() *Bot

Bot 返回当前消息所属的Bot

func (*Message) Card

func (m *Message) Card() (*Card, error)

Card 获取card类型

func (*Message) Context

func (m *Message) Context() context.Context

func (*Message) FriendAddMessageContent

func (m *Message) FriendAddMessageContent() (*FriendAddMessage, error)

FriendAddMessageContent 获取FriendAddMessageContent内容

func (*Message) Get

func (m *Message) Get(key string) (value interface{}, exist bool)

Get 从消息上下文中获取值 goroutine safe

func (*Message) GetFile

func (m *Message) GetFile() (*http.Response, error)

GetFile 获取文件消息的文件

func (*Message) GetMedia

func (m *Message) GetMedia() (*http.Response, error)

GetMedia 获取媒体消息的响应

func (*Message) GetPicture

func (m *Message) GetPicture() (*http.Response, error)

GetPicture 获取图片消息的响应

func (*Message) GetVideo

func (m *Message) GetVideo() (*http.Response, error)

GetVideo 获取视频消息的响应

func (*Message) GetVoice

func (m *Message) GetVoice() (*http.Response, error)

GetVoice 获取录音消息的响应

func (*Message) HasAttachment

func (m *Message) HasAttachment() bool

HasAttachment 是否有附件

func (*Message) HasFile

func (m *Message) HasFile() bool

HasFile 判断消息是否为文件类型的消息

func (*Message) IsArticle

func (m *Message) IsArticle() bool

IsArticle 判断当前的消息类型是否为文章

func (*Message) IsAt

func (m *Message) IsAt() bool

IsAt 判断消息是否为@消息

func (*Message) IsCard

func (m *Message) IsCard() bool

func (*Message) IsComeFromGroup

func (m *Message) IsComeFromGroup() bool

IsComeFromGroup 判断消息是否来自群组 可能是自己或者别的群员发送

func (*Message) IsEmoticon

func (m *Message) IsEmoticon() bool

IsEmoticon 是否为表情包消息

func (*Message) IsFriendAdd

func (m *Message) IsFriendAdd() bool

func (*Message) IsJoinGroup

func (m *Message) IsJoinGroup() bool

IsJoinGroup 判断是否有人加入了群聊

func (*Message) IsLocation

func (m *Message) IsLocation() bool

func (*Message) IsMedia

func (m *Message) IsMedia() bool

func (*Message) IsNotify

func (m *Message) IsNotify() bool

func (*Message) IsPaiYiPai

func (m *Message) IsPaiYiPai() bool

IsPaiYiPai 判断消息是否为拍一拍 不要问我为什么取名为PaiYiPai,因为我也不知道取啥名字好

func (*Message) IsPicture

func (m *Message) IsPicture() bool

func (*Message) IsRealtimeLocation

func (m *Message) IsRealtimeLocation() bool

func (*Message) IsRealtimeLocationStart

func (m *Message) IsRealtimeLocationStart() bool

func (*Message) IsRealtimeLocationStop

func (m *Message) IsRealtimeLocationStop() bool

func (*Message) IsRecalled

func (m *Message) IsRecalled() bool

IsRecalled 判断是否撤回

func (*Message) IsReceiveRedPacket

func (m *Message) IsReceiveRedPacket() bool

IsReceiveRedPacket 判断当前是否收到红包

func (*Message) IsRenameGroup

func (m *Message) IsRenameGroup() bool

IsRenameGroup 判断当前是否是群组重命名

func (*Message) IsSelfSendToGroup

func (m *Message) IsSelfSendToGroup() bool

IsSelfSendToGroup 判断消息是否由自己发送到群组

func (*Message) IsSendByFriend

func (m *Message) IsSendByFriend() bool

IsSendByFriend 判断消息是否由好友发送

func (*Message) IsSendByGroup

func (m *Message) IsSendByGroup() bool

IsSendByGroup 判断消息是否由群组发送

func (*Message) IsSendBySelf

func (m *Message) IsSendBySelf() bool

IsSendBySelf 判断消息是否由自己发送

func (*Message) IsSendRedPacket

func (m *Message) IsSendRedPacket() bool

IsSendRedPacket 否发出红包判断当前是

func (*Message) IsSysNotice

func (m *Message) IsSysNotice() bool

func (*Message) IsSystem

func (m *Message) IsSystem() bool

func (*Message) IsText

func (m *Message) IsText() bool

func (*Message) IsTickled

func (m *Message) IsTickled() bool

IsTickled 判断消息是否为拍一拍

func (*Message) IsTickledMe

func (m *Message) IsTickledMe() bool

IsTickledMe 判断消息是否拍了拍自己

func (*Message) IsTransferAccounts

func (m *Message) IsTransferAccounts() bool

IsTransferAccounts 判断当前的消息是不是微信转账

func (*Message) IsVideo

func (m *Message) IsVideo() bool

func (*Message) IsVoice

func (m *Message) IsVoice() bool

func (*Message) IsVoipInvite

func (m *Message) IsVoipInvite() bool

IsVoipInvite 判断消息是否为语音或视频通话邀请

func (*Message) MediaData

func (m *Message) MediaData() (*AppMessageData, error)

MediaData 获取当前App Message的具体内容

func (*Message) Owner

func (m *Message) Owner() *Self

Owner 返回当前消息的拥有者

func (*Message) Receiver

func (m *Message) Receiver() (*User, error)

Receiver 获取消息的接收者 如果消息是群组消息,则返回群组 如果消息是好友消息,则返回好友 如果消息是系统消息,则返回当前用户

func (*Message) ReplyFile

func (m *Message) ReplyFile(file io.Reader) (*SentMessage, error)

ReplyFile 回复文件消息

func (*Message) ReplyImage

func (m *Message) ReplyImage(file io.Reader) (*SentMessage, error)

ReplyImage 回复图片消息

func (*Message) ReplyText

func (m *Message) ReplyText(content string) (*SentMessage, error)

ReplyText 回复文本消息

func (*Message) ReplyVideo

func (m *Message) ReplyVideo(file io.Reader) (*SentMessage, error)

ReplyVideo 回复视频消息

func (*Message) RevokeMsg

func (m *Message) RevokeMsg() (*RevokeMsg, error)

RevokeMsg 获取撤回消息的内容

func (*Message) SaveFile

func (m *Message) SaveFile(writer io.Writer) error

SaveFile 保存文件到指定的 io.Writer

func (*Message) SaveFileToLocal

func (m *Message) SaveFileToLocal(filename string) error

SaveFileToLocal 保存文件到本地

func (*Message) Sender

func (m *Message) Sender() (*User, error)

Sender 获取消息的发送者

func (*Message) SenderInGroup

func (m *Message) SenderInGroup() (*User, error)

SenderInGroup 获取消息在群里面的发送者

func (*Message) Set

func (m *Message) Set(key string, value interface{})

Set 往消息上下文中设置值 goroutine safe

func (*Message) StatusNotify

func (m *Message) StatusNotify() bool

StatusNotify 判断是否为操作通知消息

func (*Message) String

func (m *Message) String() string

func (*Message) WithContext

func (m *Message) WithContext(ctx context.Context)

type MessageContext

type MessageContext struct {
	*Message
	// contains filtered or unexported fields
}

MessageContext 消息处理上下文对象

func (*MessageContext) Abort

func (c *MessageContext) Abort()

Abort 中断当前消息处理, 不会调用下一个消息处理函数, 但是不会中断当前的处理函数

func (*MessageContext) AbortHandler

func (c *MessageContext) AbortHandler() MessageContextHandler

AbortHandler 获取当前中断的消息处理函数

func (*MessageContext) IsAbort

func (c *MessageContext) IsAbort() bool

IsAbort 判断是否被中断

func (*MessageContext) Next

func (c *MessageContext) Next()

Next 主动调用下一个消息处理函数(或开始调用)

type MessageContextHandler

type MessageContextHandler func(ctx *MessageContext)

MessageContextHandler 消息处理函数

type MessageContextHandlerGroup

type MessageContextHandlerGroup []MessageContextHandler

type MessageDispatcher

type MessageDispatcher interface {
	Dispatch(msg *Message)
}

MessageDispatcher 消息分发处理接口 跟 DispatchMessage 结合封装成 MessageHandler

type MessageErrorHandler

type MessageErrorHandler func(err error) error

MessageErrorHandler 获取消息时发生了错误的处理函数 参数err为获取消息时发生的错误,返回值为处理后的错误 如果返回nil,则表示忽略该错误,否则将继续传递该错误

type MessageHandler

type MessageHandler func(msg *Message)

MessageHandler 消息处理函数

type MessageMatchDispatcher

type MessageMatchDispatcher struct {
	// contains filtered or unexported fields
}

MessageMatchDispatcher impl MessageDispatcher interface

dispatcher := NewMessageMatchDispatcher()
dispatcher.OnText(func(msg *Message){
		msg.ReplyText("hello")
})
bot := DefaultBot()
bot.MessageHandler = DispatchMessage(dispatcher)

func NewMessageMatchDispatcher

func NewMessageMatchDispatcher() *MessageMatchDispatcher

NewMessageMatchDispatcher Constructor

func (*MessageMatchDispatcher) AsMessageHandler

func (m *MessageMatchDispatcher) AsMessageHandler() MessageHandler

AsMessageHandler 将MessageMatchDispatcher转换为MessageHandler

func (*MessageMatchDispatcher) Dispatch

func (m *MessageMatchDispatcher) Dispatch(msg *Message)

Dispatch impl MessageDispatcher 遍历 MessageMatchDispatcher 所有的消息处理函数 获取所有匹配上的函数 执行处理的消息处理方法

func (*MessageMatchDispatcher) OnCard

func (m *MessageMatchDispatcher) OnCard(handlers ...MessageContextHandler)

OnCard 注册处理消息类型为Card的处理函数

func (*MessageMatchDispatcher) OnEmoticon

func (m *MessageMatchDispatcher) OnEmoticon(handlers ...MessageContextHandler)

OnEmoticon 注册处理消息类型为Emoticon的处理函数(表情包)

func (*MessageMatchDispatcher) OnFriend

func (m *MessageMatchDispatcher) OnFriend(handlers ...MessageContextHandler)

OnFriend 注册发送者为好友的处理函数

func (*MessageMatchDispatcher) OnFriendAdd

func (m *MessageMatchDispatcher) OnFriendAdd(handlers ...MessageContextHandler)

OnFriendAdd 注册处理消息类型为FriendAdd的处理函数

func (*MessageMatchDispatcher) OnFriendByNickName

func (m *MessageMatchDispatcher) OnFriendByNickName(nickName string, handlers ...MessageContextHandler)

OnFriendByNickName 注册根据好友昵称是否匹配的消息处理函数

func (*MessageMatchDispatcher) OnFriendByRemarkName

func (m *MessageMatchDispatcher) OnFriendByRemarkName(remarkName string, handlers ...MessageContextHandler)

OnFriendByRemarkName 注册根据好友备注是否匹配的消息处理函数

func (*MessageMatchDispatcher) OnGroup

func (m *MessageMatchDispatcher) OnGroup(handlers ...MessageContextHandler)

OnGroup 注册发送者为群组的处理函数

func (*MessageMatchDispatcher) OnGroupByGroupName

func (m *MessageMatchDispatcher) OnGroupByGroupName(groupName string, handlers ...MessageContextHandler)

OnGroupByGroupName 注册根据群名是否匹配的消息处理函数

func (*MessageMatchDispatcher) OnImage

func (m *MessageMatchDispatcher) OnImage(handlers ...MessageContextHandler)

OnImage 注册处理消息类型为Image的处理函数

func (*MessageMatchDispatcher) OnMedia

func (m *MessageMatchDispatcher) OnMedia(handlers ...MessageContextHandler)

OnMedia 注册处理消息类型为Media(多媒体消息,包括但不限于APP分享、文件分享)的处理函数

func (*MessageMatchDispatcher) OnRecalled

func (m *MessageMatchDispatcher) OnRecalled(handlers ...MessageContextHandler)

OnRecalled 注册撤回消息类型的处理函数

func (*MessageMatchDispatcher) OnText

func (m *MessageMatchDispatcher) OnText(handlers ...MessageContextHandler)

OnText 注册处理消息类型为Text的处理函数

func (*MessageMatchDispatcher) OnTrickled

func (m *MessageMatchDispatcher) OnTrickled(handlers ...MessageContextHandler)

OnTrickled 注册处理消息类型为拍一拍的处理函数

func (*MessageMatchDispatcher) OnUser

func (m *MessageMatchDispatcher) OnUser(f func(user *User) bool, handlers ...MessageContextHandler)

OnUser 注册根据消息发送者的行为是否匹配的消息处理函数

func (*MessageMatchDispatcher) OnVoice

func (m *MessageMatchDispatcher) OnVoice(handlers ...MessageContextHandler)

OnVoice 注册处理消息类型为Voice的处理函数

func (*MessageMatchDispatcher) RegisterHandler

func (m *MessageMatchDispatcher) RegisterHandler(matchFunc MatchFunc, handlers ...MessageContextHandler)

RegisterHandler 注册消息处理函数, 根据自己的需求自定义 matchFunc返回true则表示处理对应的handlers

func (*MessageMatchDispatcher) SetAsync

func (m *MessageMatchDispatcher) SetAsync(async bool)

SetAsync 设置是否异步处理

type MessageResponse

type MessageResponse struct {
	BaseResponse BaseResponse
	LocalID      string
	MsgID        string
}

type MessageResponseParser

type MessageResponseParser struct {
	Reader io.Reader
}

MessageResponseParser 消息响应解析器

func (*MessageResponseParser) Err

func (p *MessageResponseParser) Err() error

Err 解析错误

func (*MessageResponseParser) MsgID

func (p *MessageResponseParser) MsgID() (string, error)

MsgID 解析消息ID

func (*MessageResponseParser) SentMessage

func (p *MessageResponseParser) SentMessage(msg *SendMessage) (*SentMessage, error)

SentMessage 返回 SentMessage

type MessageSenderMatchFunc

type MessageSenderMatchFunc func(user *User) bool

type MessageType

type MessageType int

MessageType 以Go惯用形式定义了PC微信所有的官方消息类型。 详见 message_test.go

Example (Output)
for _, wxt := range []MessageType{
	MsgTypeText, MsgTypeImage, MsgTypeVoice, MsgTypeVerify,
	MsgTypePossibleFriend, MsgTypeShareCard, MsgTypeVideo, MsgTypeEmoticon,
	MsgTypeLocation, MsgTypeApp, MsgTypeVoip, MsgTypeVoipNotify,
	MsgTypeVoipInvite, MsgTypeMicroVideo, MsgTypeSys, MsgTypeRecalled} {
	fmt.Printf("收到一条%s(type %d)\n", wxt, wxt)
}
fmt.Println("=======")
for _, wxt := range []MessageType{10000, 6, 51} {
	wxtstr := wxt.String()
	if regexp.MustCompile(`^M`).MatchString(wxtstr) {
		wxtstr = "未知消息"
	}
	fmt.Printf("收到一条%s(type %d): %s\n", wxtstr, wxt, wxt)
}
Output:

收到一条文本消息(type 1)
收到一条图片消息(type 3)
收到一条语音消息(type 34)
收到一条认证消息(type 37)
收到一条好友推荐消息(type 40)
收到一条名片消息(type 42)
收到一条视频消息(type 43)
收到一条表情消息(type 47)
收到一条地理位置消息(type 48)
收到一条APP消息(type 49)
收到一条VOIP消息(type 50)
收到一条VOIP结束消息(type 52)
收到一条VOIP邀请(type 53)
收到一条小视频消息(type 62)
收到一条系统消息(type 10000)
收到一条消息撤回(type 10002)
=======
收到一条系统消息(type 10000): 系统消息
收到一条未知消息(type 6): MessageType(6)
收到一条未知消息(type 51): MessageType(51)
const (
	MsgTypeText           MessageType = 1     // 文本消息
	MsgTypeImage          MessageType = 3     // 图片消息
	MsgTypeVoice          MessageType = 34    // 语音消息
	MsgTypeVerify         MessageType = 37    // 认证消息
	MsgTypePossibleFriend MessageType = 40    // 好友推荐消息
	MsgTypeShareCard      MessageType = 42    // 名片消息
	MsgTypeVideo          MessageType = 43    // 视频消息
	MsgTypeEmoticon       MessageType = 47    // 表情消息
	MsgTypeLocation       MessageType = 48    // 地理位置消息
	MsgTypeApp            MessageType = 49    // APP消息
	MsgTypeVoip           MessageType = 50    // VOIP消息
	MsgTypeVoipNotify     MessageType = 52    // VOIP结束消息
	MsgTypeVoipInvite     MessageType = 53    // VOIP邀请
	MsgTypeMicroVideo     MessageType = 62    // 小视频消息
	MsgTypeSys            MessageType = 10000 // 系统消息
	MsgTypeRecalled       MessageType = 10002 // 消息撤回
)

func (MessageType) String

func (i MessageType) String() string

type Mode

type Mode interface {
	GetLoginUUID(ctx context.Context, client *Client) (*http.Response, error)
	GetLoginInfo(ctx context.Context, client *Client, path string) (*http.Response, error)
	PushLogin(ctx context.Context, client *Client, uin int64) (*http.Response, error)
}

type Mp

type Mp struct{ *User }

Mp 公众号对象

func (*Mp) SendFile

func (m *Mp) SendFile(file io.Reader) (*SentMessage, error)

SendFile 发送文件消息给公众号

func (*Mp) SendImage

func (m *Mp) SendImage(file io.Reader) (*SentMessage, error)

SendImage 发送图片消息给公众号

func (*Mp) SendText

func (m *Mp) SendText(content string) (*SentMessage, error)

SendText 发送文本消息给公众号

func (*Mp) String

func (m *Mp) String() string

type Mps

type Mps []*Mp

Mps 公众号组对象

func (Mps) AsMembers

func (m Mps) AsMembers() Members

AsMembers 将公众号列表转换为用户列表

func (Mps) Count

func (m Mps) Count() int

Count 数量统计

func (Mps) First

func (m Mps) First() *Mp

First 获取第一个

func (Mps) GetByNickName

func (m Mps) GetByNickName(nickname string) *Mp

GetByNickName 根据nickname查询一个Mp

func (Mps) GetByUserName

func (m Mps) GetByUserName(username string) *Mp

GetByUserName 根据username查询一个Mp

func (Mps) Last

func (m Mps) Last() *Mp

Last 获取最后一个

func (Mps) Search

func (m Mps) Search(limit int, searchFuncList ...func(*Mp) bool) (results Mps)

Search 根据自定义条件查找

func (Mps) SearchByNickName

func (m Mps) SearchByNickName(limit int, nickName string) (results Mps)

SearchByNickName 根据昵称查找

func (Mps) SearchByUserName

func (m Mps) SearchByUserName(limit int, userName string) (results Mps)

SearchByUserName 根据用户名查找

func (Mps) Sort

func (m Mps) Sort() Mps

Sort 对公众号进行排序

func (Mps) Uniq

func (m Mps) Uniq() Mps

Uniq 对公众号进行去重

type PushLogin

type PushLogin struct {
	// contains filtered or unexported fields
}

PushLogin 免扫码登录模式

func (*PushLogin) Login

func (p *PushLogin) Login(bot *Bot) error

Login 实现了 BotLogin 接口

type PushLoginResponse

type PushLoginResponse struct {
	Ret  string `json:"ret"`
	Msg  string `json:"msg"`
	UUID string `json:"uuid"`
}

func (PushLoginResponse) Err

func (p PushLoginResponse) Err() error

func (PushLoginResponse) Ok

func (p PushLoginResponse) Ok() bool

type RecommendInfo

type RecommendInfo struct {
	OpCode     int
	Scene      int
	Sex        int
	VerifyFlag int
	AttrStatus int64
	QQNum      int64
	Alias      string
	City       string
	Content    string
	NickName   string
	Province   string
	Signature  string
	Ticket     string
	UserName   string
}

RecommendInfo 一些特殊类型的消息会携带该结构体信息

type Ret

type Ret int

func (Ret) Error

func (r Ret) Error() string

Error impl error interface

func (Ret) String

func (i Ret) String() string

type RetryLoginOption

type RetryLoginOption struct {
	BaseBotLoginOption
	MaxRetryCount int
	// contains filtered or unexported fields
}

RetryLoginOption 在登录失败后进行扫码登录

func (*RetryLoginOption) OnError

func (r *RetryLoginOption) OnError(bot *Bot, err error) error

OnError 实现了 BotLoginOption 接口 当登录失败后,会调用此方法进行扫码登录

type RevokeMsg

type RevokeMsg struct {
	SysMsg    xml.Name `xml:"sysmsg"`
	Type      string   `xml:"type,attr"`
	RevokeMsg struct {
		OldMsgId   int64  `xml:"oldmsgid"`
		MsgId      int64  `xml:"msgid"`
		Session    string `xml:"session"`
		ReplaceMsg string `xml:"replacemsg"`
	} `xml:"revokemsg"`
}

RevokeMsg 撤回消息Content

type ScanLogin

type ScanLogin struct {
	UUID string
}

ScanLogin 扫码登录

func (*ScanLogin) Login

func (s *ScanLogin) Login(bot *Bot) error

Login 实现了 BotLogin 接口

type Selector

type Selector string
const (
	SelectorNormal          Selector = "0" // 正常
	SelectorNewMsg          Selector = "2" // 有新消息
	SelectorModContact      Selector = "4" // 联系人信息变更
	SelectorAddOrDelContact Selector = "6" // 添加或删除联系人
	SelectorModChatRoom     Selector = "7" // 进入或退出聊天室
)

type Self

type Self struct {
	*User
	// contains filtered or unexported fields
}

Self 自己,当前登录用户对象

func (*Self) AddFriendIntoManyGroups

func (s *Self) AddFriendIntoManyGroups(friend *Friend, groups ...*Group) error

AddFriendIntoManyGroups 拉好友进多个群聊 AddFriendIntoGroups, 名字和上面的有点像

func (*Self) AddFriendsIntoGroup

func (s *Self) AddFriendsIntoGroup(group *Group, friends ...*Friend) error

AddFriendsIntoGroup 拉多名好友进群 最好自己是群主,成功率高一点,因为有的群允许非群组拉人,而有的群不允许

func (*Self) Bot

func (s *Self) Bot() *Bot

Bot 获取当前用户的机器人

func (*Self) ChkFrdGrpMpNil

func (s *Self) ChkFrdGrpMpNil() bool

func (*Self) ContactList

func (s *Self) ContactList() Members

ContactList 获取最近的联系人列表

func (*Self) CreateGroup

func (s *Self) CreateGroup(topic string, friends ...*Friend) (*Group, error)

CreateGroup 创建群聊 topic 群昵称,可以传递字符串 friends 群员,最少为2个,加上自己3个,三人才能成群

func (*Self) FileHelper

func (s *Self) FileHelper() *Friend

FileHelper 获取文件传输助手对象,封装成Friend返回

fh := self.FileHelper() // or fh := openwechat.NewFriendHelper(self)

func (*Self) ForwardMessageToFriends

func (s *Self) ForwardMessageToFriends(msg *SentMessage, delay time.Duration, friends ...*Friend) error

ForwardMessageToFriends 转发给好友

func (*Self) ForwardMessageToGroups

func (s *Self) ForwardMessageToGroups(msg *SentMessage, delay time.Duration, groups ...*Group) error

ForwardMessageToGroups 转发给群组

func (*Self) Friends

func (s *Self) Friends(update ...bool) (Friends, error)

Friends 获取所有的好友

func (*Self) Groups

func (s *Self) Groups(update ...bool) (Groups, error)

Groups 获取所有的群组

func (*Self) ID

func (s *Self) ID() int64

ID 当前登录用户的ID

func (*Self) MPSubscribeList

func (s *Self) MPSubscribeList() []*MPSubscribeMsg

MPSubscribeList 获取部分公众号文章列表

func (*Self) Members

func (s *Self) Members(update ...bool) (Members, error)

Members 获取所有的好友、群组、公众号信息

func (*Self) Mps

func (s *Self) Mps(update ...bool) (Mps, error)

Mps 获取所有的公众号

func (*Self) RemoveMemberFromGroup

func (s *Self) RemoveMemberFromGroup(group *Group, members Members) error

RemoveMemberFromGroup 从群聊中移除用户 Deprecated 无论是网页版,还是程序上都不起作用

func (*Self) RenameGroup

func (s *Self) RenameGroup(group *Group, newName string) error

RenameGroup 群组重命名 Deprecated

func (*Self) RevokeMessage

func (s *Self) RevokeMessage(msg *SentMessage) error

RevokeMessage 撤回消息

sentMessage, err := friend.SendText("message")
if err == nil {
    self.RevokeMessage(sentMessage) // or sentMessage.Revoke()
}

func (*Self) SendFileToFriend

func (s *Self) SendFileToFriend(friend *Friend, file io.Reader) (*SentMessage, error)

SendFileToFriend 发送文件给好友

func (*Self) SendFileToFriends

func (s *Self) SendFileToFriends(file io.Reader, delay time.Duration, friends ...*Friend) error

SendFileToFriends 发送文件给好友

func (*Self) SendFileToGroup

func (s *Self) SendFileToGroup(group *Group, file io.Reader) (*SentMessage, error)

SendFileToGroup 发送文件给群组

func (*Self) SendFileToGroups

func (s *Self) SendFileToGroups(file io.Reader, delay time.Duration, groups ...*Group) error

SendFileToGroups 发送文件给群组

func (*Self) SendFileToMp

func (s *Self) SendFileToMp(mp *Mp, file io.Reader) (*SentMessage, error)

SendFileToMp 发送文件给公众号

func (*Self) SendImageToFriend

func (s *Self) SendImageToFriend(friend *Friend, file io.Reader) (*SentMessage, error)

SendImageToFriend 发送图片消息给好友

func (*Self) SendImageToFriends

func (s *Self) SendImageToFriends(img io.Reader, delay time.Duration, friends ...*Friend) error

SendImageToFriends 发送图片消息给好友

func (*Self) SendImageToGroup

func (s *Self) SendImageToGroup(group *Group, file io.Reader) (*SentMessage, error)

SendImageToGroup 发送图片消息给群组

func (*Self) SendImageToGroups

func (s *Self) SendImageToGroups(img io.Reader, delay time.Duration, groups ...*Group) error

SendImageToGroups 发送图片消息给群组

func (*Self) SendImageToMp

func (s *Self) SendImageToMp(mp *Mp, file io.Reader) (*SentMessage, error)

SendImageToMp 发送图片消息给公众号

func (*Self) SendTextToFriend

func (s *Self) SendTextToFriend(friend *Friend, text string) (*SentMessage, error)

SendTextToFriend 发送文本消息给好友

func (*Self) SendTextToFriends

func (s *Self) SendTextToFriends(text string, delay time.Duration, friends ...*Friend) error

SendTextToFriends 发送文本消息给好友

func (*Self) SendTextToGroup

func (s *Self) SendTextToGroup(group *Group, text string) (*SentMessage, error)

SendTextToGroup 发送文本消息给群组

func (*Self) SendTextToGroups

func (s *Self) SendTextToGroups(text string, delay time.Duration, groups ...*Group) error

SendTextToGroups 发送文本消息给群组

func (*Self) SendTextToMp

func (s *Self) SendTextToMp(mp *Mp, text string) (*SentMessage, error)

SendTextToMp 发送文本消息给公众号

func (*Self) SendVideoToFriend

func (s *Self) SendVideoToFriend(friend *Friend, file io.Reader) (*SentMessage, error)

SendVideoToFriend 发送视频给好友

func (*Self) SendVideoToFriends

func (s *Self) SendVideoToFriends(video io.Reader, delay time.Duration, friends ...*Friend) error

SendVideoToFriends 发送视频给好友

func (*Self) SendVideoToGroup

func (s *Self) SendVideoToGroup(group *Group, file io.Reader) (*SentMessage, error)

SendVideoToGroup 发送视频给群组

func (*Self) SendVideoToGroups

func (s *Self) SendVideoToGroups(video io.Reader, delay time.Duration, groups ...*Group) error

SendVideoToGroups 发送视频给群组

func (*Self) SendVideoToMp

func (s *Self) SendVideoToMp(mp *Mp, file io.Reader) (*SentMessage, error)

SendVideoToMp 发送视频消息给公众号

func (*Self) SetRemarkNameToFriend

func (s *Self) SetRemarkNameToFriend(friend *Friend, remarkName string) error

SetRemarkNameToFriend 设置好友备注 Deprecated 已经失效了

self.SetRemarkNameToFriend(friend, "remark") // or friend.SetRemarkName("remark")

func (*Self) UpdateMembersDetail

func (s *Self) UpdateMembersDetail() error

UpdateMembersDetail 更新所有的联系人信息

type SendMessage

type SendMessage struct {
	Type         MessageType
	Content      string
	FromUserName string
	ToUserName   string
	LocalID      string
	ClientMsgId  string
	MediaId      string `json:"MediaId,omitempty"`
}

SendMessage 发送消息的结构体

func NewMediaSendMessage

func NewMediaSendMessage(msgType MessageType, fromUserName, toUserName, mediaId string) *SendMessage

NewMediaSendMessage 媒体消息的构造方法

func NewSendMessage

func NewSendMessage(msgType MessageType, content, fromUserName, toUserName, mediaId string) *SendMessage

NewSendMessage SendMessage的构造方法

func NewTextSendMessage

func NewTextSendMessage(content, fromUserName, toUserName string) *SendMessage

NewTextSendMessage 文本消息的构造方法

type SendMessageFunc

type SendMessageFunc func() (*SentMessage, error)

type SentMessage

type SentMessage struct {
	*SendMessage

	MsgId string
	// contains filtered or unexported fields
}

SentMessage 已发送的信息

func (*SentMessage) CanRevoke

func (s *SentMessage) CanRevoke() bool

CanRevoke 是否可以撤回该消息

func (*SentMessage) ForwardToFriends

func (s *SentMessage) ForwardToFriends(friends ...*Friend) error

ForwardToFriends 转发该消息给好友 该方法会阻塞直到所有好友都接收到消息 这里为了兼容以前的版本,默认休眠0.5秒,如果需要更快的速度,可以使用 SentMessage.ForwardToFriendsWithDelay

func (*SentMessage) ForwardToFriendsWithDelay

func (s *SentMessage) ForwardToFriendsWithDelay(delay time.Duration, friends ...*Friend) error

ForwardToFriendsWithDelay 转发该消息给好友,延迟指定时间

func (*SentMessage) ForwardToGroups

func (s *SentMessage) ForwardToGroups(groups ...*Group) error

ForwardToGroups 转发该消息给群组 该方法会阻塞直到所有群组都接收到消息 这里为了兼容以前的版本,默认休眠0.5秒,如果需要更快的速度,可以使用 SentMessage.ForwardToGroupsDelay

func (*SentMessage) ForwardToGroupsWithDelay

func (s *SentMessage) ForwardToGroupsWithDelay(delay time.Duration, groups ...*Group) error

ForwardToGroupsWithDelay 转发该消息给群组, 延迟指定时间

func (*SentMessage) Revoke

func (s *SentMessage) Revoke() error

Revoke 撤回该消息

type Serializer

type Serializer interface {
	Encode(writer io.Writer, v interface{}) error
	Decode(reader io.Reader, v interface{}) error
}

Serializer is an interface for encoding and decoding data.

type Session

type Session struct {
	LoginInfo *LoginInfo
	Request   *BaseRequest
	Response  *WebInitResponse
}

Session 会话信息,包含登录信息、请求信息、响应信息

type SyncCheckResponse

type SyncCheckResponse struct {
	RetCode  string
	Selector Selector
}

func NewSyncCheckResponse

func NewSyncCheckResponse(b []byte) (*SyncCheckResponse, error)

func (SyncCheckResponse) Err

func (s SyncCheckResponse) Err() error

func (SyncCheckResponse) HasNewMessage

func (s SyncCheckResponse) HasNewMessage() bool

func (SyncCheckResponse) NorMal

func (s SyncCheckResponse) NorMal() bool

func (SyncCheckResponse) Success

func (s SyncCheckResponse) Success() bool

type SyncKey

type SyncKey struct {
	Count int
	List  []struct{ Key, Val int64 }
}

type UploadResponse

type UploadResponse struct {
	BaseResponse BaseResponse
	MediaId      string
}

type User

type User struct {
	HideInputBarFlag  int
	StarFriend        int
	Sex               int
	AppAccountFlag    int
	VerifyFlag        int
	ContactFlag       int
	WebWxPluginSwitch int
	HeadImgFlag       int
	SnsFlag           int
	IsOwner           int
	MemberCount       int
	ChatRoomId        int
	UniFriend         int
	OwnerUin          int
	Statues           int
	AttrStatus        int64
	Uin               int64
	Province          string
	City              string
	Alias             string
	DisplayName       string
	KeyWord           string
	EncryChatRoomId   string
	UserName          string
	NickName          string
	HeadImgUrl        string
	RemarkName        string
	PYInitial         string
	PYQuanPin         string
	RemarkPYInitial   string
	RemarkPYQuanPin   string
	Signature         string

	MemberList Members
	// contains filtered or unexported fields
}

User 抽象的用户结构: 好友 群组 公众号

func (*User) AsFriend

func (u *User) AsFriend() (*Friend, bool)

AsFriend 将当前用户转换为好友类型

func (*User) AsGroup

func (u *User) AsGroup() (*Group, bool)

AsGroup 将当前用户转换为群组类型

func (*User) AsMP

func (u *User) AsMP() (*Mp, bool)

AsMP 将当前用户转换为公众号类型

func (*User) AvatarID

func (u *User) AvatarID() string

AvatarID 获取用户头像id 这个值会随着用户更换头像而变化

func (*User) Detail

func (u *User) Detail() error

Detail 获取用户的详情

func (*User) Equal

func (u *User) Equal(user *User) bool

Equal 判断两个用户是否相等

func (*User) GetAvatarResponse

func (u *User) GetAvatarResponse() (resp *http.Response, err error)

GetAvatarResponse 获取用户头像

func (*User) ID

func (u *User) ID() string

ID 获取用户头像id Deprecated: 请使用 AvatarID

func (*User) IsFriend

func (u *User) IsFriend() bool

IsFriend 判断是否为好友

func (*User) IsGroup

func (u *User) IsGroup() bool

IsGroup 判断是否为群组

func (*User) IsMP

func (u *User) IsMP() bool

IsMP 判断是否为公众号

func (*User) IsPin

func (u *User) IsPin() bool

IsPin 判断当前联系人(好友、群组、公众号)是否为置顶状态

func (*User) IsSelf

func (u *User) IsSelf() bool

IsSelf 判断是否为当前用户

func (*User) OrderSymbol

func (u *User) OrderSymbol() string

OrderSymbol 获取用户的排序标识

func (*User) Pin

func (u *User) Pin() error

Pin 将联系人置顶

func (*User) SaveAvatar

func (u *User) SaveAvatar(filename string) error

SaveAvatar 下载用户头像

func (*User) SaveAvatarWithWriter

func (u *User) SaveAvatarWithWriter(writer io.Writer) error

func (*User) Self

func (u *User) Self() *Self

Self 返回当前用户

func (*User) String

func (u *User) String() string

implement fmt.Stringer

func (*User) UnPin

func (u *User) UnPin() error

UnPin 将联系人取消置顶

type UserAgentHook

type UserAgentHook struct {
	UserAgent string
}

func (UserAgentHook) AfterRequest

func (u UserAgentHook) AfterRequest(_ *http.Response, _ error)

func (UserAgentHook) BeforeRequest

func (u UserAgentHook) BeforeRequest(req *http.Request)

type UserDetailItem

type UserDetailItem struct {
	UserName        string
	EncryChatRoomId string
}

type UserDetailItemList

type UserDetailItemList []UserDetailItem

func NewUserDetailItemList

func NewUserDetailItemList(members Members) UserDetailItemList

type WebInitResponse

type WebInitResponse struct {
	Count               int
	ClientVersion       int
	GrayScale           int
	InviteStartCount    int
	MPSubscribeMsgCount int
	ClickReportInterval int
	SystemTime          int64
	ChatSet             string
	SKey                string
	BaseResponse        BaseResponse
	SyncKey             *SyncKey
	User                *User
	MPSubscribeMsgList  []*MPSubscribeMsg
	ContactList         Members
}

WebInitResponse 初始化的相应信息

type WebWxBatchContactResponse

type WebWxBatchContactResponse struct {
	Count        int
	BaseResponse BaseResponse
	ContactList  []*User
}

type WebWxContactResponse

type WebWxContactResponse struct {
	MemberCount  int
	Seq          int64
	BaseResponse BaseResponse
	MemberList   []*User
}

type WebWxSyncResponse

type WebWxSyncResponse struct {
	AddMsgCount            int
	ContinueFlag           int
	DelContactCount        int
	ModChatRoomMemberCount int
	ModContactCount        int
	Skey                   string
	SyncCheckKey           SyncKey
	SyncKey                *SyncKey
	BaseResponse           BaseResponse
	ModChatRoomMemberList  Members
	AddMsgList             []*Message
}

type WechatDomain

type WechatDomain string

func (WechatDomain) BaseHost

func (w WechatDomain) BaseHost() string

func (WechatDomain) FileHost

func (w WechatDomain) FileHost() string

func (WechatDomain) SyncHost

func (w WechatDomain) SyncHost() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL