用户信息
当游戏在Lobah 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=lobah1
部分参数描述:
| 参数名称 | 描述 |
|---|---|
| gameId | 游戏ID |
| uid | 用户ID |
| sessionId | 房间ID |
| token | 验证令牌 |
| appChannel | lobah (渠道标识) |
因此,在游戏内部,您可以使用以下JavaScript代码来获取用户信息:
javascript
function getUrlParams() {
const hash = window.location.hash
const url = window.location.search || hash.slice(hash.indexOf('?'))
const obj = {}
const reg = /[?&][^?&]+=[^?&]+/g
const arr = url.match(reg)
if (arr) {
arr.forEach(function (item) {
const tempArr = item.substring(1).split('=')
const key = decodeURIComponent(tempArr[0])
obj[key] = decodeURIComponent(tempArr[1])
})
}
return obj
}
const params = getUrlParams()
params.gameId // Game ID
params.uid // User ID
params.sessionId // Room ID
params.token // token1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21