使用chat-API接收消息

时间:2015-12-19 19:38:54

标签: php jquery whatsapp whatsapi

我想每隔2秒从WhatsApp服务器发送一条检索消息。我正在使用这个jQuery函数:

          setInterval(function(){   
                $.post("recevie_message.php",{},function(data){

                       console.log(data);
                       $arr=JSON.parse(data);
                       $.each($arr,function(index,value){
                              console.log(value.body);
                              var templateResponse = Handlebars.compile( $("#message-response-template").html());
                              var contextResponse = {response:value.body};
                   $('.chat-history').append(templateResponse(contextResponse));

                        });
          },2000);

和PHP代码:

<?php
  include_once('checkUserSession.php');
  $w=$task->connectToServer();
 // header ('Content-Type: text/html; charset=UTF-8'); 
  $username= $task->getPhoneNumber();
  $password = $task->getWhatsappPassword();
  $msg = array();
  $i=0;
  function onMessage($mynumber, $from, $id, $type, $time, $name, $body)
{
   $GLOBALS['msg'][$GLOBALS['i']]=array("from"=>$from,"body"=>$body);
   $GLOBALS['task']->saveMessage($body,'f','t',$from);
   $GLOBALS['i']++;
}


      include_once('Chat-API-master/src/events/MyEvents.php');
      $events = new MyEvents($w);
      $w->eventManager()->bind("onGetMessage", "onMessage");

      $w->pollMessage();
      echo json_encode($msg);
      $w->disconnect();


      //$w->disconnect();

    ?>

问题是我在很多电话中得到loginFaulierException(并非所有电话)。 是否有更好的方式来接收消息,换句话说,WhatsApp原生应用程序是如何工作的?

0 个答案:

没有答案