无法使用php通过聊天API接收whatsup消息
我使用PHP的聊天API发送和接收Whatsapp消息,我可以发送消息,但我无法接收消息 这是我的参考: 下面是我的PHP代码:无法使用php通过聊天API接收whatsup消息,php,jquery,api,chat,chatbot,Php,Jquery,Api,Chat,Chatbot,我使用PHP的聊天API发送和接收Whatsapp消息,我可以发送消息,但我无法接收消息 这是我的参考: 下面是我的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){ //
$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>";
}
$url='mychatAPI/message?token=tokenId';
$result=file_get_contents($url);//发送请求
$data=json_decode($result,1);//解析JSON
foreach($data['messages']作为$message){//Echo每条消息
回显“发件人:”.$message['author']。“
”;
echo“Message:.$Message['body']。”
”;
}
我还尝试使用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
}
});
var url='mychatAPI/message?token=tokenId';
$.get(url,函数(数据){//发出get请求
对于(var i=0;i
我收到了一条未发送的消息:空身体。请在JSON POST的body参数中提供消息文本。
当我回显$data
告诉我如何使用chatId或author接收Whatsapp消息,或者是否有任何方式接收消息。
或
告诉我我可以使用哪个API来接收whatsup消息,或者使用
PHP或javascript或jquery阅读消息您向我们显示的错误是逻辑错误。如果您试图获取消息,您实际上会发送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);
您向我们显示的错误是逻辑性的,如果您试图获取消息,实际上是发送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);