LoginSignup
13
16

More than 5 years have passed since last update.

LINE messaging API サンプル php

Last updated at Posted at 2016-10-05

オウム返しbot

<?php
define('TOKEN', 'トークンを入力');

//callback確認
$obj = json_decode(file_get_contents('php://input'));

//textとreplyToken取得
$event = $obj->{"events"}[0];
$text = $event->{"message"}->{"text"};
$replyToken = $event->{"replyToken"};

$post = [
    "replyToken" => $replyToken,
    "messages" => [
                    "type" => "text",
                    "text" => $text]
                  ];

$ch = curl_init("https://api.line.me/v2/bot/message/reply");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json; charser=UTF-8',
    'Authorization: Bearer ' . TOKEN;
    ));
13
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
16