[doc]: update docs (#214)

This commit is contained in:
多吃点苹果 2023-01-24 21:44:35 +08:00 committed by GitHub
parent 2d11a7b95a
commit b9bbaed369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 107 deletions

View File

@ -4,16 +4,16 @@
[![Go Doc](https://pkg.go.dev/badge/github.com/eatMoreApple/openwechat)](https://godoc.org/github.com/eatMoreApple/openwechat)[![Release](https://img.shields.io/github/v/release/eatmoreapple/openwechat.svg?style=flat-square)](https://github.com/eatmoreapple/openwechat/releases)[![Go Report Card](https://goreportcard.com/badge/github.com/eatmoreapple/openwechat)](https://goreportcard.com/badge/github.com/eatmoreapple/openwechat)[![Stars](https://img.shields.io/github/stars/eatmoreapple/openwechat.svg?style=flat-square)](https://img.shields.io/github/stars/eatmoreapple/openwechat.svg?style=flat-square)[![Forks](https://img.shields.io/github/forks/eatmoreapple/openwechat.svg?style=flat-square)](https://img.shields.io/github/forks/eatmoreapple/openwechat.svg?style=flat-square)
> golang版个人微信号API, 突破网页版限制,类似开发公众号一样,开发个人微信号
> golang版个人微信号API, 突破登录限制,类似开发公众号一样,开发个人微信号
微信机器人:smiling_imp:,利用微信号完成一些功能的定制化开发⭐
* 模块简单易用,易于扩展
* 支持定制化开发,如日志记录,自动回复
* 突破网页版登录限制📣
* 突破登录限制📣
* 无需重复扫码登录
* 支持多个微信号同时登陆
@ -115,7 +115,7 @@ func main() {
### 添加微信(EatMoreApple):apple:(备注: openwechat进群交流:smiling_imp:
**如果二维码图片没显示出来,请添加微信号 EatMoreApple**
**如果二维码图片没显示出来,请添加微信号 eatmoreapple**
<img width="210px" src="https://raw.githubusercontent.com/eatmoreapple/eatMoreApple/main/img/wechat.jpg" align="left">

View File

@ -84,6 +84,8 @@ bot.Login()
// 创建热存储容器对象
reloadStorage := openwechat.NewJsonFileHotReloadStorage("storage.json")
defer reloadStorage.Close()
// 执行热登录
bot.HotLogin(reloadStorage)
```
@ -95,7 +97,7 @@ bot.HotLogin(reloadStorage)
我们只需要在`HotLogin`增加一个参数,让它在失败后执行扫码登录即可
```go
bot.HotLogin(reloadStorage, openwechat.HotLoginWithRetry(true))
bot.HotLogin(reloadStorage, openwechat.NewRetryLoginOption())
```
当扫码登录成功后,会将会话信息写入到`热存储容器`中,下次再执行热登录的时候就会从`热存储容器`中读取会话信息,直接登录成功。
@ -119,29 +121,23 @@ type HotReloadStorage io.ReadWriter
openwechat也提供了这样的功能。
```go
bot.PushLogin(storage HotReloadStorage, opts ...PushLoginOptionFunc) error
bot.PushLogin(storage HotReloadStorage, opts ...openwechat.BotLoginOption) error
```
`PushLogin`需要传入一个`热存储容器`,和一些可选参数。
`HotReloadStorage` 跟上面一样,用来保存会话信息,必要参数。
`PushLoginOptionFunc`是一个可选参数,用来设置一些额外的行为。
`openwechat.BotLoginOption`是一个可选参数,用来设置一些额外的行为。
目前有下面几个可选参数:
```go
// PushLoginWithoutUUIDCallback 设置 PushLogin 不执行二维码回调, 默认为 true
func PushLoginWithoutUUIDCallback(flag bool) PushLoginOptionFunc
// NewSyncReloadDataLoginOption 登录成功后定时同步热存储容器数据
func NewSyncReloadDataLoginOption(duration time.Duration) BotLoginOption
// PushLoginWithoutScanCallback 设置 PushLogin 不执行扫码回调, 默认为true
func PushLoginWithoutScanCallback(flag bool) PushLoginOptionFunc
// PushLoginWithoutLoginCallback 设置 PushLogin 不执行登录回调默认为false
func PushLoginWithoutLoginCallback(flag bool) PushLoginOptionFunc
// PushLoginWithRetry 设置 PushLogin 失败后执行扫码登录默认为false
func PushLoginWithRetry(flag bool) PushLoginOptionFunc
// NewRetryLoginOption 登录失败后进行扫码登录
func NewRetryLoginOption() BotLoginOption
```
注意:如果是第一次登录,``PushLogin`` 一定会失败的,因为我们的`HotReloadStorage`里面没有会话信息,你需要设置失败会进行扫码登录。
@ -149,7 +145,8 @@ func PushLoginWithRetry(flag bool) PushLoginOptionFunc
```go
bot := openwechat.DefaultBot()
reloadStorage := openwechat.NewJsonFileHotReloadStorage("storage.json")
err = bot.PushLogin(reloadStorage, openwechat.PushLoginWithRetry(true))
defer reloadStorage.Close()
err = bot.PushLogin(reloadStorage, openwechat.NewRetryLoginOption())
```
这样当第一次登录失败的时候,会自动执行扫码登录。
@ -164,13 +161,21 @@ err = bot.PushLogin(reloadStorage, openwechat.PushLoginWithRetry(true))
通过对`bot`对象绑定扫码回调即可实现对应的功能。
```go
bot.ScanCallBack = func(body []byte) { fmt.Println(string(body)) }
bot.ScanCallBack = func(body openwechat.CheckLoginResponse) { fmt.Println(string(body)) }
```
用户扫码后body里面会携带用户的头像信息。
**注**:绑定扫码回调须在登录前执行。
`CheckLoginResponse` 是一个`[]byte`包装类型, 扫码成功后可以通过该类型获取用户的头像信息。
```go
type CheckLoginResponse []byte
func (c CheckLoginResponse) Avatar() (string, error)
```
### 登录回调
@ -178,13 +183,13 @@ bot.ScanCallBack = func(body []byte) { fmt.Println(string(body)) }
`bot`对象绑定登录
```go
bot.LoginCallBack = func(body []byte) {
bot.LoginCallBack = func(body openwechat.CheckLoginResponse) {
fmt.Println(string(body))
// to do your business
}
```
登录回调的参数就是当前客户端需要跳转的链接,可以不用关心它。
登录回调的参数就是当前客户端需要跳转的链接,用户可以不用关心它。(其实可以拿来做一些骚操作😈)
登录回调函数可以当做一个信号处理,表示当前扫码登录的用户已经确认登录。

View File

@ -1,7 +1,5 @@
# 消息
### 接受消息
被动接受的消息对象,由微信服务器发出
@ -18,8 +16,6 @@ bot.MessageHandler = func(msg *openwechat.Message) {
以下简写为`msg`
#### 消息内容
```go
@ -30,8 +26,6 @@ msg.Content // 获取消息内容
由于消息分为很多种类型,它们都共用`Content`属性。一般当消息类型为文本类型的时候,我们才会去访问`Content`属性。
#### 消息类型判断
下面的判断消息类型的方法均返回`bool`
@ -117,13 +111,17 @@ msg.IsIsPaiYiPai() // 拍一拍消息
msg.IsTickled()
```
##### 判断是否拍了拍自己
```go
msg.IsTickledMe()
```
##### 判断是否有新人加入群聊
```go
msg.IsJoinGroup()
```
#### 获取消息的发送者
```go
@ -132,16 +130,12 @@ sender, err := msg.Sender()
如果是群聊消息,该方法返回的是群聊对象(需要自己将`User`转换为`Group`对象)
#### 获取消息的接受者
```go
receiver, err := msg.Receiver()
```
#### 获取消息在群里面的发送者
```go
@ -150,8 +144,6 @@ sender, err := msg.SenderInGroup()
获取群聊中具体发消息的用户,前提该消息必须来自群聊。
#### 是否由自己发送
```go
@ -164,31 +156,24 @@ msg.IsSendBySelf()
msg.IsTickled()
```
#### 消息是否由好友发出
```go
msg.IsSendByFriend()
```
#### 消息是否由群聊发出
```go
msg.IsSendByGroup()
```
#### 回复文本消息
```go
msg.ReplyText("hello")
```
#### 回复图片消息
```go
@ -197,8 +182,6 @@ defer img.Close()
msg.ReplyImage(img)
```
#### 回复文件消息
```go
@ -207,8 +190,6 @@ defer file.Close()
msg.ReplyFile(file)
```
#### 获取消息里的其他信息
##### 名片消息
@ -253,8 +234,6 @@ type Card struct {
}
```
##### 获取已撤回的消息
```go
@ -278,8 +257,6 @@ type RevokeMsg struct {
}
```
#### 同意好友请求
```go
@ -291,8 +268,6 @@ friend, err := msg.Agree()
该方法调用成功的前提是`msg.IsFriendAdd()`返回为`true`
#### 设置为已读
```go
@ -301,10 +276,6 @@ msg.AsRead()
该当前消息设置为已读
#### 设置消息的上下文
用于多个消息处理函数之间的通信,并且是协程安全的。
@ -321,10 +292,6 @@ msg.Set("hello", "world")
value, exist := msg.Get("hello")
```
### 已发送消息
已发送消息指当前用户发送出去的消息
@ -339,8 +306,6 @@ sentMsg, err := msg.ReplyText("hello") // 通过回复消息获取
// and so on
```
#### 撤回消息
撤回刚刚发送的消息撤回消息的有效时间为2分钟超过了这个时间则无法撤回
@ -349,16 +314,12 @@ sentMsg, err := msg.ReplyText("hello") // 通过回复消息获取
sentMsg.Revoke()
```
#### 判断是否可以撤回
```go
sentMsg.CanRevoke()
```
#### 转发给好友
```go
@ -367,8 +328,6 @@ sentMsg.ForwardToFriends(friend1, friend2)
将刚发送的消息转发给好友
#### 转发给群聊
```go
@ -377,10 +336,6 @@ sentMsg.ForwardToGroups(group1, group2)
将刚发送的消息转发给群聊
### Emoji表情
openwechat提供了微信全套`emoji`表情的支持