api.smsserviceapi.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Class SMSServiceApi to be inherited by real SMS services APIs implementations
  4. * located in 'api/vendor/sms_service_APIs' to provide re-usability and common interaction interface for SendDogAdvanced class
  5. */
  6. abstract class SMSServiceApi {
  7. /**
  8. * SendDogAdvanced instance plceholder
  9. *
  10. * @var null
  11. */
  12. protected $instanceSendDog = null;
  13. /**
  14. * Placeholder for settings record data from sms_services table
  15. *
  16. * @var array
  17. */
  18. protected $apiSettingsRaw = array();
  19. /**
  20. * SMS service ID in sms_services table
  21. *
  22. * @var int
  23. */
  24. protected $serviceId = 0;
  25. /**
  26. * SMS service login
  27. *
  28. * @var string
  29. */
  30. protected $serviceLogin = '';
  31. /**
  32. * SMS service password
  33. *
  34. * @var string
  35. */
  36. protected $servicePassword = '';
  37. /**
  38. * SMS service base URL/IP
  39. *
  40. * @var string
  41. */
  42. protected $serviceGatewayAddr = '';
  43. /**
  44. * SMS service alpha name
  45. *
  46. * @var string
  47. */
  48. protected $serviceAlphaName = '';
  49. /**
  50. * SMS service API key
  51. *
  52. * @var string
  53. */
  54. protected $serviceApiKey = '';
  55. /**
  56. * Assigned as a default SMS service
  57. *
  58. * @var bool
  59. */
  60. protected $isDefaultService = false;
  61. /**
  62. * Messages to be processed by push method
  63. *
  64. * @var array
  65. */
  66. protected $smsMessagePack = array();
  67. /**
  68. * Placeholder for UbillingConfig object
  69. *
  70. * @var null
  71. */
  72. protected $ubConfig = null;
  73. public function __construct($smsServiceId, $smsPack = array()) {
  74. global $ubillingConfig;
  75. $this->ubConfig = $ubillingConfig;
  76. $this->serviceId = $smsServiceId;
  77. $this->instanceSendDog = new SendDogAdvanced();
  78. $this->apiSettingsRaw = $this->instanceSendDog->getSmsServicesConfigData(" WHERE `id` = " . $smsServiceId);
  79. $this->getSettings();
  80. $this->smsMessagePack = $smsPack;
  81. }
  82. /**
  83. * Fills up the config placeholders for a particular SMS service
  84. */
  85. protected function getSettings() {
  86. if (!empty($this->apiSettingsRaw)) {
  87. $this->serviceLogin = $this->apiSettingsRaw[0]['login'];
  88. $this->servicePassword = $this->apiSettingsRaw[0]['passwd'];
  89. $this->serviceGatewayAddr = $this->apiSettingsRaw[0]['url_addr'];
  90. $this->serviceAlphaName = $this->apiSettingsRaw[0]['alpha_name'];
  91. $this->serviceApiKey = $this->apiSettingsRaw[0]['api_key'];
  92. $this->isDefaultService = $this->apiSettingsRaw[0]['default_service'];
  93. }
  94. }
  95. /**
  96. * Returns styled error message about not supported features
  97. */
  98. protected function showErrorFeatureIsNotSupported() {
  99. $errormes = $this->instanceSendDog->getUBMsgHelperInstance()->getStyledMessage(__('This SMS service does not support this function'), 'error', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  100. die(wf_modalAutoForm(__('Error'), $errormes, $_POST['modalWindowId'], '', true));
  101. }
  102. public abstract function getBalance();
  103. public abstract function getSMSQueue();
  104. public abstract function pushMessages();
  105. public abstract function checkMessagesStatuses();
  106. }