如何在带有框架php slim的行bot中使用实现flex消息json

时间:2018-07-06 17:06:45

标签: php slim

如何使用苗条框架在行式bot中实现flex message json?我在两天内进行了搜索,但未找到如何将flex message json实现到php或如何使用它。这是我的php

$app->post('/webhook', function ($request, $response) use ($bot, $pass_signature)
{
// get request body and line signature header
$body        = file_get_contents('php://input');
$signature = isset($_SERVER['HTTP_X_LINE_SIGNATURE']) ? $_SERVER['HTTP_X_LINE_SIGNATURE'] : '';

// log body and signature
file_put_contents('php://stderr', 'Body: '.$body);

if($pass_signature === false)
{
    // is LINE_SIGNATURE exists in request header?
    if(empty($signature)){
        return $response->withStatus(400, 'Signature not set');
    }

    // is this request comes from LINE?
    if(! SignatureValidator::validateSignature($body, $channel_secret, $signature)){
        return $response->withStatus(400, 'Invalid signature');
    }
}

// kode aplikasi nanti disini
$data = json_decode($body, true);
if(is_array($data['events'])){
    foreach ($data['events'] as $event)
    {
        if ($event['type'] == 'message')
        {
            if($event['message']['type'] == 'text')
            {
                if($event['message']['text'] == 'menu')
                {
                    // flex message json use here
                    // $textMessageBuilder = new TextMessageBuilder($event['message']['text']);
                    // $result = $bot->replyMessage($event['replyToken'], $textMessageBuilder);
                }
                return $response->withJson($result->getJSONDecodedBody(), $result->getHTTPStatus());
            }
        }
    }
}

});

0 个答案:

没有答案