Last active
November 5, 2017 04:28
-
-
Save kinokoRider/19d3b527d316271f8e50089c1775c6a9 to your computer and use it in GitHub Desktop.
LINEMessaginAPIWrapper.php
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 | |
//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; | |
} | |
} | |
?> |
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 | |
$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