【问题标题】:can not receive whatsup message with chat API using php无法使用 php 接收带有聊天 API 的 whatsapp 消息
【发布时间】:2020-06-30 10:57:06
【问题描述】:

我正在使用带有 PHP 的聊天 API 来发送和接收 Whatsapp 消息,我可以发送消息但我无法接收消息。

这是我的参考:https://chat-api.com/en/?lang=EN

这是我的 PHP 代码:

$url = 'mychatAPI/message?token=tokenId';
$result = file_get_contents($url); // Send a request
$data = json_decode($result, 1); // Parse JSON
foreach($data['messages'] as $message){ // Echo every message
    echo "Sender:".$message['author']."<br>";
    echo "Message: ".$message['body']."<br>";
}

我也尝试过使用 Jquery:

var url = 'mychatAPI/message?token=tokenId';
$.get(url, function (data) { // Make a GET request
    for (var i = 0; i < data.messages.length; i++) { // For each message
        var message = data.messages[i];
        console.log(message.author + ': ' + message.body); //Send it to console
    } 
});

当我回显$data时,我得到了这个Message was not sent: empty body. Please provide message text in body parameter in JSON POST.

告诉我如何通过使用 chatId 或作者接收我的 Whatsapp 消息,或者有什么方法可以接收消息。 或者 告诉我可以使用哪个 API 来接收我的 whatsup 消息或使用 PHP or javascript or jquery 阅读消息。

【问题讨论】:

    标签: php jquery api chat chatbot


    【解决方案1】:

    如果您尝试获取消息,您向我们显示的错误是逻辑错误,您实际上发送了一个 POST 请求来获取消息。

    这样做:

    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'GET'
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      相关资源
      最近更新 更多