@seayoo-web/gamer-api 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -6
- package/dist/index.js +1543 -27
- package/package.json +7 -17
- package/types/index.d.ts +5 -29
- package/types/src/club.d.ts +153 -34
- package/types/src/club.define.d.ts +271 -0
- package/types/src/club.enums.d.ts +48 -0
- package/types/src/club.guards.d.ts +34 -66
- package/types/src/community.d.ts +258 -0
- package/types/src/community.define.d.ts +231 -0
- package/types/src/community.enums.d.ts +54 -0
- package/types/src/community.guards.d.ts +73 -0
- package/types/src/event.config.d.ts +10 -12
- package/types/src/event.d.ts +95 -21
- package/types/src/event.define.d.ts +295 -0
- package/types/src/event.enums.d.ts +169 -0
- package/types/src/event.guards.d.ts +37 -0
- package/types/src/token.d.ts +82 -0
- package/types/src/token.define.d.ts +29 -0
- package/types/src/token.guards.d.ts +5 -0
- package/types/src/utils.d.ts +4 -8
- package/types/src/weixin.d.ts +83 -0
- package/types/src/weixin.define.d.ts +41 -0
- package/types/src/weixin.guards.d.ts +1 -12
- package/dist/event-CXcuEQsA.js +0 -648
- package/dist/wx.js +0 -119
- package/types/src/base.d.ts +0 -64
- package/types/src/event.other.d.ts +0 -151
- package/types/src/wexin.d.ts +0 -48
- package/types/wx.d.ts +0 -36
package/dist/index.js
CHANGED
|
@@ -1,42 +1,1558 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var M = (e, t, r) => t in e ? S(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var u = (e, t, r) => M(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { isComboWebView as B } from "@seayoo-web/combo-webview";
|
|
5
|
+
import { isPlainObject as n, useConsole as V, isObject as Q, pruneURL as j, queryString as f, pruneObject as s, isArray as a, isString as H, isValuedString as z, parseJSON as J, removePara as q } from "@seayoo-web/utils";
|
|
6
|
+
import "@seayoo-web/request";
|
|
7
|
+
function O(e) {
|
|
8
|
+
return n(e, "gamer_token") && typeof e.gamer_token == "string";
|
|
9
|
+
}
|
|
10
|
+
function R(e) {
|
|
11
|
+
return n(e);
|
|
12
|
+
}
|
|
13
|
+
const A = V("GamerApiSDK");
|
|
14
|
+
function K() {
|
|
15
|
+
return typeof wx < "u" && Q(wx) && "getSystemInfo" in wx && !!wx.getSystemInfo;
|
|
16
|
+
}
|
|
17
|
+
class Ot {
|
|
18
|
+
constructor({
|
|
19
|
+
endpoint: t,
|
|
20
|
+
NetRequest: r,
|
|
21
|
+
storage: i
|
|
22
|
+
}) {
|
|
23
|
+
u(this, "$idToken", "");
|
|
24
|
+
u(this, "$weixinToken", "");
|
|
25
|
+
u(this, "$gamerToken", "");
|
|
26
|
+
u(this, "inWxMiniProgram", !1);
|
|
27
|
+
u(this, "req");
|
|
28
|
+
u(this, "storage");
|
|
29
|
+
this.storage = i, this.inWxMiniProgram = K(), this.req = r({
|
|
30
|
+
baseURL: `https://${j(t)}/v1`,
|
|
31
|
+
timeout: 1e4,
|
|
32
|
+
responseRule: {
|
|
33
|
+
ok: { resolve: "body" },
|
|
34
|
+
failed: {
|
|
35
|
+
resolve: "json",
|
|
36
|
+
statusField: "error",
|
|
37
|
+
messageField: "message"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
// 使用箭头函数绑定执行上下文
|
|
41
|
+
requestTransformer: (c) => {
|
|
42
|
+
this.$gamerToken && (c.headers.Authorization = `Bearer ${this.$gamerToken}`);
|
|
43
|
+
}
|
|
44
|
+
}), B() && (this.$gamerToken = f("gamer_token"));
|
|
45
|
+
}
|
|
46
|
+
/** 当前是否为登录状态,即是否拥有 gamerToken */
|
|
47
|
+
get isLogined() {
|
|
48
|
+
return this.$gamerToken !== "";
|
|
49
|
+
}
|
|
50
|
+
/** 读取已经设置的 idToken */
|
|
51
|
+
get idToken() {
|
|
52
|
+
return this.$idToken;
|
|
53
|
+
}
|
|
54
|
+
/** 设置从登录组件获取的 Id Token,用于后续请求自动置换 Gamer Token */
|
|
55
|
+
set idToken(t) {
|
|
56
|
+
t !== this.$idToken && (this.$gamerToken = "", this.$idToken = t);
|
|
57
|
+
}
|
|
58
|
+
/** 读取设置 wexinToken */
|
|
59
|
+
get weixinToken() {
|
|
60
|
+
return this.$weixinToken;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 设置 Weixin Token,用于后续请求自动置换 Gamer Token
|
|
64
|
+
*
|
|
65
|
+
* 仅仅在微信小程序模式下有效
|
|
66
|
+
*/
|
|
67
|
+
set weixinToken(t) {
|
|
68
|
+
this.$weixinToken !== t && (this.$weixinToken = t, this.$gamerToken = "");
|
|
69
|
+
}
|
|
70
|
+
/** 读取自动置换的 gamerToken */
|
|
71
|
+
get gamerToken() {
|
|
72
|
+
return this.$gamerToken;
|
|
73
|
+
}
|
|
74
|
+
/** 直接写入 Gamer Token,通常在 ComboWebView 中读取 url 中的 gamer_token 传入 */
|
|
75
|
+
set gamerToken(t) {
|
|
76
|
+
this.$gamerToken = t;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 用世游通行证统一登录能力签发的 ID Token / Weixin Token,自动置换 Gamer Token,成功后会自动设置后续 Request Headers
|
|
18
80
|
*
|
|
19
81
|
* [世游通行证统一登录](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=FJXYgqvLHs)
|
|
20
82
|
*
|
|
21
83
|
* [世游通行证统一登录 - Web 站点](https://365.kdocs.cn/l/cf57sp1qLlZh)
|
|
22
84
|
*
|
|
23
|
-
* -
|
|
24
|
-
* - 为了提高页面执行速度,可以在 setIdToken 后立即调用 autoLogin,比如
|
|
85
|
+
* [世游通行证统一登录 - 微信小程序](https://365.kdocs.cn/l/ccHVuUs0UsZs)
|
|
25
86
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* gamerApi.setIdToken("xxxxx").autoLogin()
|
|
29
|
-
* ```
|
|
87
|
+
* - 此方法通常不需要手动调用,在需要登录的接口调用时会自动执行
|
|
88
|
+
* - 为了提高页面执行速度,可以在设置 Token 后立即调用 autoLogin
|
|
30
89
|
*/
|
|
31
90
|
async autoLogin() {
|
|
32
91
|
if (this.gamerToken)
|
|
33
92
|
return !0;
|
|
34
93
|
if (!this.idToken)
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
94
|
+
return A.error("Missing idToken when call autoLogin()"), !1;
|
|
95
|
+
if (this.inWxMiniProgram && !this.weixinToken)
|
|
96
|
+
return A.error("Missing weixinToken when call autoLogin()"), !1;
|
|
97
|
+
const { data: t } = await this.req.post(
|
|
98
|
+
"login-with-token",
|
|
99
|
+
s({ id_token: this.idToken, weixin_token: this.inWxMiniProgram ? this.weixinToken : null }),
|
|
100
|
+
O
|
|
101
|
+
);
|
|
102
|
+
return this.gamerToken = (t == null ? void 0 : t.gamer_token) || "", !!this.gamerToken;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 获取当前 Session 的信息
|
|
106
|
+
*
|
|
107
|
+
* https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OdGVCdQxEu
|
|
108
|
+
*/
|
|
109
|
+
async getSession() {
|
|
110
|
+
if (await this.autoLogin()) return null;
|
|
111
|
+
const { data: t } = await this.req.get("session", R);
|
|
112
|
+
return t;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 实名认证
|
|
116
|
+
*
|
|
117
|
+
* https://kdocs.cn/l/cf2mO2uRLqh9?linkname=kZYnwX6RcF
|
|
118
|
+
*/
|
|
119
|
+
async authRealName(t) {
|
|
120
|
+
if (await this.autoLogin()) return null;
|
|
121
|
+
const { data: r } = await this.req.post("auth-real-name", s(t), R);
|
|
122
|
+
return r;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function N(e) {
|
|
126
|
+
return n(
|
|
127
|
+
e,
|
|
128
|
+
"default_avatar_url",
|
|
129
|
+
"official_avatar_urls",
|
|
130
|
+
"default_nickname",
|
|
131
|
+
"default_bio",
|
|
132
|
+
"default_role_avatar_url",
|
|
133
|
+
"level_configs",
|
|
134
|
+
"level_valid_days",
|
|
135
|
+
"benefit_description",
|
|
136
|
+
"exp_description",
|
|
137
|
+
"credit_description",
|
|
138
|
+
"send_role_mail_rate_limit"
|
|
139
|
+
) && Array.isArray(e.level_configs) && e.level_configs.every(
|
|
140
|
+
(t) => n(t, "exp", "level", "title")
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
function X(e) {
|
|
144
|
+
return n(
|
|
145
|
+
e,
|
|
146
|
+
"member_id",
|
|
147
|
+
"player_id",
|
|
148
|
+
"type",
|
|
149
|
+
"exp",
|
|
150
|
+
"level",
|
|
151
|
+
"credit",
|
|
152
|
+
"credit_expiring",
|
|
153
|
+
"level_change_time",
|
|
154
|
+
"level_expire_time"
|
|
155
|
+
) && typeof e.player_id == "string";
|
|
156
|
+
}
|
|
157
|
+
function x(e) {
|
|
158
|
+
return n(e, "player") && X(e.player);
|
|
159
|
+
}
|
|
160
|
+
function U(e) {
|
|
161
|
+
return n(
|
|
162
|
+
e,
|
|
163
|
+
"role_id",
|
|
164
|
+
"role_name",
|
|
165
|
+
"role_level",
|
|
166
|
+
"server_id",
|
|
167
|
+
"server_name",
|
|
168
|
+
"last_login_time"
|
|
169
|
+
) && H(e.server_id) && z(e.role_id);
|
|
170
|
+
}
|
|
171
|
+
function Y(e) {
|
|
172
|
+
return n(e, "roles") && a(e.roles, U);
|
|
173
|
+
}
|
|
174
|
+
function Z(e) {
|
|
175
|
+
return U(e) && n(e, "role_fighting");
|
|
176
|
+
}
|
|
177
|
+
function g(e) {
|
|
178
|
+
return n(e, "role_card") && Z(e.role_card);
|
|
179
|
+
}
|
|
180
|
+
function L(e) {
|
|
181
|
+
return n(e, "name", "avatar_url", "bio", "gender", "birthday") && n(e.birthday, "year", "month", "day");
|
|
182
|
+
}
|
|
183
|
+
function y(e) {
|
|
184
|
+
return n(
|
|
185
|
+
e,
|
|
186
|
+
"address_id",
|
|
187
|
+
"recipient",
|
|
188
|
+
"mobile",
|
|
189
|
+
"province",
|
|
190
|
+
"city",
|
|
191
|
+
"district",
|
|
192
|
+
"address",
|
|
193
|
+
"is_default"
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function T(e) {
|
|
197
|
+
return n(e, "addresses") && a(e.addresses, y);
|
|
198
|
+
}
|
|
199
|
+
function W(e) {
|
|
200
|
+
return n(
|
|
201
|
+
e,
|
|
202
|
+
"increased_credit",
|
|
203
|
+
"decreased_credit",
|
|
204
|
+
"expired_credit",
|
|
205
|
+
"balance_credit"
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
function ee(e) {
|
|
209
|
+
return n(
|
|
210
|
+
e,
|
|
211
|
+
"id",
|
|
212
|
+
"change_time",
|
|
213
|
+
"change_type",
|
|
214
|
+
"change_credit",
|
|
215
|
+
"balance",
|
|
216
|
+
"change_scene"
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
function te(e) {
|
|
220
|
+
return n(e, "credit_logs") && a(e.credit_logs, ee);
|
|
221
|
+
}
|
|
222
|
+
function re(e) {
|
|
223
|
+
return n(
|
|
224
|
+
e,
|
|
225
|
+
"benefit_id",
|
|
226
|
+
"name",
|
|
227
|
+
"img_url",
|
|
228
|
+
"description",
|
|
229
|
+
"min_level",
|
|
230
|
+
"max_level",
|
|
231
|
+
"product_id",
|
|
232
|
+
"tag"
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
function ne(e) {
|
|
236
|
+
return n(e, "benefits") && a(e.benefits, re);
|
|
237
|
+
}
|
|
238
|
+
function ie(e) {
|
|
239
|
+
return n(
|
|
240
|
+
e,
|
|
241
|
+
"benefit_id",
|
|
242
|
+
"name",
|
|
243
|
+
"img_url",
|
|
244
|
+
"description",
|
|
245
|
+
"min_level",
|
|
246
|
+
"max_level",
|
|
247
|
+
"product_id"
|
|
248
|
+
) && ("product" in e ? $(e.product) : !0);
|
|
249
|
+
}
|
|
250
|
+
function se(e) {
|
|
251
|
+
return n(e, "benefit") && ie(e.benefit);
|
|
252
|
+
}
|
|
253
|
+
function $(e) {
|
|
254
|
+
return n(
|
|
255
|
+
e,
|
|
256
|
+
"product_id",
|
|
257
|
+
"catalog_id",
|
|
258
|
+
"catalog_name",
|
|
259
|
+
"item_type",
|
|
260
|
+
"name",
|
|
261
|
+
"img_url",
|
|
262
|
+
"description",
|
|
263
|
+
"tag",
|
|
264
|
+
"price",
|
|
265
|
+
"stock",
|
|
266
|
+
"redeem_quantity",
|
|
267
|
+
"not_visible_after",
|
|
268
|
+
"not_visible_before",
|
|
269
|
+
"not_after",
|
|
270
|
+
"not_before",
|
|
271
|
+
"min_level",
|
|
272
|
+
"max_level",
|
|
273
|
+
"limit_daily",
|
|
274
|
+
"limit_monthly",
|
|
275
|
+
"limit_yearly",
|
|
276
|
+
"limit_total",
|
|
277
|
+
"weight",
|
|
278
|
+
"created_at",
|
|
279
|
+
"updated_at"
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
function oe(e) {
|
|
283
|
+
return n(e, "products") && a(e.products, $);
|
|
284
|
+
}
|
|
285
|
+
function ae(e) {
|
|
286
|
+
return n(
|
|
287
|
+
e,
|
|
288
|
+
"redemption_id",
|
|
289
|
+
"player_id",
|
|
290
|
+
"product_id",
|
|
291
|
+
"name",
|
|
292
|
+
"img_url",
|
|
293
|
+
"item_type",
|
|
294
|
+
"catalog_id",
|
|
295
|
+
"catalog_name",
|
|
296
|
+
"quantity",
|
|
297
|
+
"amount",
|
|
298
|
+
"status",
|
|
299
|
+
"created_at"
|
|
300
|
+
) && ("extra_data" in e ? ue(e.extra_data) || ce(e.extra_data) : !0);
|
|
301
|
+
}
|
|
302
|
+
function ue(e) {
|
|
303
|
+
return n(
|
|
304
|
+
e,
|
|
305
|
+
"address",
|
|
306
|
+
"recipient",
|
|
307
|
+
"mobile",
|
|
308
|
+
"province",
|
|
309
|
+
"city",
|
|
310
|
+
"district",
|
|
311
|
+
"express_company",
|
|
312
|
+
"express_number"
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
function ce(e) {
|
|
316
|
+
return n(e, "server_id", "role_id", "role_name");
|
|
317
|
+
}
|
|
318
|
+
function me(e) {
|
|
319
|
+
return n(e, "redemptions") && a(e.redemptions, ae);
|
|
320
|
+
}
|
|
321
|
+
var le = /* @__PURE__ */ ((e) => (e.Unknown = "unknown", e.Male = "male", e.Female = "female", e))(le || {}), _e = /* @__PURE__ */ ((e) => (e.Increase = "increase", e.Decrease = "decrease", e.Expired = "expired", e))(_e || {}), ge = /* @__PURE__ */ ((e) => (e.Order = "order", e.Consumption = "consumption", e.Redeem = "redeem", e.Expire = "expire", e.Admin = "admin", e.Event = "event", e))(ge || {}), de = /* @__PURE__ */ ((e) => (e.GameReward = "game_reward", e.Physical = "physical", e.Virtual = "virtual", e))(de || {}), pe = /* @__PURE__ */ ((e) => (e.Pending = "pending", e.issued = "issued", e.failed = "failed", e))(pe || {});
|
|
322
|
+
class Kt {
|
|
323
|
+
constructor(t) {
|
|
324
|
+
u(this, "token");
|
|
325
|
+
u(this, "req");
|
|
326
|
+
this.token = t, this.req = t.req;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* 获取俱乐部配置
|
|
330
|
+
*
|
|
331
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=tuhsPt3ihp
|
|
332
|
+
*/
|
|
333
|
+
async getConfig() {
|
|
334
|
+
const { data: t } = await this.req.get("club/config", N);
|
|
335
|
+
return t;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* 用于游戏内嵌 Web 页面和微信小程序获取当前登录的游戏账号在俱乐部中的信息。
|
|
339
|
+
*
|
|
340
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=hIDfaMlT7m
|
|
341
|
+
*/
|
|
342
|
+
async getCurrentPlayer() {
|
|
343
|
+
await this.token.autoLogin();
|
|
344
|
+
const { data: t, code: r } = await this.req.get("club/current-player", x);
|
|
345
|
+
return (t == null ? void 0 : t.player) ?? { error: r };
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* 俱乐部用户关联游戏账号
|
|
349
|
+
*
|
|
350
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=Dpb9JAKqzG
|
|
351
|
+
*/
|
|
352
|
+
async linkPlayer() {
|
|
353
|
+
await this.token.autoLogin();
|
|
354
|
+
const { data: t, code: r } = await this.req.post(
|
|
355
|
+
"club/link-player",
|
|
356
|
+
{
|
|
357
|
+
id_token: this.token.idToken
|
|
358
|
+
},
|
|
359
|
+
x
|
|
360
|
+
);
|
|
361
|
+
return (t == null ? void 0 : t.player) ?? {
|
|
362
|
+
error: r
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* 获取俱乐部关联的游戏账号下的角色列表
|
|
367
|
+
*
|
|
368
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=nwu4FiGM9V
|
|
369
|
+
*/
|
|
370
|
+
async getRoles(t, r) {
|
|
371
|
+
if (!await this.token.autoLogin()) return [];
|
|
372
|
+
const { data: i } = await this.req.get("club/roles", Y, {
|
|
373
|
+
params: s({ player_id: t, refresh: r })
|
|
374
|
+
});
|
|
375
|
+
return (i == null ? void 0 : i.roles) || [];
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* 获取俱乐部会员的角色卡片数据
|
|
379
|
+
*
|
|
380
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=A1Wr7kUXnS
|
|
381
|
+
*/
|
|
382
|
+
async getRoleCard(t) {
|
|
383
|
+
const { data: r } = await this.req.get("club/role-card", g, {
|
|
384
|
+
params: { member_id: t }
|
|
385
|
+
});
|
|
386
|
+
return (r == null ? void 0 : r.role_card) ?? null;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* 设置自己的角色卡片
|
|
390
|
+
*
|
|
391
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=XgMf6OFE5i
|
|
392
|
+
*/
|
|
393
|
+
async setRoleCard(t) {
|
|
394
|
+
if (!await this.token.autoLogin()) return null;
|
|
395
|
+
const { data: r } = await this.req.post("club/role-card", t, g);
|
|
396
|
+
return (r == null ? void 0 : r.role_card) ?? null;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* 强制刷新自己的角色卡片,从游戏内获取最新数据
|
|
400
|
+
*
|
|
401
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=RPdJquwmgv
|
|
402
|
+
*/
|
|
403
|
+
async refreshRoleCard() {
|
|
404
|
+
if (!await this.token.autoLogin()) return null;
|
|
405
|
+
const { data: t } = await this.req.post("club/refresh-role-card", {}, g);
|
|
406
|
+
return (t == null ? void 0 : t.role_card) ?? null;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* 获取俱乐部用户的信息
|
|
410
|
+
*
|
|
411
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=TMWBCFcOr2
|
|
412
|
+
*/
|
|
413
|
+
async getUserProfile(t) {
|
|
414
|
+
const { data: r } = await this.req.get("club/user-profile", L, {
|
|
415
|
+
params: { member_id: t }
|
|
416
|
+
});
|
|
417
|
+
return r;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* 修改自己的俱乐部用户信息
|
|
421
|
+
*
|
|
422
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=Qt822A57jd
|
|
423
|
+
*/
|
|
424
|
+
async updateUserProfile(t) {
|
|
425
|
+
await this.token.autoLogin();
|
|
426
|
+
const { data: r, code: i } = await this.req.post("club/user-profile", t, L);
|
|
427
|
+
return r ?? {
|
|
428
|
+
error: i
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* 获取自己的俱乐部收货地址列表
|
|
433
|
+
*
|
|
434
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=NowUIynMVn
|
|
435
|
+
*/
|
|
436
|
+
async getAddresses() {
|
|
437
|
+
if (!await this.token.autoLogin()) return [];
|
|
438
|
+
const { data: t } = await this.req.get("club/addresses", T);
|
|
439
|
+
return (t == null ? void 0 : t.addresses) ?? [];
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 增加俱乐部收货地址
|
|
443
|
+
*
|
|
444
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=TaGIIYDRYA
|
|
445
|
+
*/
|
|
446
|
+
async addAddress(t) {
|
|
447
|
+
if (!await this.token.autoLogin()) return null;
|
|
448
|
+
const { data: r } = await this.req.post("/club/add-address", s(t), y);
|
|
449
|
+
return r;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* 修改自己的俱乐部收货地址
|
|
453
|
+
*
|
|
454
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=p9FlJhHnWN
|
|
455
|
+
*/
|
|
456
|
+
async updateAddress(t) {
|
|
457
|
+
await this.token.autoLogin();
|
|
458
|
+
const { data: r, code: i } = await this.req.post("club/update-address", s(t), y);
|
|
459
|
+
return r ?? { error: i };
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* 删除自己的俱乐部收货地址
|
|
463
|
+
*
|
|
464
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=MEEOBdf8rm
|
|
465
|
+
*/
|
|
466
|
+
async deleteAddress(t) {
|
|
467
|
+
if (!await this.token.autoLogin()) return null;
|
|
468
|
+
const { ok: r } = await this.req.post("club/delete-address", { address_id: t });
|
|
469
|
+
return r;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* 获取俱乐部积分统计信息
|
|
473
|
+
*
|
|
474
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=x4uxtGstRL
|
|
475
|
+
*/
|
|
476
|
+
async getUserCredit(t) {
|
|
477
|
+
await this.token.autoLogin();
|
|
478
|
+
const { data: r, code: i } = await this.req.get("club/user-credit", W, { params: s(t) });
|
|
479
|
+
return r ?? { error: i };
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* 获取自己的俱乐部积分变动记录
|
|
483
|
+
*
|
|
484
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=lQFgF689P8
|
|
485
|
+
*/
|
|
486
|
+
async getCreditLogs(t) {
|
|
487
|
+
await this.token.autoLogin();
|
|
488
|
+
const { data: r } = await this.req.get("club/credit-logs", te, {
|
|
489
|
+
params: s({ max_results: 20, ...t })
|
|
490
|
+
});
|
|
491
|
+
return r || { credit_logs: [] };
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* 获取自己的俱乐部权益列表
|
|
495
|
+
*
|
|
496
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=UFSDGvqkdV
|
|
497
|
+
*/
|
|
498
|
+
async getBenefits() {
|
|
499
|
+
if (!await this.token.autoLogin()) return [];
|
|
500
|
+
const { data: t } = await this.req.get("club/benefits", ne);
|
|
501
|
+
return (t == null ? void 0 : t.benefits) || [];
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* 获取某个权益详细信息
|
|
505
|
+
*
|
|
506
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=XKto0MeaHF
|
|
507
|
+
*/
|
|
508
|
+
async getBenefit(t) {
|
|
509
|
+
if (!await this.token.autoLogin()) return null;
|
|
510
|
+
const { data: r } = await this.req.get("club/benefit", se, {
|
|
511
|
+
params: { benefit_id: t }
|
|
512
|
+
});
|
|
513
|
+
return (r == null ? void 0 : r.benefit) || null;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* 获取商城商品列表
|
|
517
|
+
*
|
|
518
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=r3vC3PzfMQ
|
|
519
|
+
*/
|
|
520
|
+
async getProducts() {
|
|
521
|
+
const { data: t } = await this.req.get("club/products", oe);
|
|
522
|
+
return (t == null ? void 0 : t.products) || [];
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* 兑换商城商品
|
|
526
|
+
*
|
|
527
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=LWcMVwX3OY
|
|
528
|
+
*/
|
|
529
|
+
async redeemProduct(t) {
|
|
530
|
+
await this.token.autoLogin();
|
|
531
|
+
const { ok: r, code: i } = await this.req.post("club/redeem-product", s(t));
|
|
532
|
+
return r || {
|
|
533
|
+
error: i
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* 获取兑换记录
|
|
538
|
+
*
|
|
539
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=Ml6mLgT4cM
|
|
540
|
+
*/
|
|
541
|
+
async getRedemptions(t) {
|
|
542
|
+
await this.token.autoLogin();
|
|
543
|
+
const { data: r } = await this.req.get("club/redemptions", me, {
|
|
544
|
+
params: s({ max_results: 20, ...t })
|
|
545
|
+
});
|
|
546
|
+
return r || { redemptions: [] };
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
var fe = /* @__PURE__ */ ((e) => (e.EventItem = "event_item", e.GameItem = "game_item", e.PhysicalItem = "physical_item", e.WeixinHongbao = "weixin_hongbao", e.GiftCode = "gift_code", e.LotteryTicket = "lottery_ticket", e.VoidItem = "void_item", e))(fe || {}), ye = /* @__PURE__ */ ((e) => (e.UserId = "user_id", e.RoleId = "role_id", e))(ye || {}), we = /* @__PURE__ */ ((e) => (e.None = "none", e.Daily = "daily", e.Weekly = "weekly", e.Monthly = "monthly", e))(we || {}), o = /* @__PURE__ */ ((e) => (e.Preregister = "preregister", e.Lottery = "lottery", e.Survey = "survey", e.Invite = "invite", e.Share = "share", e.Follow = "follow", e.Subscribe = "weixin_subscribe", e.Comment = "comment", e.Vote = "vote", e.GiftCode = "gift_code", e.Register = "register", e.InvitedRegister = "invited_register", e.ClaimRewards = "claim_rewards", e.Cashback = "cashback", e.Quest = "quest", e.Team = "team", e.LotteryDraw = "lottery_draw", e))(o || {}), he = /* @__PURE__ */ ((e) => (e.Active = "player_active_points", e.Login = "player_login_days", e.OrderAmount = "order_total_amount", e.Posts = "community_posts", e.Comments = "community_comments", e))(he || {}), ve = /* @__PURE__ */ ((e) => (e.System = "system", e.UserSubmission = "user_submission", e.Shortlisted = "shortlisted", e))(ve || {}), ke = /* @__PURE__ */ ((e) => (e.Ineligible = "ineligible", e.Unaccalimed = "unaccalimed", e.Received = "received", e))(ke || {}), be = /* @__PURE__ */ ((e) => (e.Unaccalimed = "unaccalimed", e.Received = "received", e.Failed = "failed", e.Delivered = "delivered", e))(be || {}), qe = /* @__PURE__ */ ((e) => (e.Ineligible = "ineligible", e.Unaccalimed = "unaccalimed", e.Received = "received", e.Failed = "failed", e))(qe || {}), Re = /* @__PURE__ */ ((e) => (e.Output = "output", e.Engage = "engage", e))(Re || {}), Ae = /* @__PURE__ */ ((e) => (e.Private = "private", e.Public = "public", e))(Ae || {}), xe = /* @__PURE__ */ ((e) => (e.Unknown = "unknown", e.Pending = "pending", e.Drawn = "drawn", e.Claimed = "claimed", e.Fail = "fail", e))(xe || {}), Le = /* @__PURE__ */ ((e) => (e.Assemble = "assemble", e.Join = "join", e.Disband = "disband", e.ChangeVisibility = "change_visibility", e.Query = "query", e))(Le || {}), Ce = /* @__PURE__ */ ((e) => (e.Query = "query", e.Draw = "draw", e.Claim = "claim", e))(Ce || {});
|
|
550
|
+
function Pe(e) {
|
|
551
|
+
return n(e, "event_name", "rules", "since", "until", "visit_count", "features") && Array.isArray(e.features) && e.features.every(Ue);
|
|
552
|
+
}
|
|
553
|
+
function Ue(e) {
|
|
554
|
+
if (!De(e))
|
|
555
|
+
return !1;
|
|
556
|
+
switch (e.feature_type) {
|
|
557
|
+
case o.Preregister:
|
|
558
|
+
case o.ClaimRewards:
|
|
559
|
+
case o.Register:
|
|
560
|
+
case o.InvitedRegister:
|
|
561
|
+
return !0;
|
|
562
|
+
case o.Lottery:
|
|
563
|
+
return Fe(e.config);
|
|
564
|
+
case o.Survey:
|
|
565
|
+
return Ge(e.config);
|
|
566
|
+
case o.Invite:
|
|
567
|
+
return Ie(e.config);
|
|
568
|
+
case o.Share:
|
|
569
|
+
return Se(e.config);
|
|
570
|
+
case o.Follow:
|
|
571
|
+
return Me(e.config);
|
|
572
|
+
case o.Subscribe:
|
|
573
|
+
return Be(e.config);
|
|
574
|
+
case o.Comment:
|
|
575
|
+
return Ve(e.config);
|
|
576
|
+
case o.Vote:
|
|
577
|
+
return Qe(e.config);
|
|
578
|
+
case o.Cashback:
|
|
579
|
+
return He(e.config);
|
|
580
|
+
case o.GiftCode:
|
|
581
|
+
return ze(e.config);
|
|
582
|
+
case o.Quest:
|
|
583
|
+
return Oe(e.config);
|
|
584
|
+
case o.Team:
|
|
585
|
+
return Ke(e.config);
|
|
586
|
+
case o.LotteryDraw:
|
|
587
|
+
return Ne(e.config);
|
|
588
|
+
default:
|
|
589
|
+
return !1;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function w(e) {
|
|
593
|
+
return n(
|
|
594
|
+
e,
|
|
595
|
+
"reward_item_id",
|
|
596
|
+
"reward_amount",
|
|
597
|
+
"reward_item_name",
|
|
598
|
+
"reward_item_icon_url",
|
|
599
|
+
"reward_item_type"
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
function $e(e) {
|
|
603
|
+
return n(e, "feature_reward_type", "reward_details") && (e.feature_reward_type === "every" ? Array.isArray(e.reward_details) && e.reward_details.every(w) : e.feature_reward_type === "regular" ? n(e.reward_details, "engage_count", "rewards") && Array.isArray(e.reward_details.rewards) && e.reward_details.rewards.every(w) : !1);
|
|
604
|
+
}
|
|
605
|
+
function De(e) {
|
|
606
|
+
return n(
|
|
607
|
+
e,
|
|
608
|
+
"feature_id",
|
|
609
|
+
"feature_name",
|
|
610
|
+
"feature_type",
|
|
611
|
+
"cycle",
|
|
612
|
+
"description",
|
|
613
|
+
"limit",
|
|
614
|
+
"since",
|
|
615
|
+
"until",
|
|
616
|
+
"engage_account_type",
|
|
617
|
+
"feature_rewards"
|
|
618
|
+
) && Array.isArray(e.feature_rewards) && e.feature_rewards.every($e);
|
|
619
|
+
}
|
|
620
|
+
function Ee(e) {
|
|
621
|
+
return n(
|
|
622
|
+
e,
|
|
623
|
+
"reward_item_id",
|
|
624
|
+
"reward_item_name",
|
|
625
|
+
"reward_item_type",
|
|
626
|
+
"reward_item_icon_url",
|
|
627
|
+
"reward_amount",
|
|
628
|
+
"reward_remaining_stock"
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
function Fe(e) {
|
|
632
|
+
return n(
|
|
633
|
+
e,
|
|
634
|
+
"consume_item_id",
|
|
635
|
+
"consume_item_name",
|
|
636
|
+
"consume_item_icon_url",
|
|
637
|
+
"consume_item_count",
|
|
638
|
+
"rewards"
|
|
639
|
+
) && Array.isArray(e.rewards) && e.rewards.every(Ee);
|
|
640
|
+
}
|
|
641
|
+
function Ge(e) {
|
|
642
|
+
return n(e, "survey_id", "survey_url");
|
|
643
|
+
}
|
|
644
|
+
function Ie(e) {
|
|
645
|
+
return n(e, "share_url");
|
|
646
|
+
}
|
|
647
|
+
function Se(e) {
|
|
648
|
+
return n(e, "share_platform");
|
|
649
|
+
}
|
|
650
|
+
function Me(e) {
|
|
651
|
+
return n(e, "platform");
|
|
652
|
+
}
|
|
653
|
+
function Be(e) {
|
|
654
|
+
return n(e, "weixin_template_ids") && Array.isArray(e.weixin_template_ids) && e.weixin_template_ids.every((t) => typeof t == "string");
|
|
655
|
+
}
|
|
656
|
+
function Ve(e) {
|
|
657
|
+
return n(e, "comments", "send_rate") && Array.isArray(e.comments) && e.comments.every((t) => typeof t == "string");
|
|
658
|
+
}
|
|
659
|
+
function Qe(e) {
|
|
660
|
+
return n(
|
|
661
|
+
e,
|
|
662
|
+
"vote_feature_ids",
|
|
663
|
+
"submission_feature_ids",
|
|
664
|
+
"finalists_amount",
|
|
665
|
+
"source",
|
|
666
|
+
"options",
|
|
667
|
+
"rewards"
|
|
668
|
+
) && Array.isArray(e.vote_feature_ids) && Array.isArray(e.submission_feature_ids) && Array.isArray(e.options) && e.options.every(je) && Array.isArray(e.rewards) && e.rewards.every(w);
|
|
669
|
+
}
|
|
670
|
+
function je(e) {
|
|
671
|
+
return n(e, "sn", "name", "amount", "jump_url", "last_vote_time", "finalists") && ("img_urls" in e ? Array.isArray(e.img_urls) : !0) && ("video_urls" in e ? Array.isArray(e.video_urls) : !0) && ("descriptions" in e ? Array.isArray(e.descriptions) : !0);
|
|
672
|
+
}
|
|
673
|
+
function He(e) {
|
|
674
|
+
return n(
|
|
675
|
+
e,
|
|
676
|
+
"order_start_time",
|
|
677
|
+
"order_end_time",
|
|
678
|
+
"claim_rewards_start_time",
|
|
679
|
+
"claim_rewards_end_time"
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
function ze(e) {
|
|
683
|
+
return n(e, "gift_items") && Array.isArray(e.gift_items) && e.gift_items.every(Je);
|
|
684
|
+
}
|
|
685
|
+
function Je(e) {
|
|
686
|
+
return n(e, "name", "count", "icon_url");
|
|
687
|
+
}
|
|
688
|
+
function Oe(e) {
|
|
689
|
+
return n(e, "objective", "completion_value") && ("team" in e ? n(e.team, "completion_value") : !0);
|
|
690
|
+
}
|
|
691
|
+
function Ke(e) {
|
|
692
|
+
return n(e, "min_members", "max_members");
|
|
693
|
+
}
|
|
694
|
+
function Ne(e) {
|
|
695
|
+
return n(e, "draw_not_after", "draw_not_before");
|
|
696
|
+
}
|
|
697
|
+
function Xe(e) {
|
|
698
|
+
return n(e, "allowed", "registered");
|
|
699
|
+
}
|
|
700
|
+
function d(e) {
|
|
701
|
+
return n(e, "count");
|
|
702
|
+
}
|
|
703
|
+
function Ye(e) {
|
|
704
|
+
return n(e, "engagements") && Array.isArray(e.engagements) && (e.engagements.every(
|
|
705
|
+
(t) => n(t, "user_id", "name", "avatar_url", "comment", "video_note", "created_at")
|
|
706
|
+
) || e.engagements.every((t) => n(t, "team_code", "leader_name", "total_members")));
|
|
707
|
+
}
|
|
708
|
+
function Ze(e) {
|
|
709
|
+
return n(e, "first_visit") && typeof e.first_visit == "boolean";
|
|
710
|
+
}
|
|
711
|
+
function Te(e) {
|
|
712
|
+
return n(e, "status") && Array.isArray(e.status) && e.status.every((t) => n(t, "feature_id", "can_engage", "has_unclaimed_rewards"));
|
|
713
|
+
}
|
|
714
|
+
function We(e) {
|
|
715
|
+
return n(e, "engagements") && a(e.engagements, D);
|
|
716
|
+
}
|
|
717
|
+
function D(e) {
|
|
718
|
+
if (!n(
|
|
719
|
+
e,
|
|
720
|
+
"engagement_id",
|
|
721
|
+
"sequence",
|
|
722
|
+
"feature_id",
|
|
723
|
+
"reward_id",
|
|
724
|
+
"reward_status",
|
|
725
|
+
"reward_source",
|
|
726
|
+
"created_at"
|
|
727
|
+
))
|
|
728
|
+
return !1;
|
|
729
|
+
if (!("data" in e))
|
|
730
|
+
return !0;
|
|
731
|
+
const t = e.data;
|
|
732
|
+
return et(t) || tt(t) || rt(t) || nt(t) || it(t) || st(t) || ot(t) || at(t) || ut(t) || ct(t) || mt(t) || lt(t);
|
|
733
|
+
}
|
|
734
|
+
function et(e) {
|
|
735
|
+
return n(e, "platforms") && Array.isArray(e.platforms);
|
|
736
|
+
}
|
|
737
|
+
function tt(e) {
|
|
738
|
+
return n(e, "lottery_count");
|
|
739
|
+
}
|
|
740
|
+
function rt(e) {
|
|
741
|
+
return n(e, "serial_number");
|
|
742
|
+
}
|
|
743
|
+
function nt(e) {
|
|
744
|
+
return n(e, "user_id");
|
|
745
|
+
}
|
|
746
|
+
function it(e) {
|
|
747
|
+
return n(e, "platform");
|
|
748
|
+
}
|
|
749
|
+
function st(e) {
|
|
750
|
+
return n(e, "option_sn");
|
|
751
|
+
}
|
|
752
|
+
function ot(e) {
|
|
753
|
+
return n(e, "weixin_openid");
|
|
754
|
+
}
|
|
755
|
+
function at(e) {
|
|
756
|
+
return n(e, "cashback_total_amount", "game_item_count", "order_total_amount");
|
|
757
|
+
}
|
|
758
|
+
function ut(e) {
|
|
759
|
+
return n(e, "gift_code");
|
|
760
|
+
}
|
|
761
|
+
function ct(e) {
|
|
762
|
+
return n(e, "team_code", "visibility", "members") && Array.isArray(e.members) && e.members.every(
|
|
763
|
+
(t) => n(t, "is_leader", "role_name", "server_name")
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
function mt(e) {
|
|
767
|
+
return n(e, "objective", "progress") ? "team" in e ? n(e.team, "progress", "players") && Array.isArray(e.team.players) && e.team.players.every(
|
|
768
|
+
(t) => n(
|
|
769
|
+
t,
|
|
770
|
+
"user_id",
|
|
771
|
+
"role_name",
|
|
772
|
+
"is_leader"
|
|
773
|
+
)
|
|
774
|
+
) : !0 : !1;
|
|
775
|
+
}
|
|
776
|
+
function E(e) {
|
|
777
|
+
return n(
|
|
778
|
+
e,
|
|
779
|
+
"reward_id",
|
|
780
|
+
"reward_item_id",
|
|
781
|
+
"reward_item_name",
|
|
782
|
+
"reward_source",
|
|
783
|
+
"reward_item_type",
|
|
784
|
+
"reward_item_icon_url",
|
|
785
|
+
"reward_amount",
|
|
786
|
+
"reward_status",
|
|
787
|
+
"event_id",
|
|
788
|
+
"event_name",
|
|
789
|
+
"feature_id",
|
|
790
|
+
"engagement_id",
|
|
791
|
+
"feature_type",
|
|
792
|
+
"receive_time"
|
|
793
|
+
) && ("extra_data" in e ? n(e.extra_data) : !0);
|
|
794
|
+
}
|
|
795
|
+
function lt(e) {
|
|
796
|
+
return !n(e, "tickets") || !("status" in e) ? !1 : e.status === "unknown" || e.status === "pending" ? !0 : "reward" in e ? E(e.reward) : !1;
|
|
797
|
+
}
|
|
798
|
+
function _t(e) {
|
|
799
|
+
return n(
|
|
800
|
+
e,
|
|
801
|
+
"reward_id",
|
|
802
|
+
"reward_item_id",
|
|
803
|
+
"reward_item_name",
|
|
804
|
+
"reward_item_type",
|
|
805
|
+
"reward_item_icon_url",
|
|
806
|
+
"reward_amount",
|
|
807
|
+
"reward_source",
|
|
808
|
+
"reward_source"
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
function gt(e) {
|
|
812
|
+
return n(e, "engagement_id") && ("engagement" in e ? D(e.engagement) : !0) && ("rewards" in e ? a(e.rewards, _t) : !0);
|
|
813
|
+
}
|
|
814
|
+
function dt(e) {
|
|
815
|
+
return n(e, "reward_id", "reward_status");
|
|
816
|
+
}
|
|
817
|
+
function pt(e) {
|
|
818
|
+
return n(e, "claimed_items") && a(e.claimed_items, dt);
|
|
819
|
+
}
|
|
820
|
+
function ft(e) {
|
|
821
|
+
return n(e, "reward_status");
|
|
822
|
+
}
|
|
823
|
+
function yt(e) {
|
|
824
|
+
return n(e, "user_rewards") && a(e.user_rewards, E);
|
|
825
|
+
}
|
|
826
|
+
function wt(e) {
|
|
827
|
+
return n(e, "scene");
|
|
828
|
+
}
|
|
829
|
+
function ht(e) {
|
|
830
|
+
return n(e, "params");
|
|
831
|
+
}
|
|
832
|
+
function vt(e) {
|
|
833
|
+
return n(e, "img") && typeof e.img == "string";
|
|
834
|
+
}
|
|
835
|
+
class Nt {
|
|
836
|
+
constructor(t, r) {
|
|
837
|
+
u(this, "token");
|
|
838
|
+
u(this, "event", 0);
|
|
839
|
+
u(this, "req");
|
|
840
|
+
this.token = t, this.event = r, this.req = t.req;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* 根据手机号白名单,检查手机号是否允许登录某个游戏
|
|
844
|
+
*
|
|
845
|
+
* https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OWGSPF3Ysl
|
|
846
|
+
*/
|
|
847
|
+
async verifyMobileAllowed(t) {
|
|
848
|
+
const { data: r } = await this.req.get("verify-mobile-allowed", Xe, {
|
|
849
|
+
params: { mobile: t }
|
|
850
|
+
});
|
|
851
|
+
return r;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* 获取运营活动的基础配置信息
|
|
855
|
+
*
|
|
856
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=wFXxtdNKPm
|
|
857
|
+
*/
|
|
858
|
+
async getConfig() {
|
|
859
|
+
const { data: t } = await this.req.get(`event/${this.event}/event-config`, Pe);
|
|
860
|
+
return t;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* 获取某个玩法参与用户数量
|
|
864
|
+
*
|
|
865
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=ejPOcWMvT1
|
|
866
|
+
*/
|
|
867
|
+
async getEngagementsUserCount(t) {
|
|
868
|
+
const { data: r } = await this.req.get(`event/${this.event}/feature-engagement-count`, d, {
|
|
869
|
+
params: { feature_id: t, type: "user" }
|
|
870
|
+
});
|
|
871
|
+
return (r == null ? void 0 : r.count) ?? null;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* 获取某个玩法参与次数
|
|
875
|
+
*
|
|
876
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=ejPOcWMvT1
|
|
877
|
+
*/
|
|
878
|
+
async getEngagementsCount(t) {
|
|
879
|
+
const { data: r } = await this.req.get(`event/${this.event}/feature-engagement-count`, d, {
|
|
880
|
+
params: { feature_id: t, type: "engagement" }
|
|
881
|
+
});
|
|
882
|
+
return (r == null ? void 0 : r.count) ?? null;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* 获取某个玩法的参与记录(和特定用户无关)
|
|
886
|
+
*
|
|
887
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=THtZ4ewIQW
|
|
888
|
+
*/
|
|
889
|
+
async getEngagements(t) {
|
|
890
|
+
const { data: r } = await this.req.get(`event/${this.event}/feature-engagements`, Ye, {
|
|
891
|
+
params: { feature_id: t }
|
|
892
|
+
});
|
|
893
|
+
return (r == null ? void 0 : r.engagements) || [];
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* 用户访问某个活动或玩法
|
|
897
|
+
*
|
|
898
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=DWtJrnrBCn
|
|
899
|
+
*/
|
|
900
|
+
async visit(t) {
|
|
901
|
+
await this.token.autoLogin();
|
|
902
|
+
const { data: r, code: i } = await this.req.post(
|
|
903
|
+
`event/${this.event}/visit`,
|
|
904
|
+
s(t || {}),
|
|
905
|
+
Ze
|
|
906
|
+
);
|
|
907
|
+
return r ?? {
|
|
908
|
+
error: i
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* 获取用户在目标活动下的所有玩法的参与状态,用于前端进一步确定如何执行交互逻辑
|
|
913
|
+
*
|
|
914
|
+
* 💡活动下包含 engage_account_type 为 role_id 的玩法时,前端需要提供 server_id 和 role_id
|
|
915
|
+
*
|
|
916
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=WzX5BrMNpL
|
|
917
|
+
*/
|
|
918
|
+
async getUserFeatureStatus(t) {
|
|
919
|
+
if (!await this.token.autoLogin()) return [];
|
|
920
|
+
const { data: r } = await this.req.get("event/user-feature-status", Te, {
|
|
921
|
+
params: s({ ...t, event_id: this.event })
|
|
922
|
+
});
|
|
923
|
+
return (r == null ? void 0 : r.status) || [];
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* 获取当前登录用户参与某个玩法的记录
|
|
927
|
+
*
|
|
928
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=WSbAeDZc8F
|
|
929
|
+
*/
|
|
930
|
+
async getUserEngagements(t) {
|
|
931
|
+
if (!await this.token.autoLogin()) return [];
|
|
932
|
+
const { data: r } = await this.req.get(`event/${this.event}/user-engagements`, We, {
|
|
933
|
+
params: { feature_id: t }
|
|
934
|
+
});
|
|
935
|
+
return (r == null ? void 0 : r.engagements) || [];
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* 用户参与某个玩法(需要先调用 visit 接口)
|
|
939
|
+
*
|
|
940
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=vuOyrcry3S
|
|
941
|
+
*/
|
|
942
|
+
async engage(t) {
|
|
943
|
+
await this.token.autoLogin();
|
|
944
|
+
const { data: r, code: i } = await this.req.post(`event/${this.event}/engame`, s(t), gt);
|
|
945
|
+
return r ?? {
|
|
946
|
+
error: i
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* 用户领取除红包和实物奖励以外的所有奖励
|
|
951
|
+
*
|
|
952
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=lCGuqgvUDP
|
|
953
|
+
*/
|
|
954
|
+
async claimRewards(t) {
|
|
955
|
+
await this.token.autoLogin();
|
|
956
|
+
const { data: r, code: i } = await this.req.post(
|
|
957
|
+
`event/${this.event}/claim-rewards`,
|
|
958
|
+
s(t),
|
|
959
|
+
pt
|
|
960
|
+
);
|
|
961
|
+
return (r == null ? void 0 : r.claimed_items) ?? {
|
|
962
|
+
error: i
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* 用户领取红包奖励
|
|
967
|
+
*
|
|
968
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=aQLhlOAB4Q
|
|
969
|
+
*/
|
|
970
|
+
async claimWeixinHongbao(t) {
|
|
971
|
+
await this.token.autoLogin();
|
|
972
|
+
const { data: r, code: i } = await this.req.post(
|
|
973
|
+
`event/${this.event}/claim-weixin-hongbao`,
|
|
974
|
+
{ reward_id: t },
|
|
975
|
+
ft
|
|
976
|
+
);
|
|
977
|
+
return r ?? {
|
|
978
|
+
error: i
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* 查询用户活动奖励列表
|
|
983
|
+
*
|
|
984
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=qj12eIgYQG
|
|
985
|
+
*/
|
|
986
|
+
async getUserRewards(t) {
|
|
987
|
+
if (!await this.token.autoLogin()) return [];
|
|
988
|
+
const { data: r } = await this.req.post(
|
|
989
|
+
"event/user-rewards",
|
|
990
|
+
s({ ...t, event_id: this.event }),
|
|
991
|
+
yt
|
|
992
|
+
);
|
|
993
|
+
return (r == null ? void 0 : r.user_rewards) || [];
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* 查询用户活动道具数量。注意,这里只能是活动道具
|
|
997
|
+
*
|
|
998
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=mnGCTeTgMb
|
|
999
|
+
*/
|
|
1000
|
+
async getUserItemCount(t) {
|
|
1001
|
+
if (!await this.token.autoLogin()) return null;
|
|
1002
|
+
const { data: r } = await this.req.get(`event/${this.event}/user-item-count`, d, {
|
|
1003
|
+
params: { item_id: t }
|
|
1004
|
+
});
|
|
1005
|
+
return (r == null ? void 0 : r.count) ?? null;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* 填写实物奖励收货地址
|
|
1009
|
+
*
|
|
1010
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=QIwGhnaexb
|
|
1011
|
+
*/
|
|
1012
|
+
async submitUserRewardAddress(t) {
|
|
1013
|
+
if (!await this.token.autoLogin()) return null;
|
|
1014
|
+
const { ok: r } = await this.req.post(`event/${this.event}/user-reward-address`, t);
|
|
1015
|
+
return r;
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* 小程序码携带参数最多 32 个可见字符,若前端携带参数过长,则将参数保存在 api 中,并返回符合小程序码要求的 scene
|
|
1019
|
+
*
|
|
1020
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=TbEeyUmZzN
|
|
1021
|
+
*
|
|
1022
|
+
* @param params - 前端扫描二维码打开小程序所需参数
|
|
1023
|
+
*/
|
|
1024
|
+
async getUnlimitQrcodeScene(t) {
|
|
1025
|
+
if (!await this.token.autoLogin()) return null;
|
|
1026
|
+
const { data: r } = await this.req.get("event/unlimit-qrcode-scene", wt, {
|
|
1027
|
+
params: { params: t }
|
|
1028
|
+
});
|
|
1029
|
+
return (r == null ? void 0 : r.scene) ?? null;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* 根据小程序码携带 scene 值,获取对应的前端所需参数
|
|
1033
|
+
*
|
|
1034
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=SzWPFZDQBV
|
|
1035
|
+
*
|
|
1036
|
+
* @param scene - 小程序码 scene 值
|
|
1037
|
+
*/
|
|
1038
|
+
async getParamsByQrcodeScene(t) {
|
|
1039
|
+
const { data: r } = await this.req.get("event/params-by-qrcode-scene", ht, {
|
|
1040
|
+
params: { scene: t }
|
|
1041
|
+
});
|
|
1042
|
+
return (r == null ? void 0 : r.params) ?? null;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* 生成不限制的带参数的小程序码(data URI格式的小程序码)
|
|
1046
|
+
*
|
|
1047
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=Rvmoq8iIy0
|
|
1048
|
+
*/
|
|
1049
|
+
async generateUnlimitQrcode(t) {
|
|
1050
|
+
if (!await this.token.autoLogin()) return null;
|
|
1051
|
+
const { data: r } = await this.req.post("event/unlimit-qrcode", s(t), vt);
|
|
1052
|
+
return (r == null ? void 0 : r.img) ?? null;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
function F(e) {
|
|
1056
|
+
return n(e, "forum_id", "icon_url", "name", "tags", "sort", "mode", "member_ids") && Array.isArray(e.tags) && Array.isArray(e.member_ids);
|
|
1057
|
+
}
|
|
1058
|
+
function kt(e) {
|
|
1059
|
+
return n(e, "forums") && a(e.forums, F);
|
|
1060
|
+
}
|
|
1061
|
+
function h(e) {
|
|
1062
|
+
return n(e, "topic_id", "cover_url", "name", "description", "tags", "post_num") && Array.isArray(e.tags);
|
|
1063
|
+
}
|
|
1064
|
+
function bt(e) {
|
|
1065
|
+
return n(e, "topics") && a(e.topics, h);
|
|
1066
|
+
}
|
|
1067
|
+
function qt(e) {
|
|
1068
|
+
return n(e, "topic") && h(e.topic);
|
|
1069
|
+
}
|
|
1070
|
+
function v(e) {
|
|
1071
|
+
return n(
|
|
1072
|
+
e,
|
|
1073
|
+
"post_id",
|
|
1074
|
+
"forum",
|
|
1075
|
+
"posted_by",
|
|
1076
|
+
"nickname",
|
|
1077
|
+
"avatar_url",
|
|
1078
|
+
"content",
|
|
1079
|
+
"summary",
|
|
1080
|
+
"like_num",
|
|
1081
|
+
"comments_num",
|
|
1082
|
+
"liked",
|
|
1083
|
+
"image_urls",
|
|
1084
|
+
"topics",
|
|
1085
|
+
"event_ids",
|
|
1086
|
+
"is_pinned",
|
|
1087
|
+
"is_highlighted",
|
|
1088
|
+
"status",
|
|
1089
|
+
"create_time"
|
|
1090
|
+
) && a(e.topics, h) && F(e.forum);
|
|
1091
|
+
}
|
|
1092
|
+
function C(e) {
|
|
1093
|
+
return n(e, "next_token", "posts") && a(e.posts, v);
|
|
1094
|
+
}
|
|
1095
|
+
function Rt(e) {
|
|
1096
|
+
return n(e, "post") && v(e.post);
|
|
1097
|
+
}
|
|
1098
|
+
function k(e) {
|
|
1099
|
+
return n(e);
|
|
1100
|
+
}
|
|
1101
|
+
function At(e) {
|
|
1102
|
+
return n(e) && ("post" in e ? v(e.post) : !0) && ("antispam" in e ? k(e.antispam) : !0);
|
|
1103
|
+
}
|
|
1104
|
+
function l(e) {
|
|
1105
|
+
return n(
|
|
1106
|
+
e,
|
|
1107
|
+
"comment_id",
|
|
1108
|
+
"post_id",
|
|
1109
|
+
"commented_by",
|
|
1110
|
+
"nickname",
|
|
1111
|
+
"avatar_url",
|
|
1112
|
+
"content",
|
|
1113
|
+
"like_num",
|
|
1114
|
+
"reply_num",
|
|
1115
|
+
"liked",
|
|
1116
|
+
"image_url",
|
|
1117
|
+
"create_time",
|
|
1118
|
+
"status"
|
|
1119
|
+
) && ("replies" in e ? a(e.replies, b) : !0);
|
|
1120
|
+
}
|
|
1121
|
+
function xt(e) {
|
|
1122
|
+
return n(e, "comment") && l(e.comment);
|
|
1123
|
+
}
|
|
1124
|
+
function Lt(e) {
|
|
1125
|
+
return n(e, "comments") && a(e.comments, l);
|
|
1126
|
+
}
|
|
1127
|
+
function b(e) {
|
|
1128
|
+
return n(
|
|
1129
|
+
e,
|
|
1130
|
+
"reply_id",
|
|
1131
|
+
"comment_id",
|
|
1132
|
+
"replied_by",
|
|
1133
|
+
"nickname",
|
|
1134
|
+
"avatar_url",
|
|
1135
|
+
"content",
|
|
1136
|
+
"like_num",
|
|
1137
|
+
"liked",
|
|
1138
|
+
"reply_to",
|
|
1139
|
+
"create_time"
|
|
1140
|
+
) && Ct(e.reply_to);
|
|
1141
|
+
}
|
|
1142
|
+
function Ct(e) {
|
|
1143
|
+
return n(e, "reply_id", "replied_by", "avatar_url", "nickname");
|
|
1144
|
+
}
|
|
1145
|
+
function Pt(e) {
|
|
1146
|
+
return n(e) && ("comment" in e ? l(e.comment) : !0) && ("antispam" in e ? k(e.antispam) : !0);
|
|
1147
|
+
}
|
|
1148
|
+
function Ut(e) {
|
|
1149
|
+
return n(e, "replies") && a(e.replies, b);
|
|
1150
|
+
}
|
|
1151
|
+
function $t(e) {
|
|
1152
|
+
return n(e, "reply") && b(e.reply);
|
|
1153
|
+
}
|
|
1154
|
+
function Dt(e) {
|
|
1155
|
+
return n(e) && ("reply" in e ? l(e.comment) : !0) && ("antispam" in e ? k(e.antispam) : !0);
|
|
1156
|
+
}
|
|
1157
|
+
function Et(e) {
|
|
1158
|
+
return n(e, "image_url", "upload_url", "existed") && typeof e.existed == "boolean";
|
|
1159
|
+
}
|
|
1160
|
+
function Ft(e) {
|
|
1161
|
+
return n(
|
|
1162
|
+
e,
|
|
1163
|
+
"notification_id",
|
|
1164
|
+
"notification_type",
|
|
1165
|
+
"is_read",
|
|
1166
|
+
"create_time",
|
|
1167
|
+
"origin_user_id",
|
|
1168
|
+
"origin_user_name",
|
|
1169
|
+
"origin_user_avatar_url"
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
function Gt(e) {
|
|
1173
|
+
return n(e, "notifications") && a(e.notifications, Ft);
|
|
1174
|
+
}
|
|
1175
|
+
function It(e) {
|
|
1176
|
+
return n(e, "system", "comment", "like");
|
|
1177
|
+
}
|
|
1178
|
+
var St = /* @__PURE__ */ ((e) => (e.All = "all", e.Limit = "limit", e))(St || {}), Mt = /* @__PURE__ */ ((e) => (e.Pending = "pending", e.Approved = "approved", e.Failed = "failed", e.Suspect = "suspect", e))(Mt || {}), Bt = /* @__PURE__ */ ((e) => (e.System = "system", e.Comment = "comment", e.Like = "like", e))(Bt || {}), Vt = /* @__PURE__ */ ((e) => (e.System = "system", e.PostPinned = "post_pinned", e.PostHighlighted = "post_highlighted", e.PostDeleted = "post_deleted", e.PostCommented = "post_commented", e.PostLiked = "post_liked", e.CommentReplied = "comment_replied", e.CommentLiked = "comment_liked", e.CommentDeleted = "comment_deleted", e.ReplyReplied = "reply_replied", e.ReplyLiked = "reply_liked", e.ReplyDeleted = "reply_deleted", e))(Vt || {});
|
|
1179
|
+
class Xt {
|
|
1180
|
+
constructor(t) {
|
|
1181
|
+
u(this, "token");
|
|
1182
|
+
u(this, "req");
|
|
1183
|
+
this.token = t, this.req = t.req;
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* 获取社区版块列表,仅返回启用状态的版块
|
|
1187
|
+
*
|
|
1188
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=QaqUa2K0z0
|
|
1189
|
+
*/
|
|
1190
|
+
async getForums() {
|
|
1191
|
+
const { data: t } = await this.req.get("community/forums", kt);
|
|
1192
|
+
return (t == null ? void 0 : t.forums) || [];
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* 获取社区话题列表,仅返回启用状态的话题
|
|
1196
|
+
*
|
|
1197
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=mIwpymAQom
|
|
1198
|
+
*/
|
|
1199
|
+
async getTopics() {
|
|
1200
|
+
const { data: t } = await this.req.get("community/topics", bt);
|
|
1201
|
+
return (t == null ? void 0 : t.topics) || [];
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* 根据话题 ID 获取社区话题信息
|
|
1205
|
+
*
|
|
1206
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=Jvw7xMK31K
|
|
1207
|
+
*/
|
|
1208
|
+
async getTopic(t) {
|
|
1209
|
+
const { data: r, code: i } = await this.req.get("community/topic", qt, {
|
|
1210
|
+
params: { topic_id: t }
|
|
1211
|
+
});
|
|
1212
|
+
return (r == null ? void 0 : r.topic) ?? { error: i };
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* 获取社区帖子列表
|
|
1216
|
+
*
|
|
1217
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=XKI9lDVrPq
|
|
1218
|
+
*/
|
|
1219
|
+
async getPosts(t) {
|
|
1220
|
+
const { data: r, code: i } = await this.req.get("community/posts", C, {
|
|
1221
|
+
params: s(t)
|
|
1222
|
+
});
|
|
1223
|
+
return r ?? { error: i };
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* 获取社区置顶帖子列表
|
|
1227
|
+
*
|
|
1228
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=yXubbZuDlC
|
|
1229
|
+
*/
|
|
1230
|
+
async getPinnedPosts(t, r, i) {
|
|
1231
|
+
const { data: c, code: m } = await this.req.get("community/pinned-posts", C, {
|
|
1232
|
+
params: s({ forum_id: t, max_results: r, next_token: i })
|
|
1233
|
+
});
|
|
1234
|
+
return c ?? { error: m };
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* 根据帖子 id 获取帖子详情
|
|
1238
|
+
*
|
|
1239
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=hj1AZy5rcP
|
|
1240
|
+
*/
|
|
1241
|
+
async getPost(t) {
|
|
1242
|
+
const { data: r, code: i } = await this.req.get("community/post", Rt, {
|
|
1243
|
+
params: { post_id: t }
|
|
1244
|
+
});
|
|
1245
|
+
return (r == null ? void 0 : r.post) ?? { error: i };
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* 发布帖子
|
|
1249
|
+
*
|
|
1250
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=M5okHBuaVk
|
|
1251
|
+
*/
|
|
1252
|
+
async post(t) {
|
|
1253
|
+
const { data: r, code: i } = await this.req.post("community/post", s(t), At);
|
|
1254
|
+
return r ?? {
|
|
1255
|
+
error: i
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* 获取社区帖子评论列表
|
|
1260
|
+
*
|
|
1261
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=djKbX7lFdp
|
|
1262
|
+
*/
|
|
1263
|
+
async getComments(t) {
|
|
1264
|
+
const { data: r, code: i } = await this.req.get("community/comments", Lt, {
|
|
1265
|
+
params: s(t)
|
|
1266
|
+
});
|
|
1267
|
+
return r ?? { error: i };
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* 根据评论 id 获取评论详情
|
|
1271
|
+
*
|
|
1272
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=RIc7oxVGae
|
|
1273
|
+
*/
|
|
1274
|
+
async getComment(t) {
|
|
1275
|
+
const { data: r, code: i } = await this.req.get("community/comment", xt, {
|
|
1276
|
+
params: { comment_id: t }
|
|
1277
|
+
});
|
|
1278
|
+
return (r == null ? void 0 : r.comment) ?? { error: i };
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* 帖子下发表评论
|
|
1282
|
+
*
|
|
1283
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=Nv7lk0nTmr
|
|
1284
|
+
*/
|
|
1285
|
+
async comment(t) {
|
|
1286
|
+
await this.token.autoLogin();
|
|
1287
|
+
const { data: r, code: i } = await this.req.post("community/comment", s(t), Pt);
|
|
1288
|
+
return r ?? {
|
|
1289
|
+
error: i
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* 获取社区帖子评论回复列表
|
|
1294
|
+
*
|
|
1295
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=sVKBbY83MY
|
|
1296
|
+
*/
|
|
1297
|
+
async getReplies(t) {
|
|
1298
|
+
const { data: r } = await this.req.get("community/replies", Ut, {
|
|
1299
|
+
params: s({ max_results: 20, ...t })
|
|
1300
|
+
});
|
|
1301
|
+
return r ?? { replies: [] };
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* 根据回复 id 获取回复详情
|
|
1305
|
+
*
|
|
1306
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=kxhcSXD3MG
|
|
1307
|
+
*/
|
|
1308
|
+
async getReply(t) {
|
|
1309
|
+
const { data: r, code: i } = await this.req.get("community/reply", $t, {
|
|
1310
|
+
params: { reply_id: t }
|
|
1311
|
+
});
|
|
1312
|
+
return (r == null ? void 0 : r.reply) ?? { error: i };
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* 回复帖子评论或回复
|
|
1316
|
+
*
|
|
1317
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=KA8WpTX2pg
|
|
1318
|
+
*/
|
|
1319
|
+
async reply(t) {
|
|
1320
|
+
await this.token.autoLogin();
|
|
1321
|
+
const { data: r, code: i } = await this.req.post("community/reply", s(t), Dt);
|
|
1322
|
+
return r ?? {
|
|
1323
|
+
error: i
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* 对 帖子/评论/回复 点赞
|
|
1328
|
+
*
|
|
1329
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=CR3m6PyXfZ
|
|
1330
|
+
*/
|
|
1331
|
+
async like(t) {
|
|
1332
|
+
await this.token.autoLogin();
|
|
1333
|
+
const { ok: r, code: i } = await this.req.post("community/like", { ...t, action: "like" });
|
|
1334
|
+
return r || {
|
|
1335
|
+
error: i
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* 对 帖子/评论/回复 取消点赞
|
|
1340
|
+
*
|
|
1341
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=CR3m6PyXfZ
|
|
1342
|
+
*/
|
|
1343
|
+
async unlike(t) {
|
|
1344
|
+
await this.token.autoLogin();
|
|
1345
|
+
const { ok: r, code: i } = await this.req.post("community/like", { ...t, action: "unlike" });
|
|
1346
|
+
return r || {
|
|
1347
|
+
error: i
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* 获取资源预上传地址
|
|
1352
|
+
*
|
|
1353
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=dWWhpoShxZ
|
|
1354
|
+
*/
|
|
1355
|
+
async getMediaPresignUrl(t) {
|
|
1356
|
+
await this.token.autoLogin();
|
|
1357
|
+
const { data: r } = await this.req.get("community/media-presign-url", Et, {
|
|
1358
|
+
params: t
|
|
1359
|
+
});
|
|
1360
|
+
return r;
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* 获取用户社区通知
|
|
1364
|
+
*
|
|
1365
|
+
* 了解更多[通知的分类](https://kdocs.cn/l/cbggfJodHLIz?linkname=AiCR5khgOr)。
|
|
1366
|
+
*
|
|
1367
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=W5lceDgbBG
|
|
1368
|
+
*/
|
|
1369
|
+
async getNotifications(t) {
|
|
1370
|
+
await this.token.autoLogin();
|
|
1371
|
+
const { data: r } = await this.req.get("community/notifications", Gt, {
|
|
1372
|
+
params: s({ max_results: 20, ...t })
|
|
1373
|
+
});
|
|
1374
|
+
return r || { notifications: [] };
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* 获取用户未读通知数量
|
|
1378
|
+
*
|
|
1379
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=CwIOMjAfMU
|
|
1380
|
+
*/
|
|
1381
|
+
async getUnreadNotificationsCount() {
|
|
1382
|
+
if (!await this.token.autoLogin()) return null;
|
|
1383
|
+
const { data: t } = await this.req.get("community/unread-notifications-count", It);
|
|
1384
|
+
return t;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* 社区用户将通知标为已读
|
|
1388
|
+
*
|
|
1389
|
+
* https://kdocs.cn/l/cbggfJodHLIz?linkname=TCJQxnOjJe
|
|
1390
|
+
*/
|
|
1391
|
+
async clearUnreadNotifications(t) {
|
|
1392
|
+
if (!await this.token.autoLogin()) return !1;
|
|
1393
|
+
const { ok: r } = await this.req.post("community/clear-unread-notifications", { category: t });
|
|
1394
|
+
return r;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
function p(e) {
|
|
1398
|
+
return n(e, "openid", "unionid", "weixin_token");
|
|
1399
|
+
}
|
|
1400
|
+
var Qt = /* @__PURE__ */ ((e) => (e.RedirectUriDisMatch = "10003", e.AppidError = "10016", e.AuthorizationError = "10015", e.NoRightForScope = "10005", e.Frequently = "10009", e.AppBanded = "10004", e.ShouldFllow = "10006", e.ScopeNull = "10010", e.RedirectUriNull = "10011", e.AppidNull = "10012", e.StateNull = "10013", e))(Qt || {});
|
|
1401
|
+
const P = "wx_login_cache";
|
|
1402
|
+
class Yt {
|
|
1403
|
+
/**
|
|
1404
|
+
* 创建微信相关功能接口
|
|
1405
|
+
*
|
|
1406
|
+
* - authToken 需要导入 AuthToken 进行初始化后传入
|
|
1407
|
+
* - appid 可以静态设置,也可以在小程序中动态获取,见下示例代码
|
|
1408
|
+
*
|
|
1409
|
+
* ```js
|
|
1410
|
+
* const info = wx.getAccountInfoSync();
|
|
1411
|
+
* console.log(info.miniProgram.appId)
|
|
1412
|
+
* ```
|
|
1413
|
+
*
|
|
1414
|
+
* https://developers.weixin.qq.com/miniprogram/dev/api/open-api/account-info/wx.getAccountInfoSync.html
|
|
1415
|
+
*/
|
|
1416
|
+
constructor(t, r) {
|
|
1417
|
+
u(this, "token");
|
|
1418
|
+
u(this, "appid");
|
|
1419
|
+
u(this, "req");
|
|
1420
|
+
this.token = t, this.req = t.req, this.appid = r, this.getLoginCache();
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* 检查缓存中的登录数据
|
|
1424
|
+
*
|
|
1425
|
+
* 如果没有缓存或缓存数据错误,则需要调用 [wx.login](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html) 后调用 login 方法
|
|
1426
|
+
*
|
|
1427
|
+
* 也可以直接调用 login 方法,并传入 wxcode 的读取函数
|
|
1428
|
+
*/
|
|
1429
|
+
async getLoginCache() {
|
|
1430
|
+
const t = await this.token.storage.get(P);
|
|
1431
|
+
if (!t)
|
|
1432
|
+
return null;
|
|
1433
|
+
const r = J(t);
|
|
1434
|
+
return p(r) ? (this.token.weixinToken = r.weixin_token, await this.token.autoLogin(), r) : null;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* 小程序页面微信静默登录,获取 weixinToken / openid / unionid。
|
|
1438
|
+
*
|
|
1439
|
+
* 使用场景:
|
|
1440
|
+
*
|
|
1441
|
+
* - 小程序的任意页面打开后应该优先调用此方法以获取登录状态
|
|
1442
|
+
*
|
|
1443
|
+
* 注意:
|
|
1444
|
+
*
|
|
1445
|
+
* - 登录成功后会将登录信息缓存到本地,重复或并发调用不会引起任何副作用。
|
|
1446
|
+
* - 由于小程序的存储是以用户维度隔离的,每个微信用户在每个小程序下只要成功调用一次此 API 就会缓存请求结果。
|
|
1447
|
+
* - 微信公众号网页授权请使用 webLogin 方法
|
|
1448
|
+
*
|
|
1449
|
+
* https://kdocs.cn/l/cf2mO2uRLqh9?linkname=GwIZ0givCb
|
|
1450
|
+
*
|
|
1451
|
+
* @param wxLoginCodeGetter - 微信小程序调用 [wx.login](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html) 获得的登录凭证
|
|
1452
|
+
*/
|
|
1453
|
+
async login(t) {
|
|
1454
|
+
const r = await this.getLoginCache();
|
|
1455
|
+
if (r)
|
|
1456
|
+
return r;
|
|
1457
|
+
const i = await t(), { data: c, code: m } = await this.req.post(
|
|
1458
|
+
"weixin/login",
|
|
1459
|
+
{ code: i, appid: this.appid },
|
|
1460
|
+
p,
|
|
1461
|
+
{ message: !1 }
|
|
1462
|
+
);
|
|
1463
|
+
return c && (this.token.weixinToken = c.weixin_token, await Promise.all([this.token.autoLogin(), this.token.storage.set(P, JSON.stringify(c))])), c ?? { error: m };
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* 在微信内嵌网页中调用微信公众号授权登录【暂未启用】
|
|
1467
|
+
*
|
|
1468
|
+
* 注意:
|
|
1469
|
+
*
|
|
1470
|
+
* - 登录回调地址强制是当前页面,包括 location search 和 location hash 部分
|
|
1471
|
+
* - 登录跳转返回 code 后,会将 code 从 url 中删除以防止 code 泄露,如需设置分享则需要在此方法执行完毕之后
|
|
1472
|
+
*
|
|
1473
|
+
* 官方参考资料:
|
|
1474
|
+
*
|
|
1475
|
+
* - [微信网页开发 / 网页授权](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html)
|
|
1476
|
+
*
|
|
1477
|
+
* @param scope - 网页授权作用域
|
|
1478
|
+
* - snsapi_base 不弹出授权页面,用户无感知,只能获取用户 openid,如果需要获取 unionid 则需要 snsapi_userinfo
|
|
1479
|
+
* - snsapi_userinfo 【默认】弹出授权页面,可拿到 openid、unionid、昵称、头像等信息,但用户也可能会拒绝授权
|
|
1480
|
+
*/
|
|
1481
|
+
async webLogin(t = "snsapi_userinfo") {
|
|
1482
|
+
const r = f("code"), i = Date.now(), c = +f("state");
|
|
1483
|
+
if (!r || !c || c < i - 1e3 * 60 * 5 || c > i) {
|
|
1484
|
+
const I = q(["code", "state"]);
|
|
1485
|
+
location.replace(
|
|
1486
|
+
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appid}&redirect_uri=${encodeURIComponent(I)}&response_type=code&scope=${t}&state=${i}#wechat_redirect`
|
|
1487
|
+
);
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
if (/^100\d{2}$/.test(r))
|
|
1491
|
+
return { error: r };
|
|
1492
|
+
const m = q(["code", "state"]);
|
|
1493
|
+
"replaceState" in history && history.replaceState({}, "", m);
|
|
1494
|
+
const { data: _, code: G } = await this.req.post(
|
|
1495
|
+
"weixin/login",
|
|
1496
|
+
{
|
|
1497
|
+
code: r,
|
|
1498
|
+
appid: this.appid
|
|
1499
|
+
},
|
|
1500
|
+
p
|
|
1501
|
+
);
|
|
1502
|
+
return _ && (this.token.weixinToken = _.weixin_token, await this.token.autoLogin()), _ ?? { error: G };
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* 关联游戏账号,无返回值,全程静默
|
|
1506
|
+
*
|
|
1507
|
+
* 用于从游戏内跳转至小程序时,将微信用户身份和游戏内身份关联起来,使得后续的企业微信客服流程能够知道该微信用户在游戏内的身份。
|
|
1508
|
+
*
|
|
1509
|
+
* https://kdocs.cn/l/cf2mO2uRLqh9?linkname=ci73N833Mk
|
|
1510
|
+
*
|
|
1511
|
+
* @param weixinToken 调用 login 后,得到的 weixinToken,如果 weixinToken 为空则跳过不处理
|
|
1512
|
+
* @param gameCode 从游戏内跳转至小程序时,通过请求参数 query 携带的 game_code,如果值为空则跳过不处理
|
|
1513
|
+
*/
|
|
1514
|
+
async linkPlayer(t, r) {
|
|
1515
|
+
!t || !r || await this.req.post(
|
|
1516
|
+
"weixin/link-player",
|
|
1517
|
+
{
|
|
1518
|
+
weixin_token: t,
|
|
1519
|
+
game_code: r
|
|
1520
|
+
},
|
|
1521
|
+
null,
|
|
1522
|
+
{
|
|
1523
|
+
message: !1
|
|
1524
|
+
}
|
|
1525
|
+
);
|
|
38
1526
|
}
|
|
39
1527
|
}
|
|
40
1528
|
export {
|
|
41
|
-
|
|
1529
|
+
Ot as AuthToken,
|
|
1530
|
+
qe as CliamRewardStatus,
|
|
1531
|
+
Kt as ClubApi,
|
|
1532
|
+
ge as ClubCreditChangeSence,
|
|
1533
|
+
_e as ClubCreditChangeType,
|
|
1534
|
+
de as ClubItemType,
|
|
1535
|
+
pe as ClubRedemptionStatus,
|
|
1536
|
+
Xt as CommunityApi,
|
|
1537
|
+
ye as EngageAccountType,
|
|
1538
|
+
Nt as EventApi,
|
|
1539
|
+
we as EventPeriodType,
|
|
1540
|
+
o as FeatureType,
|
|
1541
|
+
St as ForumMode,
|
|
1542
|
+
fe as GamerItemType,
|
|
1543
|
+
le as Gender,
|
|
1544
|
+
Ce as LotteryDrawAction,
|
|
1545
|
+
xe as LotteryTicketStatus,
|
|
1546
|
+
Bt as NotificationCategory,
|
|
1547
|
+
Vt as NotificationType,
|
|
1548
|
+
Mt as PostStatus,
|
|
1549
|
+
he as QuestObjective,
|
|
1550
|
+
Re as RewardSoure,
|
|
1551
|
+
ke as RewardStatusPrefix,
|
|
1552
|
+
be as RewardStatusSuffix,
|
|
1553
|
+
Le as TeamAction,
|
|
1554
|
+
Ae as TeamVisibility,
|
|
1555
|
+
ve as VoteOptionSource,
|
|
1556
|
+
Yt as WeixinApi,
|
|
1557
|
+
Qt as WeixinWebLoginErrorCode
|
|
42
1558
|
};
|