package module
v0.0.0-...-693f7c6 Latest Latest

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

Go to latest
Published: Aug 7, 2020 License: Apache-2.0 Imports: 29 Imported by: 1



rboot wechat adapter sdk forked from KevinGong2013/wechat




View Source
const (
	// Offical 公众号 ...
	Offical = 0
	// Friend 好友 ...
	Friend = 1
	// Group 群组 ...
	Group = 2
	// Member 群组成员 ...
	Member = 3
	// FriendAndMember 即是好友也是群成员 ...
	FriendAndMember = 4
View Source
const (
	// Delete 删除联系人
	Delete = 0
	// Modify 有人修改了自己的信息
	Modify = 1
View Source
const (
	// 男
	Male = iota
	// 女
	// 未知
	// 任何
View Source
const (
	EVENT_STOP_LOOP    int = 500
	EVENT_CLIENT_START int = iota + 1


This section is empty.


This section is empty.


type BaseRequest

type BaseRequest struct {
	XMLName xml.Name `xml:"error" json:"-"`

	Ret        int    `xml:"ret" json:"-"`
	Message    string `xml:"message" json:"-"`
	Wxsid      string `xml:"wxsid" json:"Sid"`
	Skey       string `xml:"skey"`
	DeviceID   string `xml:"-"`
	Wxuin      int64  `xml:"wxuin" json:"Uin"`
	PassTicket string `xml:"pass_ticket" json:"-"`

BaseRequest is a base for all wx api request.

type BaseResponse

type BaseResponse struct {
	Ret    int
	ErrMsg string

BaseResponse for all api resp.

type Caller

type Caller interface {
	IsSuccess() bool
	Error() error

Caller is a interface, All response need implement this.

type Configure

type Configure struct {
	Processor         UUIDProcessor
	Debug             bool
	CachePath         string
	UniqueGroupMember bool
	// contains filtered or unexported fields

Configure ...

func DefaultConfigure

func DefaultConfigure() *Configure

DefaultConfigure create default configuration

func NewConfigure

func NewConfigure(cachePath string, debug bool, processor UUIDProcessor) *Configure

type Contact

type Contact struct {
	UserName        string
	NickName        string
	HeadImgURL      string `json:"HeadImgUrl"`
	HeadHash        string
	RemarkName      string
	DisplayName     string
	StarFriend      float64
	Sex             float64
	Signature       string
	VerifyFlag      float64
	ContactFlag     float64
	HeadImgFlag     float64
	Province        string
	City            string
	Alias           string
	EncryChatRoomID string `json:"EncryChatRoomId"`
	Type            int
	MemberList      []*Contact

Contact is wx Account struct

func (*Contact) To

func (contact *Contact) To() string

To is contact's ID can be used in msg struct

type ContactData

type ContactData struct {
	ChangeType int
	Contact    Contact

EventContactData 通讯录中删人 或者有人修改资料的时候

type CountedContent

type CountedContent struct {
	Count   int
	Content []map[string]interface{}

CountedContent is a Wrappered for data struct from wx server

type Event

type Event struct {
	Type int
	From string
	To   string
	Data interface{}
	Time int64

Event ...

type Msg

type Msg interface {
	Path() string
	To() string
	Content() map[string]interface{}

	Description() string

Msg implement this interface, can added addition send by wechat

type MsgData

type MsgData struct {
	IsGroupMsg       bool
	IsMediaMsg       bool
	IsSendedByMySelf bool
	MsgType          int64
	AtMe             bool
	MediaURL         string
	Content          string
	FromUserName     string
	SenderUserName   string
	ToUserName       string
	OriginalMsg      map[string]interface{}

EventMsgData 新消息

type Response

type Response struct {
	BaseResponse *BaseResponse

Response is a wrapper.

func (*Response) Error

func (response *Response) Error() error

response's error msg.

func (*Response) IsSuccess

func (response *Response) IsSuccess() bool

IsSuccess flag this request is success or failed.

type Stream

type Stream struct {
	Event chan Event
	Hook  func(Event)

type UUIDProcessor

type UUIDProcessor interface {
	ProcessUUID(uuid string) error
	UUIDDidConfirm(err error)

UUIDProcessor scan this uuid

type WeChat

type WeChat struct {
	Client      *http.Client
	BaseURL     string
	BaseRequest *BaseRequest
	MySelf      Contact
	IsLogin     bool
	Stream      *Stream
	SyncNotify  chan int
	// contains filtered or unexported fields

WeChat container a default http client and base request.

func NewBot

func NewBot(conf *Configure) (*WeChat, error)

NewBot is start point for wx bot.

func (*WeChat) AllContacts

func (wechat *WeChat) AllContacts() []*Contact

AllContacts ...

func (*WeChat) ContactByUserName

func (wechat *WeChat) ContactByUserName(un string) *Contact

ContactByUserName ...

func (*WeChat) CookieDataTicket

func (wechat *WeChat) CookieDataTicket() string

CookieDataTicket ...

func (*WeChat) DownloadMedia

func (wechat *WeChat) DownloadMedia(url string, localPath string) (string, error)

DownloadMedia use to download a voice or immage msg

func (*WeChat) Execute

func (wechat *WeChat) Execute(path string, body io.Reader, call Caller) error

Execute a http request by default http client.

func (*WeChat) ExecuteRequest

func (wechat *WeChat) ExecuteRequest(req *http.Request, call Caller) error

ExecuteRequest is designed for perform http request

func (*WeChat) ForceUpdateGroup

func (wechat *WeChat) ForceUpdateGroup(groupID string)

ForceUpdateGroup update group information

func (*WeChat) GetContactHeadImg

func (wechat *WeChat) GetContactHeadImg(c *Contact) ([]byte, error)

GetContactHeadImg ...

func (*WeChat) Go

func (wechat *WeChat) Go()

Go 皮皮虾我们走

func (*WeChat) Hook

func (wechat *WeChat) Hook(f func(Event))

Hook modify event on fly

func (*WeChat) MembersOfGroup

func (wechat *WeChat) MembersOfGroup(groupUserName string) ([]*Contact, error)

MembersOfGroup ..返回群中所有的成员

func (*WeChat) PassTicketKV

func (wechat *WeChat) PassTicketKV() string

PassTicketKV return a string like `pass_ticket=1234s`

func (*WeChat) SearchContact

func (wechat *WeChat) SearchContact(nickName string, city string, sex int, contactType int) ([]*Contact, error)

ContactsByNickName search contact with nick name

func (*WeChat) SendFile

func (wechat *WeChat) SendFile(path, to string) error

SendFile is desined to send contain attachment Message to group or contact. path must exit in local file system.

func (*WeChat) SendMsg

func (wechat *WeChat) SendMsg(message Msg) error

SendMsg send Message to group or contact

func (*WeChat) SendTextMsg

func (wechat *WeChat) SendTextMsg(msg, to string) error

SendTextMsg send text message

func (*WeChat) SkeyKV

func (wechat *WeChat) SkeyKV() string

SkeyKV return a string like `skey=1234s`

func (*WeChat) SyncContact

func (wechat *WeChat) SyncContact() error

SyncContact with Wechat server.

func (*WeChat) UpdateGroupIfNeeded

func (wechat *WeChat) UpdateGroupIfNeeded(groupID string)

UpdateGroupIfNeeded ...

func (*WeChat) UploadMedia

func (wechat *WeChat) UploadMedia(buf []byte, kind types.Type, info os.FileInfo, to string) (string, error)

UploadMedia is a convernice method to upload attachment to wx cdn.


Path Synopsis

Jump to

Keyboard shortcuts

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