Skip to content

Commit 7714330

Browse files
committed
更新UserSig
1 parent 2bba99c commit 7714330

File tree

4 files changed

+290
-274
lines changed

4 files changed

+290
-274
lines changed

im.go

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,102 +8,108 @@
88
package im
99

1010
import (
11-
"github.com/dobyte/tencent-im/account"
12-
"github.com/dobyte/tencent-im/group"
13-
"github.com/dobyte/tencent-im/internal/core"
14-
"github.com/dobyte/tencent-im/mute"
15-
"github.com/dobyte/tencent-im/operation"
16-
"github.com/dobyte/tencent-im/private"
17-
"github.com/dobyte/tencent-im/profile"
18-
"github.com/dobyte/tencent-im/push"
19-
"github.com/dobyte/tencent-im/sns"
11+
"github.com/dobyte/tencent-im/account"
12+
"github.com/dobyte/tencent-im/group"
13+
"github.com/dobyte/tencent-im/internal/core"
14+
"github.com/dobyte/tencent-im/internal/sign"
15+
"github.com/dobyte/tencent-im/mute"
16+
"github.com/dobyte/tencent-im/operation"
17+
"github.com/dobyte/tencent-im/private"
18+
"github.com/dobyte/tencent-im/profile"
19+
"github.com/dobyte/tencent-im/push"
20+
"github.com/dobyte/tencent-im/sns"
2021
)
2122

2223
type Error = core.Error
2324

2425
type (
25-
IM interface {
26-
// SNS 获取关系链管理接口
27-
SNS() sns.API
28-
// Mute 获取全局禁言管理接口
29-
Mute() mute.API
30-
// Push 获取全员推送接口
31-
Push() push.API
32-
// Group 获取群组管理接口
33-
Group() group.API
34-
// Account 获取账号管理接口
35-
Account() account.API
36-
// Profile 获取资料管理接口
37-
Profile() profile.API
38-
// Private 获取私聊消息接口
39-
Private() private.API
40-
// Operation 获取运营管理接口
41-
Operation() operation.API
42-
}
43-
44-
Options struct {
45-
AppId int // 应用 SDKAppID,可在即时通信 IM 控制台 的应用卡片中获取。
46-
AppSecret string // 密钥信息,可在即时通信 IM 控制台 的应用详情页面中获取,具体操作请参见 获取密钥
47-
UserId string // 用户ID
48-
}
49-
50-
im struct {
51-
client core.Client
52-
appId int
53-
appSecret string
54-
}
26+
IM interface {
27+
// GetUserSig 获取UserSig签名
28+
GetUserSig() string
29+
// SNS 获取关系链管理接口
30+
SNS() sns.API
31+
// Mute 获取全局禁言管理接口
32+
Mute() mute.API
33+
// Push 获取全员推送接口
34+
Push() push.API
35+
// Group 获取群组管理接口
36+
Group() group.API
37+
// Account 获取账号管理接口
38+
Account() account.API
39+
// Profile 获取资料管理接口
40+
Profile() profile.API
41+
// Private 获取私聊消息接口
42+
Private() private.API
43+
// Operation 获取运营管理接口
44+
Operation() operation.API
45+
}
46+
47+
Options struct {
48+
AppId int // 应用SDKAppID,可在即时通信 IM 控制台 的应用卡片中获取。
49+
AppSecret string // 密钥信息,可在即时通信 IM 控制台 的应用详情页面中获取,具体操作请参见 获取密钥
50+
UserId string // 用户ID
51+
Expire int // UserSig过期时间
52+
}
53+
54+
im struct {
55+
opt Options
56+
client core.Client
57+
}
5558
)
5659

57-
// NewIM create a im instance.
5860
func NewIM(opt Options) IM {
59-
return &im{
60-
appId: opt.AppId,
61-
client: core.NewClient(core.Options{
62-
AppId: opt.AppId,
63-
AppSecret: opt.AppSecret,
64-
UserId: opt.UserId,
65-
}),
66-
}
61+
return &im{opt: opt, client: core.NewClient(core.Options{
62+
AppId: opt.AppId,
63+
AppSecret: opt.AppSecret,
64+
UserId: opt.UserId,
65+
Expire: opt.Expire,
66+
})}
67+
}
68+
69+
// GetUserSig 获取UserSig签名
70+
func (i *im) GetUserSig() string {
71+
userSig, _ := sign.GenUserSig(i.opt.AppId, i.opt.AppSecret, i.opt.UserId, i.opt.Expire)
72+
return userSig
6773
}
6874

6975
// SNS 获取关系链管理接口
7076
func (i *im) SNS() sns.API {
71-
return sns.NewAPI(i.client)
77+
return sns.NewAPI(i.client)
7278
}
7379

7480
// Mute 获取全局禁言管理接口
7581
func (i *im) Mute() mute.API {
76-
return mute.NewAPI(i.client)
82+
return mute.NewAPI(i.client)
7783
}
7884

7985
// Push 获取全员推送接口
8086
func (i *im) Push() push.API {
81-
return push.NewAPI(i.client)
87+
return push.NewAPI(i.client)
8288
}
8389

8490
// Group 获取群组管理接口
8591
func (i *im) Group() group.API {
86-
return group.NewAPI(i.client)
92+
return group.NewAPI(i.client)
8793
}
8894

8995
// Account 获取账号管理接口
9096
func (i *im) Account() account.API {
91-
return account.NewAPI(i.client)
97+
return account.NewAPI(i.client)
9298
}
9399

94100
// Profile 获取资料管理接口
95101
func (i *im) Profile() profile.API {
96-
return profile.NewAPI(i.client)
102+
return profile.NewAPI(i.client)
97103
}
98104

99105
// Private 获取私聊消息接口
100106
func (i *im) Private() private.API {
101-
return private.NewAPI(i.client)
107+
return private.NewAPI(i.client)
102108
}
103109

104110
// Operation 获取运营管理接口
105111
func (i *im) Operation() operation.API {
106-
return operation.NewAPI(i.client)
112+
return operation.NewAPI(i.client)
107113
}
108114

109115
func (i *im) Callback() {

0 commit comments

Comments
 (0)