-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.htm
83 lines (76 loc) · 2.6 KB
/
index.htm
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<title>TelegramBot PHP WebValidation test</title>
<script>
function submitData(e)
{
e.preventDefault();
const wa=window.Telegram.WebApp;
if (wa.initData)
{
const received_data=wa.initDataUnsafe;
const send_data=new URLSearchParams({
auth_date: received_data.auth_date,
hash : received_data.hash,
initData: wa.initData
});
console.log('ftch')
fetch("./api.php?"+send_data.toString())
.then((response) => {
return response.json();
})
.then((data) => {
document.querySelector("#sent-data").innerHTML="<h3>Sent data:</h3>"+JSON.stringify(data.sent_data).replace(/,"/mg,',<br/>"');
document.querySelector("#signed").innerHTML="<h4>Signed</h4>"+data.signed;
document.querySelector("#secret").innerHTML="<h4>Secret</h4>"+data.secret;
document.querySelector("#hash").innerHTML="<h4>Hash</h4>"+data.hash;
if (data.is_valid)
{
document.querySelector("#info-msg").innerHTML="Data is valid";
}
else
{
document.querySelector("#info-msg").innerHTML="Data is INVALID";
}
});
}
else
{
alert("started not form Telegram webapp");
}
}
function initDataLoad() {
if (window.Telegram.WebApp.initData) {
const initData = window.Telegram.WebApp.initData;
document.querySelector("#init-data").innerHTML=JSON.stringify(initData).replace(/,"/mg,',<br/>"');
}
}
</script>
</head>
<body >
<div id="init-data"></div>
<div class="form-item">
<form name="form" method="GET" id="form" onsubmit="submitData(event)">
<input type="submit" name='submit' value="Send data from telegram"/>
</form>
<div id="info-msg"></div>
<div id="sent-data"></div>
<div id="signed"></div>
<div id="secret"></div>
<div id="hash"></div>
</div>
</body>
<style>
.form-item
{
margin:20px;
}
#sent-data
{
max-width:100vw;
}
</style>
</html>