smsfly.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. class smsfly extends SendDogProto {
  3. /**
  4. * Loads SMS-Fly service config
  5. *
  6. * @return void
  7. */
  8. public function loadSmsflyConfig() {
  9. $smsgateway = zb_StorageGet('SENDDOG_SMSFLY_GATEWAY');
  10. if (empty($smsgateway)) {
  11. $smsgateway = 'http://sms-fly.com/api/api.php';
  12. zb_StorageSet('SENDDOG_SMSFLY_GATEWAY', $smsgateway);
  13. }
  14. $smslogin = zb_StorageGet('SENDDOG_SMSFLY_LOGIN');
  15. if (empty($smslogin)) {
  16. $smslogin = '380501234567';
  17. zb_StorageSet('SENDDOG_SMSFLY_LOGIN', $smslogin);
  18. }
  19. $smspassword = zb_StorageGet('SENDDOG_SMSFLY_PASSWORD');
  20. if (empty($smspassword)) {
  21. $smspassword = 'MySecretPassword';
  22. zb_StorageSet('SENDDOG_SMSFLY_PASSWORD', $smspassword);
  23. }
  24. $smssign = zb_StorageGet('SENDDOG_SMSFLY_SIGN');
  25. if (empty($smssign)) {
  26. $smssign = 'InfoCentr';
  27. zb_StorageSet('SENDDOG_SMSFLY_SIGN', $smssign);
  28. }
  29. $this->settings['SMSFLY_GATEWAY'] = $smsgateway;
  30. $this->settings['SMSFLY_LOGIN'] = $smslogin;
  31. $this->settings['SMSFLY_PASSWORD'] = $smspassword;
  32. $this->settings['SMSFLY_SIGN'] = $smssign;
  33. }
  34. /**
  35. * Returns set of inputs, required for SMS-Fly service configuration
  36. *
  37. * @return string
  38. */
  39. public function renderSmsflyConfigInputs() {
  40. $inputs = wf_tag('h2') . __('SMS-Fly') . ' ' . wf_Link(self::URL_ME . '&showmisc=smsfly', wf_img_sized('skins/icon_dollar.gif', __('Balance'), '10', '10'), true) . wf_tag('h2', true);
  41. $inputs .= wf_TextInput('editsmsflygateway', __('SMS-Fly API address'), $this->settings['SMSFLY_GATEWAY'], true, 30);
  42. $inputs .= wf_TextInput('editsmsflylogin', __('User login to access SMS-Fly API'), $this->settings['SMSFLY_LOGIN'], true, 20);
  43. $inputs .= wf_TextInput('editsmsflypassword', __('User password for access SMS-Fly API'), $this->settings['SMSFLY_PASSWORD'], true, 20);
  44. $inputs .= wf_TextInput('editsmsflysign', __('SMS-Fly') . ' ' . __('Sign') . ' (' . __('Alphaname') . ')', $this->settings['SMSFLY_SIGN'], true, 20);
  45. $smsServiceFlag = ($this->settings['SMS_SERVICE'] == 'smsfly') ? true : false;
  46. $inputs .= wf_RadioInput('defaultsmsservice', __('Use SMS-Fly as default SMS service'), 'smsfly', true, $smsServiceFlag);
  47. return ($inputs);
  48. }
  49. /**
  50. * Sends all sms storage via sms-fly.com service
  51. *
  52. * @return void
  53. */
  54. public function smsflyPushMessages() {
  55. $result = '';
  56. $apiUrl = $this->settings['SMSFLY_GATEWAY'];
  57. $source = $this->safeEscapeString($this->settings['SMSFLY_SIGN']);
  58. $description = "Ubilling_" . zb_rand_string(8);
  59. $start_time = 'AUTO';
  60. $end_time = 'AUTO';
  61. $rate = 1;
  62. $lifetime = 4;
  63. $user = $this->settings['SMSFLY_LOGIN'];
  64. $password = $this->settings['SMSFLY_PASSWORD'];
  65. $allSmsQueue = $this->smsQueue->getQueueData();
  66. if (!empty($allSmsQueue)) {
  67. foreach ($allSmsQueue as $io => $eachsms) {
  68. $number = str_replace('+', '', $eachsms['number']); //numbers in international format without +
  69. $myXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  70. $myXML .= "<request>";
  71. $myXML .= "<operation>SENDSMS</operation>";
  72. $myXML .= ' <message start_time="' . $start_time . '" end_time="' . $end_time . '" lifetime="' . $lifetime . '" rate="' . $rate . '" desc="' . $description . '" source="' . $source . '">' . "\n";
  73. $myXML .= " <body>" . $eachsms['message'] . "</body>";
  74. $myXML .= " <recipient>" . $number . "</recipient>";
  75. $myXML .= "</message>";
  76. $myXML .= "</request>";
  77. $ch = curl_init();
  78. curl_setopt($ch, CURLOPT_USERPWD, $user . ':' . $password);
  79. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  80. curl_setopt($ch, CURLOPT_POST, 1);
  81. curl_setopt($ch, CURLOPT_URL, $apiUrl);
  82. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Accept: text/xml"));
  83. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  84. curl_setopt($ch, CURLOPT_POSTFIELDS, $myXML);
  85. $result .= curl_exec($ch);
  86. curl_close($ch);
  87. //remove old sent message
  88. $this->smsQueue->deleteSms($eachsms['filename']);
  89. }
  90. }
  91. }
  92. /**
  93. * Renders current SMS-Fly service user balance
  94. *
  95. * @return string
  96. */
  97. public function renderSmsflyBalance() {
  98. $result = '';
  99. $myXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  100. $myXML .= "<request>";
  101. $myXML .= "<operation>GETBALANCE</operation>";
  102. $myXML .= "</request>";
  103. $ch = curl_init();
  104. curl_setopt($ch, CURLOPT_USERPWD, $this->settings['SMSFLY_LOGIN'] . ':' . $this->settings['SMSFLY_PASSWORD']);
  105. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  106. curl_setopt($ch, CURLOPT_POST, 1);
  107. curl_setopt($ch, CURLOPT_URL, $this->settings['SMSFLY_GATEWAY']);
  108. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Accept: text/xml"));
  109. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  110. curl_setopt($ch, CURLOPT_POSTFIELDS, $myXML);
  111. $response = curl_exec($ch);
  112. curl_close($ch);
  113. $result .= wf_BackLink(self::URL_ME, '', true);
  114. $result .= $this->messages->getStyledMessage(__('Current account balance') . ': ' . $response, 'info');
  115. return ($result);
  116. }
  117. /**
  118. * Saves service settings to database
  119. *
  120. * @return void
  121. */
  122. public function saveSettings() {
  123. //SMS-Fly configuration
  124. if ($_POST['editsmsflygateway'] != $this->settings['SMSFLY_GATEWAY']) {
  125. zb_StorageSet('SENDDOG_SMSFLY_GATEWAY', $_POST['editsmsflygateway']);
  126. log_register('SENDDOG CONFIG SET SMSFLYGATEWAY `' . $_POST['editsmsflygateway'] . '`');
  127. }
  128. if ($_POST['editsmsflylogin'] != $this->settings['SMSFLY_LOGIN']) {
  129. zb_StorageSet('SENDDOG_SMSFLY_LOGIN', $_POST['editsmsflylogin']);
  130. log_register('SENDDOG CONFIG SET SMSFLYLOGIN `' . $_POST['editsmsflylogin'] . '`');
  131. }
  132. if ($_POST['editsmsflypassword'] != $this->settings['SMSFLY_PASSWORD']) {
  133. zb_StorageSet('SENDDOG_SMSFLY_PASSWORD', $_POST['editsmsflypassword']);
  134. log_register('SENDDOG CONFIG SET SMSFLYPASSWORD `' . $_POST['editsmsflypassword'] . '`');
  135. }
  136. if ($_POST['editsmsflysign'] != $this->settings['SMSFLY_SIGN']) {
  137. zb_StorageSet('SENDDOG_SMSFLY_SIGN', $_POST['editsmsflysign']);
  138. log_register('SENDDOG CONFIG SET SMSFLYSIGN `' . $_POST['editsmsflysign'] . '`');
  139. }
  140. }
  141. }