@seayoo-web/gamer-api 1.0.3 → 1.1.0
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 +6 -14
- package/dist/index.js +359 -295
- package/package.json +8 -8
- package/types/src/token.d.ts +16 -15
- package/types/src/token.define.d.ts +0 -4
- package/types/src/utils.d.ts +8 -2
- package/types/src/weixin.d.ts +1 -3
package/README.md
CHANGED
|
@@ -19,6 +19,11 @@ export function login(idToken: string) {
|
|
|
19
19
|
authToken.autoLogin();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// 检测是否登录,登录后获取用户数据
|
|
23
|
+
export async function getUserInfo() {
|
|
24
|
+
return authToken.isLogined ? await authToken.getSession() : null
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
// 如果在 ComboWebView 中,url query 会直接提供 gamer_token
|
|
23
28
|
// authToken 会自动从 url query 中读取并更新 gamer_token
|
|
24
29
|
|
|
@@ -31,7 +36,6 @@ export { eventApi, clubApi, communityApi, weixinApi };
|
|
|
31
36
|
```js
|
|
32
37
|
import { NetRequest } from "@seayoo-web/request/wx";
|
|
33
38
|
import { AuthToken, EventApi, ClubApi, WeixinApi } from "@seayoo-web/gamer-api";
|
|
34
|
-
import { usePromise } from "@seayoo-web/utils";
|
|
35
39
|
|
|
36
40
|
const authToken = new AuthToken("https://gamer-api.seayoo.com", NetRequest);
|
|
37
41
|
const eventApi = new EventApi(authToken, eventId);
|
|
@@ -41,18 +45,7 @@ const weixinApi = new WeixinApi(authToken, appId);
|
|
|
41
45
|
|
|
42
46
|
// 获取 weixinToken / unionid / openid
|
|
43
47
|
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
|
-
})
|
|
48
|
+
const result = await weixinApi.login()
|
|
56
49
|
if("error" in result) {
|
|
57
50
|
/* handle error */
|
|
58
51
|
return null
|
|
@@ -71,4 +64,3 @@ export function login(idToken: string, weixinToken: string) {
|
|
|
71
64
|
// 导出供其他功能使用
|
|
72
65
|
export { eventApi, clubApi, communityApi, weixinApi };
|
|
73
66
|
```
|
|
74
|
-
|