前提・実現したいこと
「おもしろまじめなチャットボットをつくろう」
http://cgi1.plala.or.jp/~higpen/book/chatBot/index.shtml
でチャットボットを作成しています。
P97からの応答するBotで返信が来ません。
ネットに落ちている別のPHPプログラムでは返信がきます。
本を参考にしながら書いたプログラムで返信が来ない理由がわかりません。
ラインボットが得意な方、PHP得意な方、よろしければ教えてください。
該当のソースコード
■main.php
<?php require_once('hello/hello.php'); define('DEBUG','debug.txt'); require_once('tool.php'); $input=file_get_contents('php://input'); debug('input',$input); if(!empty($input)){ $events=json_decode($input)->events; foreach($events as $event){ bot($event); } } ■tool.php <?php define('TOKEN','ここにはラインのトークンをいれています。'); if(file_exists(DEBUG)) unlink(DEBUG); function debug($title,$text){ file_put_contents(DEBUG,'['.$title.']'."\n".$text."\n\n",FILE_APPEND); } function post($url,$object){ $json=json_encode($object); debug('output',$json); $curl=curl_init('https://api.line.me/v2/bot/message/'.$url); curl_setopt($curl,CURLOPT_POST,true); curl_setopt($curl,CURLOPT_POSTFIELDS,$json); curl_setopt($curl,CURLOPT_HTTPHEADER,[ 'Content-Type:application/json', 'Authorization:Bearer'.TOKEN ]); $result=curl_exec($curl); debug('result',$result); curl_close($curl); } function reply($event,$text){ $object=[ 'replyToken'=>$event->replyToken, 'messages'=>[['type'=>'text','text'=>$text]] ]; post('reply',$object); } ■hello/hello.php <?php function bot($event){ reply($event,'HELLO'); } ```ここに言語名を入力 ソースコード PHP ``` ### 試したこと ブラウザから各PHPにアクセスして、500が出ませんので、コンパイルは出来ています。 http://www.lb-yado.tk/mybot/debug.txt https://www.lb-yado.tk/mybot/main.php https://www.lb-yado.tk/mybot/tool.php https://www.lb-yado.tk/mybot/hello/hello.php ### 補足情報(FW/ツールのバージョンなど) ラインはSSL通信でのみ可能で、 共有SSLサーバーを契約して、 別のPHPプログラムでは応答が来ることから、SSL通信は問題ありません。回答1件
あなたの回答
tips
プレビュー