GradwellSms.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. class GradwellSms extends SMSServiceApi {
  3. public function __construct($smsServiceId, array $smsPack = array()) {
  4. parent::__construct($smsServiceId, $smsPack);
  5. }
  6. public function pushMessages() {
  7. global $ubillingConfig;
  8. $apikey = $this->serviceApiKey;
  9. $sender = $this->serviceAlphaName;
  10. $smsHistoryEnabled = $ubillingConfig->getAlterParam('SMS_HISTORY_ON');
  11. $smsAdvancedEnabled = $ubillingConfig->getAlterParam('SMS_SERVICES_ADVANCED_ENABLED');
  12. $telepatia = new Telepathy(false);
  13. if ($smsHistoryEnabled) {
  14. $telepatia->flushPhoneTelepathyCache();
  15. $telepatia->usePhones();
  16. }
  17. $allSmsQueue = $this->smsMessagePack;
  18. if (!empty($allSmsQueue)) {
  19. $smsPacketId = strtoupper(md5(uniqid(rand(), true)));
  20. log_register('SENDDOG GRADWELLSMS sending SMS packet ' . $smsPacketId);
  21. foreach ($allSmsQueue as $eachsms) {
  22. $url = $this->serviceGatewayAddr
  23. . '?auth=' . $apikey
  24. . '&originator=' . $sender
  25. . '&destination=' . str_replace(array('+', '440'), array('', '44'), $eachsms['number'])
  26. . '&message=' . urlencode($eachsms['message']);
  27. $ch = curl_init($url);
  28. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  29. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  30. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  31. $result = curl_exec($ch);
  32. curl_close($ch);
  33. if (strpos($result, 'OK:') !== false) {
  34. if (strpos($result, 'id') !== false and $smsHistoryEnabled) {
  35. $idPos = strpos($result, 'id');
  36. $messID = trim(substr($result, $idPos + 2));
  37. //$PhoneToSearch = $this->sendDog->cutInternationalsFromPhoneNum($eachsms['number']);
  38. $Login = $telepatia->getByPhoneFast($eachsms['number']);
  39. if ($smsAdvancedEnabled) {
  40. $query = "INSERT INTO `sms_history` (`smssrvid`, `login`, `phone`, `srvmsgself_id`, `srvmsgpack_id`, `date_send`, `send_status`, `msg_text`)
  41. VALUES (" . $this->serviceId . ", '" . $Login . "', '" . $eachsms['number'] . "', '" . $messID . "', '" . $smsPacketId . "', '" . curdatetime() . "', '" . __('Message queued') . "', '" . $eachsms['message'] . "');";
  42. } else {
  43. $query = "INSERT INTO `sms_history` (`login`, `phone`, `srvmsgself_id`, `srvmsgpack_id`, `date_send`, `send_status`, `msg_text`)
  44. VALUES ('" . $Login . "', '" . $eachsms['number'] . "', '" . $messID . "', '" . $smsPacketId . "', '" . curdatetime() . "', '" . __('Message queued') . "', '" . $eachsms['message'] . "');";
  45. }
  46. nr_query($query);
  47. } else {
  48. log_register('SENDDOG GRADWELLSMS message ID not found - can\'t write history: ' . $result);
  49. }
  50. } elseif (strpos($result, 'ERR:') !== false) {
  51. log_register('SENDDOG GRADWELLSMS delivery failed with error: ' . $result);
  52. } else {
  53. log_register('SENDDOG GRADWELLSMS unknown server answer: ' . $result);
  54. }
  55. //remove old sent message
  56. $this->instanceSendDog->getSmsQueueInstance()->deleteSms($eachsms['filename']);
  57. }
  58. }
  59. }
  60. public function getBalance() {
  61. $this->showErrorFeatureIsNotSupported();
  62. }
  63. public function getSMSQueue() {
  64. $this->showErrorFeatureIsNotSupported();
  65. }
  66. public function checkMessagesStatuses() {
  67. log_register('Checking statuses for [' . get_class($this) . '] SMS service is not implemented');
  68. }
  69. }