✨ 新增自定义设备Id接口
This commit is contained in:
parent
879be7aed8
commit
8b7d66a534
19
bot.go
19
bot.go
@ -29,6 +29,7 @@ type Bot struct {
|
|||||||
Storage *Storage
|
Storage *Storage
|
||||||
HotReloadStorage HotReloadStorage
|
HotReloadStorage HotReloadStorage
|
||||||
uuid string
|
uuid string
|
||||||
|
deviceId string // 设备Id
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alive 判断当前用户是否正常在线
|
// Alive 判断当前用户是否正常在线
|
||||||
@ -44,7 +45,16 @@ func (b *Bot) Alive() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetDeviceId
|
||||||
|
// @description: 设置设备Id
|
||||||
|
// @receiver b
|
||||||
|
// @param deviceId
|
||||||
|
func (b *Bot) SetDeviceId(deviceId string) {
|
||||||
|
b.deviceId = deviceId
|
||||||
|
}
|
||||||
|
|
||||||
// GetCurrentUser 获取当前的用户
|
// GetCurrentUser 获取当前的用户
|
||||||
|
//
|
||||||
// self, err := bot.GetCurrentUser()
|
// self, err := bot.GetCurrentUser()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return
|
// return
|
||||||
@ -59,6 +69,7 @@ func (b *Bot) GetCurrentUser() (*Self, error) {
|
|||||||
|
|
||||||
// HotLogin 热登录,可实现重复登录,
|
// HotLogin 热登录,可实现重复登录,
|
||||||
// retry设置为true可在热登录失效后进行普通登录行为
|
// retry设置为true可在热登录失效后进行普通登录行为
|
||||||
|
//
|
||||||
// Storage := NewJsonFileHotReloadStorage("Storage.json")
|
// Storage := NewJsonFileHotReloadStorage("Storage.json")
|
||||||
// err := bot.HotLogin(Storage, true)
|
// err := bot.HotLogin(Storage, true)
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
@ -172,12 +183,17 @@ func (b *Bot) HandleLogin(data []byte) error {
|
|||||||
// 将LoginInfo存到storage里面
|
// 将LoginInfo存到storage里面
|
||||||
b.Storage.LoginInfo = info
|
b.Storage.LoginInfo = info
|
||||||
|
|
||||||
|
// 处理设备Id
|
||||||
|
if b.deviceId == "" {
|
||||||
|
b.deviceId = GetRandomDeviceId()
|
||||||
|
}
|
||||||
|
|
||||||
// 构建BaseRequest
|
// 构建BaseRequest
|
||||||
request := &BaseRequest{
|
request := &BaseRequest{
|
||||||
Uin: info.WxUin,
|
Uin: info.WxUin,
|
||||||
Sid: info.WxSid,
|
Sid: info.WxSid,
|
||||||
Skey: info.SKey,
|
Skey: info.SKey,
|
||||||
DeviceID: GetRandomDeviceId(),
|
DeviceID: b.deviceId,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将BaseRequest存到storage里面方便后续调用
|
// 将BaseRequest存到storage里面方便后续调用
|
||||||
@ -374,6 +390,7 @@ func NewBot() *Bot {
|
|||||||
|
|
||||||
// DefaultBot 默认的Bot的构造方法,
|
// DefaultBot 默认的Bot的构造方法,
|
||||||
// mode不传入默认为 openwechat.Desktop,详情见mode
|
// mode不传入默认为 openwechat.Desktop,详情见mode
|
||||||
|
//
|
||||||
// bot := openwechat.DefaultBot(openwechat.Desktop)
|
// bot := openwechat.DefaultBot(openwechat.Desktop)
|
||||||
func DefaultBot(modes ...Mode) *Bot {
|
func DefaultBot(modes ...Mode) *Bot {
|
||||||
bot := NewBot()
|
bot := NewBot()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user