EknotifierSms.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace ElkenGit\EknotifierPHP;
  3. use Carbon\Carbon;
  4. /**
  5. * Class SmsNotifier to provide SMS Notifier integration for EKNotifier Service.
  6. */
  7. class EknotifierSms extends EknotifierCommon
  8. {
  9. /**
  10. * Instantiate EknotifierSms Class.
  11. *
  12. * @param string|null $url
  13. * @param string|null $applicationCode
  14. * @param string|null $applicationPassword
  15. * @throws \Exception
  16. */
  17. public function __construct(string $url = null, string $applicationCode = null, string $applicationPassword = null)
  18. {
  19. parent::__construct($url, $applicationCode, $applicationPassword);
  20. }
  21. /**
  22. * Send an SMS.
  23. *
  24. * @param string $phoneNumber
  25. * @param string $text
  26. * @param int $userId
  27. * @return bool
  28. * @throws \GuzzleHttp\Exception\GuzzleException
  29. */
  30. public function sendSMS(string $phoneNumber, string $text, int $userId = 0): bool
  31. {
  32. $token = $this->getAuthToken();
  33. $request = [
  34. 'name' => $this->applicationCode . ' SMS ' . $phoneNumber,
  35. 'send_at' => date('Y-m-d H:i:s', time()),
  36. 'recipients' => [
  37. [
  38. 'application_user_id' => $userId,
  39. 'delivery_destination' => $phoneNumber,
  40. 'delivery_type' => 'SMS',
  41. 'body' => $text
  42. ]
  43. ]
  44. ];
  45. return $this->postAPI('notification/send', $request, $token);
  46. }
  47. }