Simple class makes work with chat-api.com easier
$api = new ChatApi( '_token_', // Chat-Api.com token 'https://foo.chat-api.com/instance1234' // Chat-Api.com API url );
Server example:
if(isset($_GET['qr']) { header('Content-Type: image/png'); readfile( $api->getQRCode() ); }
Client example:
<script> $.get('index.php', {'qr': '1'}, function(i) { switch(i) { case 'init': text = 'Клиент не инициализирован'; break; case 'error': text = 'Ошибка: Chat-Api не отвечает'; break; case 'loading': text = 'Идёт загрузка с WhatsApp'; break; case 'got qr code': text = 'Получен QR-код'; $('#qrcode')[0].src = 'index.php?act=qr'; break; case 'authenticated': text = 'Онлайн'; break; } alert(text); }); </script>
die( ($api->sendPhoneMessage('+12345', 'It works!') == true) ? 'Message sent' : 'Fail' );