Created
October 14, 2017 04:44
-
-
Save stachibana/971af4921a341e6350b78222a9b7f205 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/vendor/autoload.php'; | |
define('TABLE_NAME_USERS', 'users'); | |
$httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient(getenv('CHANNEL_ACCESS_TOKEN')); | |
$bot = new \LINE\LINEBot($httpClient, ['channelSecret' => getenv('CHANNEL_SECRET')]); | |
$signature = $_SERVER["HTTP_" . \LINE\LINEBot\Constant\HTTPHeader::LINE_SIGNATURE]; | |
try { | |
$events = $bot->parseEventRequest(file_get_contents('php://input'), $signature); | |
} catch(\LINE\LINEBot\Exception\InvalidSignatureException $e) { | |
error_log("parseEventRequest failed. InvalidSignatureException => ".var_export($e, true)); | |
} catch(\LINE\LINEBot\Exception\UnknownEventTypeException $e) { | |
error_log("parseEventRequest failed. UnknownEventTypeException => ".var_export($e, true)); | |
} catch(\LINE\LINEBot\Exception\UnknownMessageTypeException $e) { | |
error_log("parseEventRequest failed. UnknownMessageTypeException => ".var_export($e, true)); | |
} catch(\LINE\LINEBot\Exception\InvalidEventRequestException $e) { | |
error_log("parseEventRequest failed. InvalidEventRequestException => ".var_export($e, true)); | |
} | |
foreach ($events as $event) { | |
$inputString = file_get_contents('php://input'); | |
error_log($inputString); | |
if ($event instanceof \LINE\LINEBot\Event\MessageEvent) { | |
if($event instanceof \LINE\LINEBot\Event\MessageEvent\TextMessage) { | |
$bot->replyText($event->getReplyToken(), 'message from beacon bot'); | |
} | |
} | |
else if($event instanceof \LINE\LINEBot\Event\BeaconDetectionEvent) { | |
$bot->replyText($event->getReplyToken(), 'beacon event fired -> ' . $event->getHwid() . ' : ' . $event->getBeaconEventType() . ' : ' . $event->getDeviceMessage()); | |
//{"events":[{"type":"beacon","replyToken":"a4d324d7aabd4d80ac041e54fd8b0f46","source":{"userId":"U5e8f9121ac6c4dde98356f48acba2642","type":"user"},"timestamp":1507180006633,"beacon":{"hwid":"000001938c","type":"enter"}}]} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment