wxweb

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

README

wxweb

微信个人号机器人框架,基于微信网页版协议。

Documentation

Index

Constants

View Source
const (

	// 已扫码未确认
	StateScan

	// 等待确认超时
	StateScanTimeout

	// 已确认(正在登录)
	StateConfirm

	// 登录成功(此时可以正常收发消息)
	StateRunning

	// 已下线(主动、被动或异常)
	StateStop
)
View Source
const (

	// 好友
	ContactFriend

	// 群
	ContactGroup

	// 公众号
	ContactMPS

	// 系统
	ContactSystem
)
View Source
const (
	// 自带表情是文本消息,Content字段内容为:[奸笑],
	// emoji表情也是文本消息,Content字段内容为:<span class="emoji emoji1f633"></span>,
	// 如果连同文字和表情一起发送,Content字段内容是文字和表情直接是混在一起,
	// 位置坐标也是文本消息,Content字段内容为:雨花台区雨花西路(德安花园东):/cgi-bin/mmwebwx-bin/webwxgetpubliclinkimg?url=xxx&msgid=741398718084560243&pictype=location
	MsgText = 1

	// 图片/照片消息
	MsgImage = 3

	// 语音消息
	MsgVoice = 34

	// 被添加好友待验证
	MsgVerify = 37

	MsgFriendRecommend = 40

	// 名片消息
	MsgCard = 42

	// 拍摄(视频消息)
	MsgVideo = 43

	// 动画表情,
	// 包括官方表情包中的表情(Content字段无内容)和自定义的图片表情(Content字段内容为XML)
	MsgAnimEmotion = 47

	MsgLocation = 48

	// 公众号推送的链接,分享的链接(AppMsgType=1/3/5),红包(AppMsgType=2001),
	// 发送的文件,收藏,实时位置共享
	MsgLink = 49

	MsgVoip = 50

	// 登录之后系统发送的初始化消息
	MsgInit = 51

	MsgVoipNotify = 52
	MsgVoipInvite = 53
	MsgVideoCall  = 62

	MsgNotice = 9999

	// 系统消息,
	// 例如通过好友验证,系统会发送"你已添加了...","如果陌生人...","实时位置共享已结束"的消息,
	MsgSystem = 10000

	// 撤回消息
	MsgRevoke = 10002
)

Variables

View Source
var (
	ErrInvalidState = errors.New("invalid state")

	ErrReq = errors.New("request failed")

	ErrResp = errors.New("response invalid")

	ErrContactNotFound = errors.New("contact not found")
)

Functions

func CountBots

func CountBots() int

func EachBot

func EachBot(f func(*Bot) bool)

func EnableDump

func EnableDump(enabled bool)

Types

type Bot

type Bot struct {
	StartTime time.Time
	StopTime  time.Time
	// contains filtered or unexported fields
}

func GetBotByUUID

func GetBotByUUID(uuid string) *Bot

func GetBotByUin

func GetBotByUin(uin int64) *Bot

func New

func New() *Bot

func RunningBots

func RunningBots() []*Bot

func (*Bot) Accept

func (bot *Bot) Accept(toUserName, ticket string) (*Contact, error)

通过验证且添加到联系人

func (*Bot) Contacts

func (bot *Bot) Contacts() *Contacts

func (*Bot) DownloadAvatar

func (bot *Bot) DownloadAvatar(dst string) (string, error)

func (*Bot) DownloadQRCode

func (bot *Bot) DownloadQRCode(dst string) (string, error)

func (*Bot) ForwardImage

func (bot *Bot) ForwardImage(toUserName, mediaId string) error

func (*Bot) ForwardVideo

func (bot *Bot) ForwardVideo(toUserName, mediaId string) error

func (*Bot) GetAttr

func (bot *Bot) GetAttr(attr interface{}, defaultValue interface{}) interface{}

func (*Bot) GetAttrBool

func (bot *Bot) GetAttrBool(attr string, defaultValue bool) bool

func (*Bot) GetAttrInt

func (bot *Bot) GetAttrInt(attr string, defaultValue int) int

func (*Bot) GetAttrInt64

func (bot *Bot) GetAttrInt64(attr string, defaultValue int64) int64

func (*Bot) GetAttrString

func (bot *Bot) GetAttrString(attr string, defaultValue string) string

func (*Bot) GetAttrUint

func (bot *Bot) GetAttrUint(attr string, defaultValue uint) uint

func (*Bot) GetAttrUint64

func (bot *Bot) GetAttrUint64(attr string, defaultValue uint64) uint64

func (*Bot) GetContactFromServer

func (bot *Bot) GetContactFromServer(toUserName string) (*Contact, error)

func (*Bot) GetContactsFromServer

func (bot *Bot) GetContactsFromServer(toUserNames ...string) ([]*Contact, error)

func (*Bot) Release

func (bot *Bot) Release()

func (*Bot) Remark

func (bot *Bot) Remark(toUserName, remark string) error

func (*Bot) Self

func (bot *Bot) Self() *Contact

func (*Bot) SendImage

func (bot *Bot) SendImage(toUserName string, data []byte, filename string) (string, error)

func (*Bot) SendText

func (bot *Bot) SendText(toUserName string, text string) error

func (*Bot) SendVideo

func (bot *Bot) SendVideo(toUserName string, data []byte, filename string) (string, error)

func (*Bot) SetAttr

func (bot *Bot) SetAttr(attr interface{}, value interface{})

func (*Bot) Start

func (bot *Bot) Start(handler Handler)

func (*Bot) Stop

func (bot *Bot) Stop()

func (*Bot) Verify

func (bot *Bot) Verify(toUserName, ticket string) error

type Contact

type Contact struct {

	// 联系人类型,
	// 个人和群为0,
	// 订阅号为8,
	// 企业号为24(包括扩微信支付),
	// 系统号为56(微信团队官方帐号),
	// 29(未知,招行信用卡为29)
	VerifyFlag int

	// Type是VerifyFlag解析后的值
	Type int

	// UserName每次登录都不一样,
	// 群以@@开头,其他以@开头,系统帐号则直接是名字,如:
	// weixin(微信团队)/filehelper(文件传输助手)/fmessage(朋友消息推荐)
	UserName string

	// 昵称,如果是群,表示群名称
	NickName string

	// 备注(仅好友有该字段)
	RemarkName string

	// 成员列表(仅群有该字段),
	// 只在调用Update后才有值,UserName->NickName
	Members map[string]string
	// contains filtered or unexported fields
}

func GetContact

func GetContact(userName string) *Contact

func (*Contact) Bot

func (c *Contact) Bot() *Bot

func (*Contact) GetAttr

func (c *Contact) GetAttr(attr interface{}, defaultValue interface{}) interface{}

func (*Contact) GetAttrBool

func (c *Contact) GetAttrBool(attr string, defaultValue bool) bool

func (*Contact) GetAttrInt

func (c *Contact) GetAttrInt(attr string, defaultValue int) int

func (*Contact) GetAttrInt64

func (c *Contact) GetAttrInt64(attr string, defaultValue int64) int64

func (*Contact) GetAttrString

func (c *Contact) GetAttrString(attr string, defaultValue string) string

func (*Contact) GetAttrUint

func (c *Contact) GetAttrUint(attr string, defaultValue uint) uint

func (*Contact) GetAttrUint64

func (c *Contact) GetAttrUint64(attr string, defaultValue uint64) uint64

func (*Contact) Raw

func (c *Contact) Raw() []byte

func (*Contact) SendImage

func (c *Contact) SendImage(data []byte, filename string) (string, error)

func (*Contact) SendText

func (c *Contact) SendText(text string) error

func (*Contact) SendVideo

func (c *Contact) SendVideo(data []byte, filename string) (string, error)

func (*Contact) SetAttr

func (c *Contact) SetAttr(attr interface{}, value interface{})

func (*Contact) Update

func (c *Contact) Update() *Contact

type Contacts

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

func (*Contacts) Add

func (cs *Contacts) Add(c *Contact)

func (*Contacts) Count

func (cs *Contacts) Count() int

func (*Contacts) Each

func (cs *Contacts) Each(f func(*Contact) bool)

func (*Contacts) EachLocked

func (cs *Contacts) EachLocked(f func(*Contact) bool)

func (*Contacts) Find

func (cs *Contacts) Find(keyword string) *Contact

func (*Contacts) Get

func (cs *Contacts) Get(userName string) *Contact

func (*Contacts) Remove

func (cs *Contacts) Remove(userName string)

type Handler

type Handler interface {
	// 登录成功(error == nil),
	// 登录失败(error != nil)
	OnSignIn(error)

	// 退出/下线
	OnSignOut()

	// 收到二维码(需扫码登录),
	// 参数为二维码链接
	OnQRCode(string)

	// 联系人更新,如:
	// 好友资料更新、删除好友或被好友删除等,
	// 建群、加入群、被拉入群、群改名、群成员变更、退群或被群主移出群等,
	// 第二个参数暂时没用
	OnContact(*Contact, int)

	// 收到消息,
	// 第二个参数暂时没用
	OnMessage(*Message, int)
}

type Message

type Message struct {
	Id           string
	FromUserName string
	ToUserName   string
	Content      string
	Url          string
	CreateTime   int64
	Type         int

	// 当前说话人(仅群消息有该字段)
	SpeakerUserName string
	// contains filtered or unexported fields
}

func (*Message) Bot

func (msg *Message) Bot() *Bot

func (*Message) GetAttr

func (msg *Message) GetAttr(attr interface{}, defaultValue interface{}) interface{}

func (*Message) GetAttrBool

func (msg *Message) GetAttrBool(attr string, defaultValue bool) bool

func (*Message) GetAttrInt

func (msg *Message) GetAttrInt(attr string, defaultValue int) int

func (*Message) GetAttrInt64

func (msg *Message) GetAttrInt64(attr string, defaultValue int64) int64

func (*Message) GetAttrString

func (msg *Message) GetAttrString(attr string, defaultValue string) string

func (*Message) GetAttrUint

func (msg *Message) GetAttrUint(attr string, defaultValue uint) uint

func (*Message) GetAttrUint64

func (msg *Message) GetAttrUint64(attr string, defaultValue uint64) uint64

func (*Message) GetFromContact

func (msg *Message) GetFromContact() *Contact

func (*Message) GetToContact

func (msg *Message) GetToContact() *Contact

func (*Message) Raw

func (msg *Message) Raw() []byte

func (*Message) ReplyImage

func (msg *Message) ReplyImage(data []byte, filename string) (string, error)

func (*Message) ReplyText

func (msg *Message) ReplyText(text string) error

func (*Message) ReplyVideo

func (msg *Message) ReplyVideo(data []byte, filename string) (string, error)

func (*Message) SetAttr

func (msg *Message) SetAttr(attr interface{}, value interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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