-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
150 lines (112 loc) · 5.48 KB
/
index.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<title>Iniciar - iChat | APIGratis</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<link rel="shortcut icon" href="https://imaladireta.com/images/icon/whatsapp.png" type="image/png">
<link rel="apple-touch-icon" sizes="194x194" href="https://imaladireta.com/images/icon/whatsapp.png" type="image/png">
<link rel="stylesheet" id="style" href="https://apigratis.com.br/static/css/demo/qrcode.css">
</head>
<body>
<div id="app">
<div class="app-wrapper app-wrapper-web">
<div id="wrapper">
<div id="window">
<div class="entry-main">
<div class="qrcode">
<img alt="Leia o QRCODE" id="base64" style="display: block;" src="https://imaladireta.com/images/icon/whatsapp.png">
</div>
<div class="entry-text" style="text-align: center;">
<div class="entry-title">Chat Demo APIGratis</div>
<div class="entry-subtitle">Use o WhatsApp no seu celular para ler o QRCODE</div>
<div class="entry-controls">
<label> <button type="button" id="buttonStart" class="btn btn-primary"> Conectar nova sessão</button> </label>
<div class="hint">Será iniciado uma sessão com nome inserido no javascript</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/gasparesganga-jquery-loading-overlay@2.1.7/dist/loadingoverlay.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.socket.io/4.3.2/socket.io.min.js" integrity="sha384-KAZ4DtjNhLChOB/hxXuKqhMLYvx3b5MlT55xPEiNmREKRzeEm+RVPlTnAn0ajQNs" crossorigin="anonymous"></script>
<script>
$(document).ready(() => {
const SERVIDOR = `https://whatsapp-srv07.apigratis.com.br`
const apitoken = `5E22BC1231XGFQ36B7CEA234F35C47651A6`
const session = `SUA_SESSION`
const sessionkey = `SUA_SESSIONKEY`
const wh_connect = `` //webhook
const wh_message = `` //webhook
const wh_status = `` //webhook
const wh_qrcode = `` //webhook
try {
socket = io(`${SERVIDOR}`, {
withCredentials: false,
});
} catch (error) {
console.log('API Desconectada!!! cd /opt/MyZap2.x.x.x node start index.js')
}
$(`#buttonStart`).on(`click`, async () => {
await requestMyZap(apitoken, session, sessionkey, wh_connect, wh_message, wh_status, wh_qrcode, 'start')
})
async function requestMyZap(apitoken, sessionkey, session, wh_connect, wh_message, wh_status, wh_qrcode, action) {
let URL = `${SERVIDOR}/${action}`
socket.on(`events`, (events) => {
$(".hint").html(`<span style="color: green;">${events?.message}</span>`)
if (events.session == session) {
$(`#base64`).attr(`src`, events?.qrCode);
$(`#base64`).LoadingOverlay("hide")
$(`#buttonStart`).attr(`disabled`, true)
$(`#base64`).LoadingOverlay("hide")
if (events?.state === 'CONNECTED' && events?.status === 'inChat') {
$("#base64").attr("src", 'https://smartpink.com.br/site/assets/img/check.gif');
setTimeout(() => {
window.location.replace(`/chat?sessionkey=${sessionkey}&session=${session}`);
}, 4000)
}
}
})
switch (action) {
case `start`:
await $.post({
url: `${URL}`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apitoken': `${apitoken ?? ''}`,
'sessionkey': `${sessionkey ?? ''}`
},
data: JSON.stringify({
session: session ?? '',
wh_connect: wh_connect ?? '',
wh_message: wh_message ?? '',
wh_status: wh_status ?? '',
wh_qrcode: wh_qrcode ?? '',
}),
beforeSend: function(data, xhr) {
$(`#base64`).LoadingOverlay("show")
},
success: function(data) {
console.log(data)
$(`#buttonStart`).attr(`disabled`, false)
},
error: function(error) {
console.log(error)
$(`#base64`).LoadingOverlay("hide")
},
})
break;
default:
console.log('requisição inválida.')
break;
}
}
});
</script>