EknotifierSmsDriver.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace common\components;
  3. use common\helpers\LoggerTool;
  4. use common\models\Countries;
  5. use common\models\SmsRecord;
  6. use ElkenGit\EknotifierPHP\EknotifierSms;
  7. class EknotifierSmsDriver implements SmsDriverInterface
  8. {
  9. /**
  10. * Send SMS via Eknotifier.
  11. *
  12. * @param string $mobile
  13. * @param string $message
  14. * @param string $userId
  15. * @param string $countryId
  16. * @param string $classify
  17. * @return bool
  18. * @throws \Exception
  19. */
  20. public function send(string $mobile, string $message, string $userId, string $countryId, string $classify = ''): bool
  21. {
  22. $eknotifierUrl = \Yii::$app->params['sms']['url'];
  23. $applicationCode = \Yii::$app->params['sms']['url'];
  24. $applicationPassword = \Yii::$app->params['sms']['url'];
  25. $zoneCode = Countries::getZoneCodeById($countryId);
  26. $eknotifierSms = new EknotifierSms($eknotifierUrl, $applicationCode, $applicationPassword);
  27. $response = $eknotifierSms->sendSMS($mobile, $message, $userId);
  28. LoggerTool::debug(['eknotifierSms', $eknotifierUrl, $applicationCode, $applicationPassword, $mobile, $zoneCode, $message, $userId, $eknotifierSms, $response]);
  29. $record = new SmsRecord();
  30. $record->USER_ID = $userId;
  31. $record->CLASSIFY = $classify;
  32. $record->COUNTRY_ID = $countryId;
  33. $record->MOBILE = $mobile;
  34. $record->ZONE_CODE = $zoneCode;
  35. $record->CONTENT = $message;
  36. $record->RESULT = '';
  37. $record->save();
  38. return true;
  39. }
  40. }