@seayoo-web/gamer-api 1.0.0 → 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 +68 -5
- 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/README.md
CHANGED
|
@@ -1,11 +1,74 @@
|
|
|
1
1
|
# Gamer Api Agent
|
|
2
2
|
|
|
3
|
+
## 页面初始化
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { NetRequest } from "@seayoo-web/request";
|
|
7
|
+
import { AuthToken, EventApi, ClubApi, CommunityApi } from "@seayoo-web/gamer-api";
|
|
8
|
+
|
|
9
|
+
const authToken = new AuthToken("https://gamer-api.seayoo.com", NetRequest);
|
|
10
|
+
const eventApi = new EventApi(authToken, eventId);
|
|
11
|
+
const clubApi = new ClubApi(authToken);
|
|
12
|
+
const communityApi = new CommunityApi(authToken);
|
|
13
|
+
|
|
14
|
+
// 设置 idToken 后即可认为登录(会在内部自动进行 gamerToken 的置换操作)
|
|
15
|
+
// idToken 通过通行证登录组件获取
|
|
16
|
+
export function login(idToken: string) {
|
|
17
|
+
authToken.idToken = idToken;
|
|
18
|
+
// 可选自动登录调用,后续每个 api 都会自动检查并 autoLogin
|
|
19
|
+
authToken.autoLogin();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 如果在 ComboWebView 中,url query 会直接提供 gamer_token
|
|
23
|
+
// authToken 会自动从 url query 中读取并更新 gamer_token
|
|
24
|
+
|
|
25
|
+
// 导出供其他功能使用
|
|
26
|
+
export { eventApi, clubApi, communityApi, weixinApi };
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 小程序初始化
|
|
30
|
+
|
|
3
31
|
```js
|
|
4
|
-
import {
|
|
32
|
+
import { NetRequest } from "@seayoo-web/request/wx";
|
|
33
|
+
import { AuthToken, EventApi, ClubApi, WeixinApi } from "@seayoo-web/gamer-api";
|
|
34
|
+
import { usePromise } from "@seayoo-web/utils";
|
|
5
35
|
|
|
6
|
-
|
|
7
|
-
const
|
|
36
|
+
const authToken = new AuthToken("https://gamer-api.seayoo.com", NetRequest);
|
|
37
|
+
const eventApi = new EventApi(authToken, eventId);
|
|
38
|
+
const clubApi = new ClubApi(authToken);
|
|
39
|
+
const communityApi = new CommunityApi(authToken);
|
|
40
|
+
const weixinApi = new WeixinApi(authToken, appId);
|
|
8
41
|
|
|
9
|
-
//
|
|
10
|
-
|
|
42
|
+
// 获取 weixinToken / unionid / openid
|
|
43
|
+
export async function weixinLogin() {
|
|
44
|
+
const result = await weixinApi.login(() => {
|
|
45
|
+
const { promise, resolve } = usePromise<string>()
|
|
46
|
+
// 调用 wx.login 获取 weixinCode
|
|
47
|
+
wx.login({
|
|
48
|
+
success(code) { resolve(code) },
|
|
49
|
+
fail({ errMsg, errno }) {
|
|
50
|
+
/* handle error */
|
|
51
|
+
resolve("")
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
return promise
|
|
55
|
+
})
|
|
56
|
+
if("error" in result) {
|
|
57
|
+
/* handle error */
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
return result; // { weixin_token, openid, unionid }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// idToken 通过通行证登录组件获取,weixinToken 通过上述方法获取
|
|
64
|
+
export function login(idToken: string, weixinToken: string) {
|
|
65
|
+
authToken.idToken = idToken
|
|
66
|
+
authToken.weixinToken = weixinToken;
|
|
67
|
+
// 可选自动登录调用,后续每个 api 都会自动检查并 autoLogin
|
|
68
|
+
authToken.autoLogin();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 导出供其他功能使用
|
|
72
|
+
export { eventApi, clubApi, communityApi, weixinApi };
|
|
11
73
|
```
|
|
74
|
+
|