|
8 | 8 | package im
|
9 | 9 |
|
10 | 10 | 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" |
20 | 21 | )
|
21 | 22 |
|
22 | 23 | type Error = core.Error
|
23 | 24 |
|
24 | 25 | 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 | + } |
55 | 58 | )
|
56 | 59 |
|
57 |
| -// NewIM create a im instance. |
58 | 60 | 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 |
67 | 73 | }
|
68 | 74 |
|
69 | 75 | // SNS 获取关系链管理接口
|
70 | 76 | func (i *im) SNS() sns.API {
|
71 |
| - return sns.NewAPI(i.client) |
| 77 | + return sns.NewAPI(i.client) |
72 | 78 | }
|
73 | 79 |
|
74 | 80 | // Mute 获取全局禁言管理接口
|
75 | 81 | func (i *im) Mute() mute.API {
|
76 |
| - return mute.NewAPI(i.client) |
| 82 | + return mute.NewAPI(i.client) |
77 | 83 | }
|
78 | 84 |
|
79 | 85 | // Push 获取全员推送接口
|
80 | 86 | func (i *im) Push() push.API {
|
81 |
| - return push.NewAPI(i.client) |
| 87 | + return push.NewAPI(i.client) |
82 | 88 | }
|
83 | 89 |
|
84 | 90 | // Group 获取群组管理接口
|
85 | 91 | func (i *im) Group() group.API {
|
86 |
| - return group.NewAPI(i.client) |
| 92 | + return group.NewAPI(i.client) |
87 | 93 | }
|
88 | 94 |
|
89 | 95 | // Account 获取账号管理接口
|
90 | 96 | func (i *im) Account() account.API {
|
91 |
| - return account.NewAPI(i.client) |
| 97 | + return account.NewAPI(i.client) |
92 | 98 | }
|
93 | 99 |
|
94 | 100 | // Profile 获取资料管理接口
|
95 | 101 | func (i *im) Profile() profile.API {
|
96 |
| - return profile.NewAPI(i.client) |
| 102 | + return profile.NewAPI(i.client) |
97 | 103 | }
|
98 | 104 |
|
99 | 105 | // Private 获取私聊消息接口
|
100 | 106 | func (i *im) Private() private.API {
|
101 |
| - return private.NewAPI(i.client) |
| 107 | + return private.NewAPI(i.client) |
102 | 108 | }
|
103 | 109 |
|
104 | 110 | // Operation 获取运营管理接口
|
105 | 111 | func (i *im) Operation() operation.API {
|
106 |
| - return operation.NewAPI(i.client) |
| 112 | + return operation.NewAPI(i.client) |
107 | 113 | }
|
108 | 114 |
|
109 | 115 | func (i *im) Callback() {
|
|
0 commit comments