wxweb

package
v0.0.0-...-4291033 Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// msg types
	MSG_TEXT        = 1     // text message
	MSG_IMG         = 3     // image message
	MSG_VOICE       = 34    // voice message
	MSG_FV          = 37    // friend verification message
	MSG_PF          = 40    // POSSIBLEFRIEND_MSG
	MSG_SCC         = 42    // shared contact card
	MSG_VIDEO       = 43    // video message
	MSG_EMOTION     = 47    // gif
	MSG_LOCATION    = 48    // location message
	MSG_LINK        = 49    // shared link message
	MSG_VOIP        = 50    // VOIPMSG
	MSG_INIT        = 51    // wechat init message
	MSG_VOIPNOTIFY  = 52    // VOIPNOTIFY
	MSG_VOIPINVITE  = 53    // VOIPINVITE
	MSG_SHORT_VIDEO = 62    // short video message
	MSG_SYSNOTICE   = 9999  // SYSNOTICE
	MSG_SYS         = 10000 // system message
	MSG_WITHDRAW    = 10002 // withdraw notification message

)
View Source
const (
	// WEB_MODE: in this mode CreateSession will return a QRCode image url
	WEB_MODE = iota + 1
	// MINAL_MODE:  CreateSession will output qrcode in terminal
	TERMINAL_MODE
)

Variables

View Source
var (
	// DefaultCommon: default session config
	DefaultCommon = &Common{
		AppId:      "wx782c26e4c19acffb",
		LoginUrl:   "https://login.weixin.qq.com",
		Lang:       "zh_CN",
		DeviceID:   "e" + GetRandomStringFromNum(15),
		UserAgent:  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36",
		SyncSrv:    "webpush.wx.qq.com",
		UploadUrl:  "https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json",
		MediaCount: 0,
	}
)
View Source
var (
	// SpecialContact: special contacts map
	SpecialContact = map[string]bool{
		"filehelper":            true,
		"newsapp":               true,
		"fmessage":              true,
		"weibo":                 true,
		"qqmail":                true,
		"tmessage":              true,
		"qmessage":              true,
		"qqsync":                true,
		"floatbottle":           true,
		"lbsapp":                true,
		"shakeapp":              true,
		"medianote":             true,
		"qqfriend":              true,
		"readerapp":             true,
		"blogapp":               true,
		"facebookapp":           true,
		"masssendapp":           true,
		"meishiapp":             true,
		"feedsapp":              true,
		"voip":                  true,
		"blogappweixin":         true,
		"weixin":                true,
		"brandsessionholder":    true,
		"weixinreminder":        true,
		"officialaccounts":      true,
		"wxitil":                true,
		"userexperience_alarm":  true,
		"notification_messages": true,
	}
)

Functions

func GetRandomStringFromNum

func GetRandomStringFromNum(length int) string

func JsLogin

func JsLogin(common *Common) (string, error)

JsLogin: jslogin api

func Login

func Login(common *Common, uuid, tip string) (string, error)

Login: login api

func QrCode

func QrCode(common *Common, uuid string) ([]byte, error)

QrCode: get qrcode

func RealTargetUserName

func RealTargetUserName(session *Session, msg *ReceivedMessage) string

func SyncCheck

func SyncCheck(common *Common, ce *XmlConfig, cookies []*http.Cookie,
	server string, skl *SyncKeyList) (int, int, error)

SyncCheck: synccheck api

func WebNewLoginPage

func WebNewLoginPage(common *Common, xc *XmlConfig, uri string) ([]*http.Cookie, error)

WebNewLoginPage: webwxnewloginpage api

func WebWxBatchGetContact

func WebWxBatchGetContact(common *Common, ce *XmlConfig, cookies []*http.Cookie, cl []*User) ([]byte, error)

WebWxBatchGetContact: webwxbatchgetcontact api

func WebWxCreateChatroom

func WebWxCreateChatroom(common *Common, ce *XmlConfig, cookies []*http.Cookie, users []*User, topic string) (interface{}, error)

WebWxCreateChatroom: webwxcreatechatroom api

func WebWxGetContact

func WebWxGetContact(common *Common, ce *XmlConfig, cookies []*http.Cookie) ([]byte, error)

WebWxGetContact: webwxgetcontact api

func WebWxGetIcon

func WebWxGetIcon(common *Common, ce *XmlConfig, cookies []*http.Cookie,
	username, chatroomid string) ([]byte, error)

WebWxGetIcon: webwxgeticon api

func WebWxGetIconByHeadImgUrl

func WebWxGetIconByHeadImgUrl(common *Common, ce *XmlConfig, cookies []*http.Cookie, headImgUrl string) ([]byte, error)

WebWxGetIconByHeadImgUrl: get head img

func WebWxGetMsgImg

func WebWxGetMsgImg(common *Common, ce *XmlConfig, cookies []*http.Cookie, msgId string) ([]byte, error)

WebWxGetMsgImg: webwxgetmsgimg api

func WebWxInit

func WebWxInit(common *Common, ce *XmlConfig) ([]byte, error)

WebWxInit: webwxinit api

func WebWxLogout

func WebWxLogout(common *Common, ce *XmlConfig, cookies []*http.Cookie) error

WebWxlogout: webwxlogout api

func WebWxRevokeMsg

func WebWxRevokeMsg(common *Common, ce *XmlConfig, cookies []*http.Cookie, clientMsgId, svrMsgId, toUserName string) error

WebWxRevokeMsg: webwxrevokemsg api

func WebWxSendEmoticon

func WebWxSendEmoticon(common *Common, ce *XmlConfig, cookies []*http.Cookie,
	from, to, media string) (int, error)

WebWxSendEmoticon: webwxsendemoticon api

func WebWxSendMsg

func WebWxSendMsg(common *Common, ce *XmlConfig, cookies []*http.Cookie,
	from, to string, msg string) ([]byte, error)

WebWxSendMsg: webwxsendmsg api

func WebWxSendMsgImg

func WebWxSendMsgImg(common *Common, ce *XmlConfig, cookies []*http.Cookie,
	from, to, media string) (int, error)

WebWxSendMsgImg: webwxsendmsgimg api

func WebWxStatusNotify

func WebWxStatusNotify(common *Common, ce *XmlConfig, bot *User) (int, error)

WebWxStatusNotify: webwxstatusnotify api

func WebWxSync

func WebWxSync(common *Common,
	ce *XmlConfig,
	cookies []*http.Cookie,
	msg chan []byte, skl *SyncKeyList) error

WebWxSync: webwxsync api

func WebWxUploadMedia

func WebWxUploadMedia(common *Common, ce *XmlConfig, cookies []*http.Cookie,
	filename string, content []byte) (string, error)

WebWxUploadMedia: webwxuploadmedia api

func WebWxVerifyUser

func WebWxVerifyUser(common *Common, ce *XmlConfig, cookies []*http.Cookie, verifyContent string, vul []*VerifyUser) ([]byte, error)

WebWxVerifyUser: webwxverifyuser api

Types

type BaseRequest

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

BaseRequest: http request body BaseRequest

type BaseResponse

type BaseResponse struct {
	Ret    int
	ErrMsg string
}

BaseResponse: web api http response body BaseResponse struct

type Common

type Common struct {
	AppId       string
	LoginUrl    string
	Lang        string
	DeviceID    string
	UserAgent   string
	CgiUrl      string
	CgiDomain   string
	SyncSrv     string
	UploadUrl   string
	MediaCount  uint32
	RedirectUri string
}

Common: session config

type ContactManager

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

ContactManager: contact manager

func CreateContactManagerFromBytes

func CreateContactManagerFromBytes(cb []byte) (*ContactManager, error)

CreateContactManagerFromBytes: create contact maanger from bytes

func (*ContactManager) AddContactFromBytes

func (s *ContactManager) AddContactFromBytes(cb []byte) error

AddContactFromBytes upate contact manager from bytes

func (*ContactManager) AddContactFromUser

func (s *ContactManager) AddContactFromUser(user *User)

AddContactFromUser add a new user contact to contact manager

func (*ContactManager) GetAll

func (s *ContactManager) GetAll() []*User

GetAll: get all contacts

func (*ContactManager) GetContactByName

func (s *ContactManager) GetContactByName(sig string) []*User

GetContactByName: get contacts by name

func (*ContactManager) GetContactByPYQuanPin

func (s *ContactManager) GetContactByPYQuanPin(sig string) *User

GetContactByPYQuanPin: get contact by User.PYQuanPin

func (*ContactManager) GetContactByUserName

func (s *ContactManager) GetContactByUserName(un string) *User

GetContactByUserName get contact by UserName

func (*ContactManager) GetGroupContacts

func (s *ContactManager) GetGroupContacts() []*User

GetGroupContacts: get group contacts

func (*ContactManager) GetStrangers

func (s *ContactManager) GetStrangers() []*User

GetStrangers: not group and not StarFriend

type ContactResponse

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

ContactResponse: get contact response struct

type EmotionMessage

type EmotionMessage struct {
	ClientMsgId  int
	EmojiFlag    int
	FromUserName string
	LocalID      int
	MediaId      string
	ToUserName   string
	Type         int
}

EmotionMessage: gif/emoji message struct

type GroupContactResponse

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

GroupContactResponse: get batch contact response struct

type Handler

type Handler func(*Session, *ReceivedMessage)

Handler: message function wrapper

type HandlerRegister

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

HandlerRegister: message handler manager

func CreateHandlerRegister

func CreateHandlerRegister() *HandlerRegister

CreateHandlerRegister: create handler register

func (*HandlerRegister) Add

func (hr *HandlerRegister) Add(key int, h Handler, name string) error

Add: add message callback handle to handler register

func (*HandlerRegister) DisableByName

func (hr *HandlerRegister) DisableByName(name string) error

DisableByName: disable message handler by name

func (*HandlerRegister) DisableByType

func (hr *HandlerRegister) DisableByType(key int) error

DisableByType: disable handler by message type

func (*HandlerRegister) Dump

func (hr *HandlerRegister) Dump() string

Dump: output all message handlers

func (*HandlerRegister) EnableByName

func (hr *HandlerRegister) EnableByName(name string) error

EnableByName: enable message handler by name

func (*HandlerRegister) EnableByType

func (hr *HandlerRegister) EnableByType(key int) error

EnableByType: enable handler by message type

func (*HandlerRegister) Get

func (hr *HandlerRegister) Get(key int) (error, []*HandlerWrapper)

Get: get message handler

type HandlerWrapper

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

HandlerWrapper: message handler wrapper

func (*HandlerWrapper) Run

func (s *HandlerWrapper) Run(session *Session, msg *ReceivedMessage)

Run: message handler callback

type InitReqBody

type InitReqBody struct {
	BaseRequest *BaseRequest
	Msg         interface{}
	SyncKey     *SyncKeyList

	Code               int
	FromUserName       string
	ToUserName         string
	ClientMsgId        int
	ClientMediaId      int
	TotalLen           int
	StartPos           int
	DataLen            int
	MediaType          int
	Scene              int
	Count              int
	List               []*User
	Opcode             int
	SceneList          []int
	SceneListCount     int
	VerifyContent      string
	VerifyUserList     []*VerifyUser
	VerifyUserListSize int

	MemberCount int
	MemberList  []*User
	Topic       string
	// contains filtered or unexported fields
}

InitReqBody: common http request body struct

type LogoutReqBody

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

LogoutReqBody: logout api http request body

type MediaMessage

type MediaMessage struct {
	Type         int
	Content      string
	FromUserName string
	ToUserName   string
	LocalID      int
	ClientMsgId  int
	MediaId      string
}

MediaMessage

type MemberManager

type MemberManager struct {
	Group *User
}

func CreateMemberManagerFromBytes

func CreateMemberManagerFromBytes(b []byte) (*MemberManager, error)

func CreateMemberManagerFromGroupContact

func CreateMemberManagerFromGroupContact(session *Session, user *User) (*MemberManager, error)

func (*MemberManager) GetContactByUserName

func (s *MemberManager) GetContactByUserName(username string) *User

func (*MemberManager) GetContactsByGender

func (s *MemberManager) GetContactsByGender(sex int) []*User

func (*MemberManager) GetHeadImgUrlByGender

func (s *MemberManager) GetHeadImgUrlByGender(sex int) []string

func (*MemberManager) Update

func (s *MemberManager) Update(session *Session) error

type ReceivedMessage

type ReceivedMessage struct {
	IsGroup       bool
	MsgId         string
	Content       string
	FromUserName  string
	ToUserName    string
	Who           string
	MsgType       int
	OriginContent string
	At            string
}

ReceivedMessage: for received message

type RevokeReqBody

type RevokeReqBody struct {
	BaseRequest *BaseRequest
	ClientMsgId string
	SvrMsgId    string
	ToUserName  string
}

RevokeReqBody: revoke message api http request body

type Session

type Session struct {
	WxWebCommon     *Common
	WxWebXcg        *XmlConfig
	Cookies         []*http.Cookie
	SynKeyList      *SyncKeyList
	Bot             *User
	Cm              *ContactManager
	QrcodePath      string //qrcode path
	QrcodeUUID      string //uuid
	HandlerRegister *HandlerRegister
}

Session: wechat bot session

func CreateSession

func CreateSession(common *Common, handlerRegister *HandlerRegister, qrmode int) (*Session, error)

CreateSession: create wechat bot session if common is nil, session will be created with default config if handlerRegister is nil, session will create a new HandlerRegister

func (*Session) GetImg

func (s *Session) GetImg(msgId string) ([]byte, error)

GetImg: get img by MsgId

func (*Session) LoginAndServe

func (s *Session) LoginAndServe(useCache bool) error

LoginAndServe: login wechat web and enter message receiving loop

func (*Session) Logout

func (s *Session) Logout() error

func (*Session) RevokeMsg

func (s *Session) RevokeMsg(clientMsgId, svrMsgId, toUserName string)

RevokeMsg: revoke message

func (*Session) SendEmotionFromBytes

func (s *Session) SendEmotionFromBytes(b []byte, from, to string)

SendEmotionFromBytes: send gif/emoji from mem

func (*Session) SendEmotionFromPath

func (s *Session) SendEmotionFromPath(path, from, to string)

SendEmotionFromPath: send gif, upload then send

func (*Session) SendImg

func (s *Session) SendImg(path, from, to string)

SendImg: send img, upload then send

func (*Session) SendImgFromBytes

func (s *Session) SendImgFromBytes(b []byte, path, from, to string)

SendImgFromBytes: send image from mem

func (*Session) SendText

func (s *Session) SendText(msg, from, to string) (string, string, error)

SendText: send text msg type 1

type SyncKey

type SyncKey struct {
	Key int
	Val int
}

SyncKey: struct for synccheck

type SyncKeyList

type SyncKeyList struct {
	Count int
	List  []SyncKey
}

SyncKeyList: list of synckey

func GetSyncKeyListFromJc

func GetSyncKeyListFromJc(jc *rrconfig.JsonConfig) (*SyncKeyList, error)

func (*SyncKeyList) String

func (s *SyncKeyList) String() string

s.String output synckey list in string

type TextMessage

type TextMessage struct {
	Type         int
	Content      string
	FromUserName string
	ToUserName   string
	LocalID      int
	ClientMsgId  int
}

TextMessage: text message struct

type User

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

User: contact struct

func GetUserInfoFromJc

func GetUserInfoFromJc(jc *rrconfig.JsonConfig) (*User, error)

type VerifyUser

type VerifyUser struct {
	Value            string
	VerifyUserTicket string
}

VerifyUser: verify user request body struct

type XmlConfig

type XmlConfig struct {
	XMLName     xml.Name `xml:"error"`
	Ret         int      `xml:"ret"`
	Message     string   `xml:"message"`
	Skey        string   `xml:"skey"`
	Wxsid       string   `xml:"wxsid"`
	Wxuin       string   `xml:"wxuin"`
	PassTicket  string   `xml:"pass_ticket"`
	IsGrayscale int      `xml:"isgrayscale"`
}

XmlConfig: web api xml response struct

Jump to

Keyboard shortcuts

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