我了解使用Facebook Messenger API时,您必须在收到任何webhook事件后使用200 OK
标头进行响应,否则API将每20秒重新发送一次webhook事件,直到200 OK
如https://developers.facebook.com/docs/messenger-platform/webhook/#response
我用下面的代码回复了200 OK
标头
<?php
header('HTTP/1.0 200 OK');
//.. some define here
//check token at setup
if(isset($_REQUEST['hub_verify_token']) && $_REQUEST['hub_verify_token'] === HUB_VERIFY_TOKEN){
echo $_REQUEST['hub_challenge'];
exit;
}
else{
$input = file_get_contents('php://input');
//... further process
}
使用此方法,API不会收到200 OK
,因为它会多次(例如100次)重新发送Webhook,并且不会传递新的Webhook,但是当我向sender_id发送消息时,它会传递。 / p>
下面只是我不断收到的约100个中的最后3个。我究竟做错了什么?
{"object":"page","entry":[{"id":"2229337433988598","time":1553082378936,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082476255,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082569721,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082667807,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082753466,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}