Skip to content

Instantly share code, notes, and snippets.

@biscuitrainbow
Created July 25, 2021 12:36
Show Gist options
  • Save biscuitrainbow/7a5b983fe7b7ec2336fa352fee15cf06 to your computer and use it in GitHub Desktop.
Save biscuitrainbow/7a5b983fe7b7ec2336fa352fee15cf06 to your computer and use it in GitHub Desktop.
<?php
namespace App\Services;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
class LineMessagingService
{
public function push($to, $messages)
{
$response = Http::withToken(env('LINE_BOT_CHANNEL_ACCESS_TOKEN'))
->withBody(json_encode([
'to' => $to,
'messages' => $messages,
]), 'application/json')
->post('https://api.line.me/v2/bot/message/push');
$response->throw()->json();
return $response;
}
public function multicast($to, $messages)
{
$response = Http::withToken(env('LINE_BOT_CHANNEL_ACCESS_TOKEN'))
->withBody(json_encode([
'to' => $to,
'messages' => $messages,
]), 'application/json')
->post('https://api.line.me/v2/bot/message/multicast');
$response->throw()->json();
return $response;
}
public function setDefaultRichMenuForUser($lineUserId, $richMenuId)
{
$response = Http::withToken(env('LINE_BOT_CHANNEL_ACCESS_TOKEN'))
->post("https://api.line.me/v2/bot/user/{$lineUserId}/richmenu/{$richMenuId}");
$response->throw()->json();
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment