SocialService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Services;
  3. use GuzzleHttp\Client;
  4. use Illuminate\Support\Facades\Log;
  5. class SocialService
  6. {
  7. protected $apiUrl = 'https://kapi.kakao.com';
  8. protected $restApiKey;
  9. public function __construct()
  10. {
  11. $this->restApiKey = env('KAKAO_REST_API_KEY');
  12. }
  13. public function sendMessage($channelId, $args)
  14. {
  15. Log::debug('channelId: ' . $channelId);
  16. // Log::debug('args: ' . json_decode($args));
  17. $client = new Client([
  18. 'base_uri' => $this->apiUrl,
  19. 'headers' => [
  20. 'Authorization' => 'KakaoAK ' . $this->restApiKey,
  21. 'Content-Type' => 'application/json',
  22. ],
  23. ]);
  24. // Log::debug('결과: ' . $response);
  25. // $response = $client->post('/v1/api/talk/channel/' . $channelId . '/message', [
  26. $response = $client->post('/v1/api/talk/channels/' . $channelId . '/message', [
  27. 'json' => [
  28. 'template_object' => [
  29. 'object_type' => 'text',
  30. 'message' => $args['message'],
  31. 'link' => [
  32. 'web_url' => $args['link_url'],
  33. ],
  34. ],
  35. ],
  36. ]);
  37. dd($response);
  38. return $response->getBody()->getContents();
  39. }
  40. }