-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtgMiniApps.html
40 lines (39 loc) · 1.14 KB
/
tgMiniApps.html
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
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#test {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script>
console.log('777', window.Telegram.WebApp.initDataUnsafe.user);
// 等待 Telegram Web App 完成初始化
window.Telegram.WebApp.ready(() => {
// 获取用户信息
const user = window.Telegram.WebApp.initDataUnsafe.user;
if (user) {
console.log('用户信息:', user);
// 你可以在这里处理用户信息,比如显示用户名、用户 ID 等
const userId = user.id;
const userName = user.username;
const firstName = user.first_name;
const lastName = user.last_name;
window.Telegram.WebApp.showAlert(userName);
// 进一步处理用户信息
} else {
console.log('未获取到用户信息');
}
});
</script>
<div id="test"></div>
</body>
</html>