File size: 5,144 Bytes
58f870a
7a8928a
d7ae16d
 
 
 
 
7a8928a
 
 
 
 
 
 
 
d7ae16d
 
7a8928a
 
d7ae16d
7a8928a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7ae16d
7a8928a
 
 
 
 
 
 
 
 
 
d7ae16d
 
7a8928a
 
 
 
 
 
 
 
 
 
 
 
 
d7ae16d
 
7a8928a
 
 
 
 
d7ae16d
 
 
 
7a8928a
d7ae16d
15790cd
 
 
 
 
 
d7ae16d
 
291e8c2
6c01ee1
7a8928a
326b9e2
7a8928a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7ae16d
 
 
 
 
 
 
82924f3
d7ae16d
 
 
 
 
 
 
7a8928a
d7ae16d
 
 
 
 
 
 
 
 
15790cd
d7ae16d
 
 
 
 
 
 
 
 
 
 
 
 
0292fb1
291e8c2
d7ae16d
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="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WhatsApp QR Code</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f0f0f0;
        }
        .header {
            background-color: #4CAF50;
            color: white;
            text-align: center;
            padding: 15px 0;
            font-size: 24px;
        }
        .container {
            display: flex;
            justify-content: space-between;
            padding: 20px;
        }
        .form-container, .qr-container {
            flex: 1;
            margin: 10px;
        }
        .form-container {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
        }
        form {
            width: 100%;
        }
        label, input {
            display: block;
            width: 100%;
            margin-bottom: 10px;
        }
        input {
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .button {
            width: 100%;
            padding: 16px 32px;
            margin-top: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition-duration: 0.4s;
        }
        .button:hover {
            background-color: #45a049;
        }
        .qr-container {
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        #qrCode {
            margin-top: 20px;
            border: 1px solid #ccc;
            padding: 10px;
            background-color: white;
            border-radius: 8px;
        }
        #statusText {
            text-align: center;
            color: blue;
            margin-top: 10px;
        }
        .success-message {
            color: green;
            font-size: 20px;
            text-align: center;
            margin-top: 10px;
        }
    </style>
</head>
<body>

    <div class="header">Авторизация</div>

    <div class="container">
        <div class="form-container">
            <form id="authForm">
                <label for="idInstance">Id Instance:</label>
                <input required type="text" id="idInstance" name="idInstance" value="1101761238">
                <label for="apiTokenInstance">API Token:</label>
                <input required type="text" id="apiTokenInstance" name="apiTokenInstance" value="88b54820abd5445894bf547dca2fb2f32ee6e70a29004c18ab">
                <button type="submit" class="button">Get QR Code</button>
            </form>
        </div>
        <div class="qr-container">
            <p id="statusText"></p>
            <img id="qrCode" src="" alt="QR Code" hidden>
        </div>
    </div>

    <script>
        document.getElementById("authForm").addEventListener("submit", function(event) {
            event.preventDefault();

            const idInstance = document.getElementById("idInstance").value;
            const apiTokenInstance = document.getElementById("apiTokenInstance").value;
            const apiUrl = "https://api.green-api.com"; // Замените на фактический URL API

            function updateQRCode() {
                fetch(`${apiUrl}/waInstance${idInstance}/qr/${apiTokenInstance}`)
                    .then(response => response.json())
                    .then(data => {
                        const qrCodeElement = document.getElementById("qrCode");
                        const statusText = document.getElementById("statusText");

                        if (data.type === 'qrCode') {
                            qrCodeElement.src = `data:image/png;base64,${data.message}`;
                            qrCodeElement.hidden = false;
                            statusText.textContent = "";
                        } else if (data.type === 'error') {
                            qrCodeElement.hidden = true;
                            statusText.textContent = `Error: ${data.message}`;
                        } else if (data.type === 'alreadyLogged') {
                            qrCodeElement.hidden = true;
                            statusText.innerHTML = "<div class='success-message'>Аккаунт авторизирован!<br>API рассылка активна.</div>";
                        }
                    })
                    .catch(error => {
                        console.error("Error fetching QR code:", error);
                        document.getElementById("statusText").textContent = "Error fetching QR code.";
                    });
            }

            // Запуск обновления QR-кода каждую секунду
            setInterval(updateQRCode, 1000);
            updateQRCode(); // Вызов сразу после отправки формы
        });
    </script>

</body>
</html>