Created
July 25, 2021 12:36
-
-
Save biscuitrainbow/7a5b983fe7b7ec2336fa352fee15cf06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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