Skip to content

Instantly share code, notes, and snippets.

@kinokoRider
Last active November 5, 2017 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinokoRider/19d3b527d316271f8e50089c1775c6a9 to your computer and use it in GitHub Desktop.
Save kinokoRider/19d3b527d316271f8e50089c1775c6a9 to your computer and use it in GitHub Desktop.
LINEMessaginAPIWrapper.php
<?php
//LINEMessagingAPIに接続するラッパークラスです。
//line/line-bot-sdk-php を利用しています。
//参考:https://github.com/line/line-bot-sdk-php
class LineMessage {
private $httpClient;
private $bot;
private $channelAccessToken = 'your-channel-acccessToken';
private $channelSecret = 'your-channel-acccessSecret'
//LINEMessagingAPI接続用クライアントの作成
public function MakeClient(){
$this->httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient($this->channelAccessToken);
}
//LINE BOTのオブジェクト作成
public function MakeBot(){
$this->bot = new \LINE\LINEBot($this->httpClient, ['channelSecret' => $this->channelSecret]);
}
//テキストメッセージのオブジェクト作成
public function MakeMessageBuilder($strRetrunMessage){
$textMessageBuilder = new \LINE\LINEBot\MessageBuilder\TextMessageBuilder($retrunMessage);
return $textMessageBuilder;
}
//テキストメッセージ送信&結果を受信
public function MakeMessageResponse($retrunMessage, $replyToken){
$r_message = $this->MakeMessageBuilder($retrunMessage);
$response = $this->bot->replyMessage($replyToken, $r_message);
return $response;
}
}
?>
<?php
$lineMessage = new LineMessage();
$lineMessage->MakeClient();
$lineMessage->MakeBot();
$objReturnMessage = $lineMessage->MakeMessageBuilder($strReturnMessage);
$lineMessage->MakeMessageResponse($objReturnMessage, $replyToken);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment