用户信息
当游戏在GameTok APP内运行时,APP会自动将用户信息附加到URL中供游戏读取。以下是附加参数的示例:
index.html?gameId=906&uid=2111265&userId=2111265&sessionId=10102651744178667593&token=1c83bd22489b24bb84d20c6d758e9c8e&language=en&zone=sa&country=SA&version_name=1.10.0250409120005&login_type=google&appChannel=lobah
1
参数说明
部分参数描述:
参数名称 | 描述 |
---|---|
gameId | 游戏ID |
uid | 用户ID |
sessionId | 房间ID |
token | 验证令牌 |
appChannel | lobah (渠道标识) |
获取参数示例代码
开发者可在游戏内通过如下 JavaScript 代码获取 URL 参数:
javascript
function getUrlParams() {
const queryString = window.location.search ||
(window.location.hash.includes('?') ? window.location.hash.substring(window.location.hash.indexOf('?')) : '')
const params = {}
if (queryString) {
queryString.slice(1).split('&').forEach(pair => {
if (pair) {
const [key, ...valueParts] = pair.split('=')
try {
params[decodeURIComponent(key)] = valueParts.length
? decodeURIComponent(valueParts.join('='))
: ''
} catch (e) {
console.warn('Failed to decode parameter:', pair)
}
}
})
}
return params
}
// 使用示例
const params = getUrlParams()
// 获取具体参数
const gameId = params.gameId // 游戏ID
const uid = params.uid // 用户ID
const sessionId = params.sessionId // 房间ID
const token = params.token // 验证令牌
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
常见问题
Q: 如果参数缺失怎么办?
A: 请确保游戏通过 GameTok APP 正常打开,若参数异常请联系平台支持。Q: token 有效期多久?
A: token 有效期与用户登录状态相关,建议每次进入游戏时都校验 token。