duanlu0559 2018-01-30 02:00
浏览 47

使用NGROK开发facebook messenger始终响应NULL

I had completed setting for ngrok and webhook on facebook.

this is very simple webhook by PHP


$access_token = "my_access_token";
$verify_token = "my_verify_token";

$hub_verify_token = "";
if (isset($_REQUEST['hub_challenge'])) {
    $challenge = $_REQUEST['hub_challenge'];
    $hub_verify_token = $_REQUEST['hub_verify_token'];
}

if ($hub_verify_token === $verify_token) {
    echo $challenge;
    exit();
}

$input = json_decode(file_get_contents('php://input'), true);


$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
$message = $input['entry'][0]['messaging'][0]['message']['text'];
$message_to_reply = 'I could see your message';


$myjsondata = '{
    "recipient":{
        "id":"' . $sender . '"
    },
    "message":{
        "text":"' . $message_to_reply . '"
    }
}';

send("me/messages", $mydata, $input, $access_token);


function send($type, $data, $input, $access_token) {

    $url = 'https://graph.facebook.com/v2.11/' . $type . '?access_token=' . $access_token;

    $ch = curl_init($url);

    $jsonDataEncoded = $data;

    curl_setopt($ch, CURLOPT_POST, 1);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

    if (!empty($input['entry'][0]['messaging'][0]['message'])) {
        $result = curl_exec($ch);
        // **this $result is always NULL**
    }
}

Result, i could receive json info from user typing in my localhost envirment. But when excuting curl, this $result is always NULL and having no error ,so weird. What's wrong with this ?

PS: If i change webhook to cloud host, Operation is normal but hard to debug :(

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘