PHP code example of jeurboy / line-sdk

1. Go to this page and download the library: Download jeurboy/line-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeurboy / line-sdk example snippets


namespace Jeurboy\LineSdk;

==== Notify token ==========';

$line_noti = Line::notify($receipientToken);

$line_text = Line::textMessage();
$line_text->setMessage('Test');

if ($line_noti->send( $line_text ) !== true) {
    echo $line_noti->getErrorMessage()."\n";
} else {
    echo "Success\n";
}

namespace Jeurboy\LineSdk;

 Access token ==========';
$channelSecret = '========== Channel secret key ==========';

$request = file_get_contents('php://input');   // Get request content

$line_bot = Line::bot($accessToken, $channelSecret);

$line_text = Line::textMessage();

$parser = Line::eventParser($request);
$events = $parser->parseEvents();

foreach ($events as $event) {
    switch ($event->getType()) {
        case 'Text':
            $line_text->setMessage('Test reply : '.$event->getMessage());
            $line_bot->send($event->getReplyToken(), $line_text);

            break;
    }
}