douju8113 2015-12-19 19:38
浏览 498

使用chat-API接收消息

I want to make an retrieve messages from WhatsApp server every 2 seconds. I am using this jQuery function :

          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);

and the PHP code:

<?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();

    ?>

The problem is that I am getting loginFaulierException at many calls (not all of them). Is there is a better way to receive messages or in other words how does the WhatsApp native app works?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line