padchat

package module
v0.0.0-...-4a44145 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2018 License: LGPL-3.0 Imports: 11 Imported by: 0

README

PadChat

GoDoc

Installation

go get -u github.com/tuotoo/padchat

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MkAtContent

func MkAtContent(req *SendMsgReq)

MkAtContent prefix 'at' symbol for req content if necessary

Types

type AddFavResp

type AddFavResp struct {
	ID      int    `json:"id"`
	Message string `json:"message"`
	Seq     int    `json:"seq"`
	Status  int    `json:"status"`
}

type Bot

type Bot struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBot

func NewBot(url string) (*Bot, error)

NewBot 乃万物之始 新建 Bot 实例, 传入 PadChat 服务端地址

func (*Bot) AcceptTransfer

func (bot *Bot) AcceptTransfer(rawMsgData Msg) (*ExternalMsgResp, error)

AcceptTransfer 接受转账 mType = 49 使用 bytes.Contains(msg.Content, []byte("<![CDATA[微信转账]]>")) 与红包区分

func (*Bot) AcceptUser

func (bot *Bot) AcceptUser(stranger, ticket string) (*MsgAndStatus, error)

AcceptUser 通过好友验证

func (*Bot) AddContact

func (bot *Bot) AddContact(stranger, ticket, content string, Type int) (*MsgAndStatus, error)

AddContact 添加好友 0: 通过微信号搜索 1: 搜索QQ号 3: 通过微信号搜索 4: 通过QQ好友添加 8: 通过群聊 12: 来自QQ好友 14: 通过群聊 15: 通过搜索手机号 17: 通过名片分享 22: 通过摇一摇打招呼方式 25: 通过漂流瓶 30: 通过二维码方式

func (*Bot) AddFav

func (bot *Bot) AddFav(content string) (*AddFavResp, error)

AddFav 添加收藏

func (*Bot) AddLabel

func (bot *Bot) AddLabel(label string) (*MsgAndStatus, error)

AddLabel 添加标签

func (*Bot) AddRoomMember

func (bot *Bot) AddRoomMember(groupID, userID string) (*MsgAndStatus, error)

AddRoomMember 添加群成员

func (*Bot) Close

func (bot *Bot) Close() CommandResp

Close 关闭微信实例(不退出登陆)

func (*Bot) CloseWS

func (bot *Bot) CloseWS()

func (*Bot) CreateRoom

func (bot *Bot) CreateRoom(userList []string) (*CreateRoomResp, error)

CreateRoom 创建群

func (*Bot) DeleteContact

func (bot *Bot) DeleteContact(userID string) (*MsgAndStatus, error)

DeleteContact 删除好友

func (*Bot) DeleteFav

func (bot *Bot) DeleteFav(favID int) (*FavResp, error)

DeleteFav 删除收藏

func (*Bot) DeleteLabel

func (bot *Bot) DeleteLabel(labelID int) (*MsgAndStatus, error)

DeleteLabel 删除标签

func (*Bot) DeleteRoomMember

func (bot *Bot) DeleteRoomMember(groupID, userID string) (*MsgAndStatus, error)

DeleteRoomMember 删除群成员

func (*Bot) GetContact

func (bot *Bot) GetContact(userID string) (*Contact, error)

GetContact 获取用户/群信息

func (*Bot) GetFav

func (bot *Bot) GetFav(favID int) (*FavResp, error)

GetFav 获取收藏消息详情

func (*Bot) GetLabelList

func (bot *Bot) GetLabelList() (*LabelListResp, error)

GetLabelList 获取所有标签

func (*Bot) GetLoginToken

func (bot *Bot) GetLoginToken() (*LoginTokenResp, error)

GetLoginToken 获取二次登陆数据

func (*Bot) GetMsgImage

func (bot *Bot) GetMsgImage(rawMsgData Msg) (*MsgImageResp, error)

GetMsgImage 获取消息原始图片 mType = 3

func (*Bot) GetMsgVideo

func (bot *Bot) GetMsgVideo(rawMsgData Msg) (*MsgVideoResp, error)

GetMsgVideo 获取消息原始视频 mType = 43

func (*Bot) GetMsgVoice

func (bot *Bot) GetMsgVoice(rawMsgData Msg) (*MsgVoiceResp, error)

GetMsgVoice 获取消息语音数据 mType = 34

func (*Bot) GetMyInfo

func (bot *Bot) GetMyInfo() (*MyInfoResp, error)

GetMyInfo 获取Bot微信号信息

func (*Bot) GetRequestToken

func (bot *Bot) GetRequestToken(ghName, url string) (*RequestTokenResp, error)

GetRequestToken 获取网页访问授权

func (*Bot) GetRoomMembers

func (bot *Bot) GetRoomMembers(groupID string) (*ChatroomInfo, error)

GetRoomMembers 获取群成员信息

func (*Bot) GetRoomQRCode

func (bot *Bot) GetRoomQRCode(groupID string) (*QRCodeResp, error)

GetRoomQRCode 获取微信群二维码

func (*Bot) GetSubscriptionInfo

func (bot *Bot) GetSubscriptionInfo(ghName string) (*SearchMPResp, error)

GetSubscriptionInfo 获取公众号信息

func (*Bot) GetUserQRCode

func (bot *Bot) GetUserQRCode(userID string, style int) (*QRCodeResp, error)

GetUserQRCode 获取用户二维码, 仅限获取自己的二维码, 无法获取其他人的二维码

func (*Bot) GetWXData

func (bot *Bot) GetWXData() (string, error)

GetWXData 获取设备62数据

func (*Bot) Init

func (bot *Bot) Init() CommandResp

Init 执行初始化, 必须在登录前调用

func (*Bot) InviteRoomMember

func (bot *Bot) InviteRoomMember(groupID, userID string) (*MsgAndStatus, error)

InviteRoomMember 邀请群成员, 会给对方发送一条邀请消息, 无法判断对方是否真的接收到

func (*Bot) Logout

func (bot *Bot) Logout() CommandResp

Logout 退出登录

func (*Bot) OnClose

func (bot *Bot) OnClose(f func(code int, text string) error)

OnClose ws 断开回调

func (*Bot) OnContactSync

func (bot *Bot) OnContactSync(f func(contact Contact))

OnContactSync 联系人同步回调

func (*Bot) OnLoaded

func (bot *Bot) OnLoaded(f func())

OnLoaded 联系人加载完成回调

func (*Bot) OnLogin

func (bot *Bot) OnLogin(f func())

OnLogin 登录成功回调

func (*Bot) OnMsg

func (bot *Bot) OnMsg(f func(msg Msg))

OnMsg 微信接收消息回调

func (*Bot) OnQRURL

func (bot *Bot) OnQRURL(f func(string))

OnQRURL 收到二维码回调, 需在执行二维码登录前配置

func (*Bot) OnScan

func (bot *Bot) OnScan(f func(resp ScanResp))

OnScan 二维码扫描回调

func (*Bot) OnWarn

func (bot *Bot) OnWarn(f func(err string))

func (*Bot) OpenRedPacket

func (bot *Bot) OpenRedPacket(rawMsgData Msg, key string) (*ExternalMsgResp, error)

OpenRedPacket 领取红包

func (*Bot) OperateSubscription

func (bot *Bot) OperateSubscription(ghName string, menuId int, menuKey string) (*MsgAndStatus, error)

OperateSubscription 操作公众号菜单

func (*Bot) PhoneLogin

func (bot *Bot) PhoneLogin(wxData, phone, code string) CommandResp

PhoneLogin 手机验证码登录

func (*Bot) QRLogin

func (bot *Bot) QRLogin() CommandResp

QRLogin 二维码登录

func (*Bot) QueryRedPacket

func (bot *Bot) QueryRedPacket(rawMsgData Msg, index int) (*ExternalMsgResp, error)

QueryRedPacket 查看红包信息, 如果是别人发的红包, 未领取且未领取完毕时, 无法取到红包信息

func (*Bot) QueryTransfer

func (bot *Bot) QueryTransfer(rawMsgData Msg) (*ExternalMsgResp, error)

QueryTransfer 查看转账消息

func (*Bot) QuitRoom

func (bot *Bot) QuitRoom(groupID string) (*MsgAndStatus, error)

QuitRoom 退出群

func (*Bot) ReceiveRedPacket

func (bot *Bot) ReceiveRedPacket(rawMsgData Msg) (*ExternalMsgResp, error)

ReceiveRedPacket 接收红包 mType = 49 使用 bytes.Contains(msg.Content, []byte("<![CDATA[微信红包]]>")) 与转账区分

func (*Bot) RequestLogin

func (bot *Bot) RequestLogin(wxData, token string) CommandResp

RequestLogin 二次登陆, 手机端会弹出确认框, 点击后登陆, 不容易封号

func (*Bot) RequestUrl

func (bot *Bot) RequestUrl(url, xKey, xUin string) (*RequestUrlResp, error)

RequestUrl 访问网页

func (*Bot) SNSComment

func (bot *Bot) SNSComment(userID, momentID, content string) (*MomentDetailResp, error)

SNSComment 评论朋友圈

func (*Bot) SNSGetObject

func (bot *Bot) SNSGetObject(momentID string) (*MomentDetailResp, error)

SNSGetObject 获取朋友圈信息详情

func (*Bot) SNSLike

func (bot *Bot) SNSLike(userID, momentID string) (*MomentDetailResp, error)

SNSLike 朋友圈点赞

func (*Bot) SNSObjectOperation

func (bot *Bot) SNSObjectOperation(momentID, commentID string,
	Type, commentType int) (*MsgAndStatus, error)

SNSObjectOperation 操作朋友圈 type - 操作类型,1为删除朋友圈,4为删除评论,5为取消赞 commentType - 操作类型,当删除评论时可用,需与评论type字段一致

func (*Bot) SNSSendMoment

func (bot *Bot) SNSSendMoment(content string) (*MomentResp, error)

SNSSendMoment 发朋友圈 content - 文本内容或 TimeLineObject 结构体文本

func (*Bot) SNSTimeLine

func (bot *Bot) SNSTimeLine(momentID string) (*MomentListResp, error)

SNSTimeLine 查看朋友圈动态 momentID 首次传入空即获取第一页, 以后传入上次拉取的最后一条信息ID

func (*Bot) SNSUpload

func (bot *Bot) SNSUpload(file string) (*SNSUploadResp, error)

SNSUpload 上传图片到朋友圈 此接口只能上传图片,并不会将图片发到朋友圈中

func (*Bot) SNSUserPage

func (bot *Bot) SNSUserPage(userID, momentID string) (*MomentListResp, error)

SNSUserPage 查看用户朋友圈 momentID 首次传入空即获取第一页, 以后传入上次拉取的最后一条信息ID

func (*Bot) SayHello

func (bot *Bot) SayHello(stranger, ticket, content string) (*MsgAndStatus, error)

SayHello 打招呼,如果已经是好友, 会收到由系统自动发送, 来自对方的一条文本信息 "xx已通过你的朋友验证请求,现在可以开始聊天了"

func (*Bot) SearchContact

func (bot *Bot) SearchContact(userID string) (*Contact, error)

SearchContact 搜索用户

func (*Bot) SearchMp

func (bot *Bot) SearchMp(content string) (*SearchMPResp, error)

SearchMp 搜索公众号

func (*Bot) SendImage

func (bot *Bot) SendImage(req SendMsgReq) (*SendMsgResp, error)

SendImage 发送图片消息, file 为图片 base64 数据

func (*Bot) SendMsg

func (bot *Bot) SendMsg(req *SendMsgReq) (*SendMsgResp, error)

SendMsg 发送文字信息

func (*Bot) SetCommandTimeout

func (bot *Bot) SetCommandTimeout(t time.Duration)

SetCommandTimeout 设置微信指令超时时间, 默认为 30 秒

func (*Bot) SetHeadImg

func (bot *Bot) SetHeadImg(file string) (*ImgResp, error)

SetHeadImg 设置头像

func (*Bot) SetLabel

func (bot *Bot) SetLabel(userID string, labelID int) (*MsgAndStatus, error)

SetLabel 设置用户标签

func (*Bot) SetRemark

func (bot *Bot) SetRemark(userID, remark string) (*MsgAndStatus, error)

SetRemark 设置备注

func (*Bot) SetRoomAnnouncement

func (bot *Bot) SetRoomAnnouncement(groupID, content string) (*MsgAndStatus, error)

SetRoomAnnouncement 设置群公告

func (*Bot) SetRoomName

func (bot *Bot) SetRoomName(groupID, content string) (*MsgAndStatus, error)

SetRoomName 设置群名称

func (*Bot) ShareCard

func (bot *Bot) ShareCard(toUserName, content, userId string) (*SendMsgResp, error)

ShareCard 分享名片

func (*Bot) SyncContact

func (bot *Bot) SyncContact() CommandResp

SyncContact 同步通讯录

func (*Bot) SyncFav

func (bot *Bot) SyncFav(favKey string) (*FavListResp, error)

SyncFav 同步收藏消息

func (*Bot) SyncMsg

func (bot *Bot) SyncMsg() CommandResp

SyncMsg 同步消息, 使用此接口手动触发同步消息, 一般用于刚登陆后调用, 可立即开始同步消息. 否则会在有新消息时才开始同步消息.

func (*Bot) TokenLogin

func (bot *Bot) TokenLogin(wxData, token string) CommandResp

TokenLogin 断线重连, 用于短时间使用 `wxData` 和 `token` 再次登录 `token`有效期很短, 如果登陆失败, 建议使用二次登陆方式

func (*Bot) UserLogin

func (bot *Bot) UserLogin(wxData, username, password string) CommandResp

UserLogin 账号密码登录

type ChatMemberInfo

type ChatMemberInfo struct {
	BigHead          string `json:"big_head"`
	ChatroomNickName string `json:"chatroom_nick_name"`
	InvitedBy        string `json:"invited_by"`
	NickName         string `json:"nick_name"`
	SmallHead        string `json:"small_head"`
	UserName         string `json:"user_name"`
}

type ChatroomInfo

type ChatroomInfo struct {
	ChatroomID int              `json:"chatroom_id"`
	Count      int              `json:"count"`
	Member     string           `json:"member"`
	Members    []ChatMemberInfo `json:"-"`
	Message    string           `json:"message"`
	Status     int              `json:"status"`
	UserName   string           `json:"user_name"`
}

type CommandResp

type CommandResp struct {
	Success bool
	Data    json.RawMessage
	Msg     string
}

type Contact

type Contact struct {
	BigHead         string `json:"big_head"`
	BitMask         int64  `json:"bit_mask"`
	BitValue        int    `json:"bit_value"`
	ChatroomID      int    `json:"chatroom_id"`
	ChatroomOwner   string `json:"chatroom_owner"`
	City            string `json:"city"`
	Continue        int    `json:"continue"`
	Country         string `json:"country"`
	ID              int    `json:"id"`
	ImgFlag         int    `json:"img_flag"`
	Intro           string `json:"intro"`
	Label           string `json:"label"`
	Level           int    `json:"level"`
	Member          string `json:"member"`
	MaxMemberCount  int    `json:"max_member_count"`
	MemberCount     int    `json:"member_count"`
	MsgType         int    `json:"msg_type"`
	NickName        string `json:"nick_name"`
	Provincia       string `json:"provincia"`
	PyInitial       string `json:"py_initial"`
	QuanPin         string `json:"quan_pin"`
	Remark          string `json:"remark"`
	RemarkPyInitial string `json:"remark_py_initial"`
	RemarkQuanPin   string `json:"remark_quan_pin"`
	Sex             int    `json:"sex"`
	Signature       string `json:"signature"`
	SmallHead       string `json:"small_head"`
	Source          int    `json:"source"`
	Status          int    `json:"status"`
	Stranger        string `json:"stranger"`
	Uin             int    `json:"uin"`
	UserName        string `json:"user_name"`
}

type CreateRoomResp

type CreateRoomResp struct {
	Message  string `json:"message"`
	Status   int    `json:"status"`
	UserName string `json:"user_name"`
}

type ExternalMsgResp

type ExternalMsgResp struct {
	External string `json:"external"`
	Key      string `json:"key"`
	Message  string `json:"message"`
	Status   int    `json:"status"`
}

type Fav

type Fav struct {
	Flag int `json:"flag"`
	ID   int `json:"id"`
	Seq  int `json:"seq"`
	Time int `json:"time"`
	Type int `json:"type"`
}

type FavDetail

type FavDetail struct {
	Flag   int    `json:"flag"`
	ID     int    `json:"id"`
	Object string `json:"object"`
	Seq    int    `json:"seq"`
	Status int    `json:"status"`
	Time   int    `json:"time"`
}

type FavListResp

type FavListResp struct {
	Continue int    `json:"continue"`
	Data     []Fav  `json:"data"`
	Key      string `json:"key"`
	Message  string `json:"message"`
	Status   int    `json:"status"`
}

type FavResp

type FavResp struct {
	Data    []FavDetail `json:"data"`
	Message string      `json:"message"`
	Status  int         `json:"status"`
}

type ImgResp

type ImgResp struct {
	BigHead   string `json:"big_head"`
	SmallHead string `json:"small_head"`
	Status    int    `json:"status"`
	Size      int    `json:"size"`
	Message   string `json:"message"`
	Data      int    `json:"data"`
}

type Label

type Label struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type LabelListResp

type LabelListResp struct {
	Label   []Label `json:"label"`
	Message string  `json:"message"`
	Status  int     `json:"status"`
}

type LoginReq

type LoginReq struct {
	LoginType string `json:"loginType"`
	WXData    string `json:"wxData"`
	Token     string `json:"token"`
	UserName  string `json:"username"`
	Password  string `json:"password"`
	Phone     string `json:"phone"`
	Code      string `json:"code"`
}

type LoginTokenResp

type LoginTokenResp struct {
	Token string `json:"token"`
	Uin   int64  `json:"uin"`
}

type Moment

type Moment struct {
	CreateTime  int    `json:"create_time"`
	Description string `json:"description"`
	ID          string `json:"id"`
	NickName    string `json:"nick_name"`
	UserName    string `json:"user_name"`
}

type MomentComment

type MomentComment struct {
	CommentFlag   int    `json:"comment_flag"`
	Content       string `json:"content"`
	CreateTime    int    `json:"create_time"`
	DeleteFlag    int    `json:"delete_flag"`
	ID            int    `json:"id"`
	NickName      string `json:"nick_name"`
	ReplyID       int    `json:"reply_id"`
	ReplyUserName string `json:"reply_user_name"`
	Source        int    `json:"source"`
	Type          int    `json:"type"`
	UserName      string `json:"user_name"`
}

type MomentDetail

type MomentDetail struct {
	Comment     []MomentComment `json:"comment"`
	CreateTime  int             `json:"create_time"`
	Description string          `json:"description"`
	ID          string          `json:"id"`
	Like        []MomentLike    `json:"like"`
	NickName    string          `json:"nick_name"`
	UserName    string          `json:"user_name"`
}

type MomentDetailResp

type MomentDetailResp struct {
	Data    MomentDetail `json:"data"`
	Message string       `json:"message"`
	Status  int          `json:"status"`
}

type MomentLike

type MomentLike struct {
	Content    string `json:"content"`
	CreateTime int    `json:"create_time"`
	ID         int    `json:"id"`
	NickName   string `json:"nick_name"`
	Type       int    `json:"type"`
	UserName   string `json:"user_name"`
}

type MomentListResp

type MomentListResp struct {
	Bgi     string   `json:"bgi"`
	Data    []Moment `json:"data"`
	Message string   `json:"message"`
	Page    string   `json:"page"`
	Status  int      `json:"status"`
}

type MomentResp

type MomentResp struct {
	Data    Moment `json:"data"`
	Message string `json:"message"`
	Status  int    `json:"status"`
}

type Msg

type Msg struct {
	Data        string          `json:"data,omitempty"`
	Content     json.RawMessage `json:"content"`
	Continue    int             `json:"continue"`
	Description string          `json:"description"`
	Status      int             `json:"status"`
	Timestamp   int             `json:"timestamp"`
	Uin         int             `json:"uin"`
	FromUser    string          `json:"from_user"`
	MsgID       string          `json:"msg_id"`
	MsgSource   string          `json:"msg_source"`
	MsgType     int             `json:"msg_type"`
	SubType     int             `json:"sub_type"`
	ToUser      string          `json:"to_user"`
	MType       int             `json:"m_type"`
}

type MsgAndStatus

type MsgAndStatus struct {
	Message string `json:"message"`
	Status  int    `json:"status"`
}

type MsgImageResp

type MsgImageResp struct {
	Image   string `json:"image"`
	Message string `json:"message"`
	Size    int    `json:"size"`
	Status  int    `json:"status"`
}

type MsgVideoResp

type MsgVideoResp struct {
	Video   string `json:"video"`
	Message string `json:"message"`
	Size    int    `json:"size"`
	Status  int    `json:"status"`
}

type MsgVoiceResp

type MsgVoiceResp struct {
	Voice   string `json:"voice"`
	Message string `json:"message"`
	Size    int    `json:"size"`
	Status  int    `json:"status"`
}

type MyInfoResp

type MyInfoResp struct {
	UserName string `json:"userName"`
	Uin      int64  `json:"uin"`
}

type PushResp

type PushResp struct {
	List []json.RawMessage `json:"list"`
}

type QRCodeResp

type QRCodeResp struct {
	Footer  string `json:"footer"`
	Message string `json:"message"`
	QRCode  string `json:"qr_code"`
	Status  int    `json:"status"`
}

type RequestTokenResp

type RequestTokenResp struct {
	FullURL  string `json:"full_url"`
	Info     string `json:"info"`
	Message  string `json:"message"`
	ShareURL string `json:"share_url"`
	Status   int    `json:"status"`
}

type RequestUrlResp

type RequestUrlResp struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	// 完整的访问结果原始数据文本(包含http头数据)
	Response string `json:"response"`
}

type SNSUploadResp

type SNSUploadResp struct {
	BigURL   string `json:"big_url"`
	SmallURL string `json:"small_url"`
	Status   int    `json:"status"`
	Size     int    `json:"size"`
	Message  string `json:"message"`
	Data     int    `json:"data"`
}

type ScanResp

type ScanResp struct {
	DeviceType  string `json:"device_type"`
	ExpiredTime int    `json:"expired_time"`
	HeadURL     string `json:"head_url"`
	NickName    string `json:"nick_name"`
	Password    string `json:"password"`
	Status      int    `json:"status"`
	UserName    string `json:"user_name"`
	External    string `json:"external"`
	Email       string `json:"email"`
	Uin         int    `json:"uin"`
	PhoneNumber string `json:"phone_number"`
	SubStatus   int    `json:"sub_status"`
}

type SearchMPResp

type SearchMPResp struct {
	Code    int    `json:"code"`
	Info    string `json:"info"`
	Message string `json:"message"`
	Offset  int    `json:"offset"`
	Status  int    `json:"status"`
}

type SendMsgReq

type SendMsgReq struct {
	ToUserName string   `json:"toUserName"`
	Content    string   `json:"content"`
	AtList     []string `json:"atList"`
	File       string   `json:"file"` // base64
}

type SendMsgResp

type SendMsgResp struct {
	Message string `json:"message"`
	MsgID   string `json:"msg_id"`
	Status  int    `json:"status"`
}

type ServerData

type ServerData struct {
	Type   string
	Event  string
	TaskID string
	CMDID  string `json:"cmdId"`
	Data   json.RawMessage
	Msg    string
}

type WSConn

type WSConn struct {
	sync.Mutex
	*websocket.Conn
}

func (*WSConn) WriteJSON

func (c *WSConn) WriteJSON(v interface{}) error

type WSReq

type WSReq struct {
	Type  string      `json:"type"`
	Cmd   string      `json:"cmd"`
	CmdID string      `json:"cmdId"`
	Data  interface{} `json:"data"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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