LINEでアラートつくる
gmailの仕様のせいかvscriptのメールがとばないからlineで飛ばそうという試み
【前提】
- Winサーバ(っていうか、ただのPC) + PHP5.5
処理順としては
pushする
というのが理想。
HTTPS通信じゃないと行けないとかいう噂も目にしましたが果たして。
【準備】
- PHP
- composer
- git
【やるよ】
・SDKをcomposerで入れる(参考にさせていただきました)(composerすげえ)
qiita.com
↓で、こう
Using version ^2.2 for linecorp/line-bot-sdk
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing linecorp/line-bot-sdk (2.2.0): Downloading (100%)
Writing lock file
Generating autoload files
サンプルソースに従って、こんなん書いてみる
test.php
$httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient('LINEアカウントのユーザID');
$bot = new \LINE\LINEBot($httpClient, ['channelSecret' => 'アクセストークン']);$textMessageBuilder = new \LINE\LINEBot\MessageBuilder\TextMessageBuilder('hello');
$response = $bot->pushMessage('', $textMessageBuilder); echo $response->getHTTPStatus() . ' ' . $response->getRawBody();
LINEアカウントのユーザIDはLine DevelopersのChannel>Basic informationの中に
(いっつも忘れるから、メモ)
叩いてみると、下記エラー
PHP Fatal error: Uncaught exception 'LINE\LINEBot\Exception\CurlExe
cutionException' with message 'error setting certificate verify locations:
CAfile: C:test\ca-bundle.crt
CApath: none' in C:\test\vendor\linecorp\line-bot-sdk
\src\LINEBot\HTTPClient\CurlHTTPClient.php:114
Stack trace:
#0 C:\test\vendor\linecorp\line-bot-sdk\src\LINEBot\HTT
PClient\CurlHTTPClient.php(75): LINE\LINEBot\HTTPClient\CurlHTTPClient->sendRequ
est('POST', 'https://api.lin...', Array, Array)
#1 C:\test\vendor\linecorp\line-bot-sdk\src\LINEBot.php
(144): LINE\LINEBot\HTTPClient\CurlHTTPClient->post('https://api.lin...', Array)#2 C:\test\test.php(11): LINE\LINEBot->pushMessage('
', Object(LINE\LINEBot\MessageBuilder\TextMessageBuilder))
#3 {main}
thrown in C:\test\vendor\linecorp\line-bot-sdk\src\LI
NEBot\HTTPClient\CurlHTTPClient.php on line 114
SSL認証か。。。。うーん。。。。また今度にします