Help us understand the problem. What is going on with this article?

LINE Notifyを使って、PHPとGuzzleでLINEに通知を送る

More than 1 year has passed since last update.

このエントリは、下記の記事のコードをGuzzleを使って書き換えたものです。
LINE Notifyを使って、PHPとcurlでLINEに通知を送る

コード

notifyを利用します

<?php
require_once 'vendor/autoload.php';

use GuzzleHttp\Client;

$token = 'トークン';
$message = 'Guzzleを使ってLINEに通知します';

$client = new Client(['base_uri' => 'https://notify-api.line.me/api/']);

$client->post('notify', [
    'headers' => [
        'Content-Type'  =>  'application/x-www-form-urlencoded',
        'Authorization' =>  'Bearer ' . $token
    ],
    'form_params' => [
        'message'   =>  $message
    ]
]);

post('notify', 'リクエスト内容')
request('POST', 'notify', 'リクエスト内容')に書き換えることができます。

statusを利用します

<?php
require_once 'vendor/autoload.php';

use GuzzleHttp\Client;

$token = 'トークン';

$client = new Client(['base_uri' => 'https://notify-api.line.me/api/']);

$response = $client->get('status',
    ['headers' => ['Authorization' => 'Bearer ' . $token]]);

var_dump($response);

上記と同様、
get('notify', 'リクエスト内容')
request('GET', 'notify', 'リクエスト内容')に書き換えることもできます。

revokeを利用します

<?php
require_once 'vendor/autoload.php';

use GuzzleHttp\Client;

$token = 'トークン';

$client = new Client(['base_uri' => 'https://notify-api.line.me/api/']);

$client->post('revoke', [
    'headers' => [
        'Content-Type'  =>  'application/x-www-form-urlencoded',
        'Authorization' =>  'Bearer ' . $token
    ]
]);

これもpost('revoke', 'リクエスト内容')
request('POST', 'revoke', 'リクエスト内容')に書き換えることができます。

参照した記事

LaravelでLineNotifyの認証からやってみる

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away