Documentation
¶
Index ¶
- Constants
- Variables
- func GetRandomStringFromNum(length int) string
- func JsLogin(common *Common) (string, error)
- func Login(common *Common, uuid, tip string) (string, error)
- func QrCode(common *Common, uuid string) ([]byte, error)
- func RealTargetUserName(session *Session, msg *ReceivedMessage) string
- func SyncCheck(common *Common, ce *XmlConfig, cookies []*http.Cookie, server string, ...) (int, int, error)
- func WebNewLoginPage(common *Common, xc *XmlConfig, uri string) ([]*http.Cookie, error)
- func WebWxBatchGetContact(common *Common, ce *XmlConfig, cookies []*http.Cookie, cl []*User) ([]byte, error)
- func WebWxCreateChatroom(common *Common, ce *XmlConfig, cookies []*http.Cookie, users []*User, ...) (interface{}, error)
- func WebWxGetContact(common *Common, ce *XmlConfig, cookies []*http.Cookie) ([]byte, error)
- func WebWxGetIcon(common *Common, ce *XmlConfig, cookies []*http.Cookie, ...) ([]byte, error)
- func WebWxGetIconByHeadImgUrl(common *Common, ce *XmlConfig, cookies []*http.Cookie, headImgUrl string) ([]byte, error)
- func WebWxGetMsgImg(common *Common, ce *XmlConfig, cookies []*http.Cookie, msgId string) ([]byte, error)
- func WebWxInit(common *Common, ce *XmlConfig) ([]byte, error)
- func WebWxLogout(common *Common, ce *XmlConfig, cookies []*http.Cookie) error
- func WebWxRevokeMsg(common *Common, ce *XmlConfig, cookies []*http.Cookie, ...) error
- func WebWxSendEmoticon(common *Common, ce *XmlConfig, cookies []*http.Cookie, from, to, media string) (int, error)
- func WebWxSendMsg(common *Common, ce *XmlConfig, cookies []*http.Cookie, from, to string, ...) ([]byte, error)
- func WebWxSendMsgImg(common *Common, ce *XmlConfig, cookies []*http.Cookie, from, to, media string) (int, error)
- func WebWxStatusNotify(common *Common, ce *XmlConfig, bot *User) (int, error)
- func WebWxSync(common *Common, ce *XmlConfig, cookies []*http.Cookie, msg chan []byte, ...) error
- func WebWxUploadMedia(common *Common, ce *XmlConfig, cookies []*http.Cookie, filename string, ...) (string, error)
- func WebWxVerifyUser(common *Common, ce *XmlConfig, cookies []*http.Cookie, verifyContent string, ...) ([]byte, error)
- type BaseRequest
- type BaseResponse
- type Common
- type ContactManager
- func (s *ContactManager) AddContactFromBytes(cb []byte) error
- func (s *ContactManager) AddContactFromUser(user *User)
- func (s *ContactManager) GetAll() []*User
- func (s *ContactManager) GetContactByName(sig string) []*User
- func (s *ContactManager) GetContactByPYQuanPin(sig string) *User
- func (s *ContactManager) GetContactByUserName(un string) *User
- func (s *ContactManager) GetGroupContacts() []*User
- func (s *ContactManager) GetStrangers() []*User
- type ContactResponse
- type EmotionMessage
- type GroupContactResponse
- type Handler
- type HandlerRegister
- func (hr *HandlerRegister) Add(key int, h Handler, name string) error
- func (hr *HandlerRegister) DisableByName(name string) error
- func (hr *HandlerRegister) DisableByType(key int) error
- func (hr *HandlerRegister) Dump() string
- func (hr *HandlerRegister) EnableByName(name string) error
- func (hr *HandlerRegister) EnableByType(key int) error
- func (hr *HandlerRegister) Get(key int) (error, []*HandlerWrapper)
- type HandlerWrapper
- type InitReqBody
- type LogoutReqBody
- type MediaMessage
- type MemberManager
- type ReceivedMessage
- type RevokeReqBody
- type Session
- func (s *Session) GetImg(msgId string) ([]byte, error)
- func (s *Session) LoginAndServe(useCache bool) error
- func (s *Session) Logout() error
- func (s *Session) RevokeMsg(clientMsgId, svrMsgId, toUserName string)
- func (s *Session) SendEmotionFromBytes(b []byte, from, to string)
- func (s *Session) SendEmotionFromPath(path, from, to string)
- func (s *Session) SendImg(path, from, to string)
- func (s *Session) SendImgFromBytes(b []byte, path, from, to string)
- func (s *Session) SendText(msg, from, to string) (string, string, error)
- type SyncKey
- type SyncKeyList
- type TextMessage
- type User
- type VerifyUser
- type XmlConfig
Constants ¶
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 )
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 ¶
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, } )
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 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 ¶
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 ¶
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 WebWxLogout ¶
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 ¶
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 ¶
BaseRequest: http request body BaseRequest
type BaseResponse ¶
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) 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 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) LoginAndServe ¶
LoginAndServe: login wechat web and enter message receiving loop
func (*Session) SendEmotionFromBytes ¶
SendEmotionFromBytes: send gif/emoji from mem
func (*Session) SendEmotionFromPath ¶
SendEmotionFromPath: send gif, upload then send
func (*Session) SendImgFromBytes ¶
SendImgFromBytes: send image from mem
type SyncKeyList ¶
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 ¶
type VerifyUser ¶
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