Skip to content

Instantly share code, notes, and snippets.

@pankpan
Last active May 30, 2016 16:13
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 pankpan/936a94175b7ef720599a24d0b2c285d1 to your computer and use it in GitHub Desktop.
Save pankpan/936a94175b7ef720599a24d0b2c285d1 to your computer and use it in GitHub Desktop.
LINE BOT PHP Sample
$channel_id="xxxxxxxxxx";
$channel_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$channel_mid="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$endpoint_url="https://trialbot-api.line.me/v1/events";
$arr=json_decode(file_get_contents("php://input"),1);
$from=$arr['result'][0]['content']['from'];
$text=$arr['result'][0]['content']['text'];
$post_data="{\"to\":[\"$from\"],\"toChannel\":1383378250,\"eventType\":\"138311608800106203\",\"content\":{\"contentType\":1,\"toType\":1,\"text\":\"$text\"}}";
$ch=curl_init();
$headers=array("Content-Type: application/json; charser=UTF-8","X-Line-ChannelID: $channel_id","X-Line-ChannelSecret: $channel_secret","X-Line-Trusted-User-With-ACL: $channel_mid");
curl_setopt($ch, CURLOPT_URL, $endpoint_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment