RedSms.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. class RedSms extends SMSServiceApi {
  3. public function __construct($smsServiceId, $smsPack = array()) {
  4. parent::__construct($smsServiceId, $smsPack);
  5. }
  6. public function getBalance() {
  7. $result = '';
  8. $timestamp = microtime() . rand(0, 10000);
  9. $api_key = $this->serviceApiKey;
  10. $login = $this->serviceLogin;
  11. $signature = md5($timestamp . $api_key);
  12. $query = $this->serviceGatewayAddr . "/client/info?login=" . $login . "&secret=" . $signature . "&ts=" . $timestamp;
  13. $curl = curl_init();
  14. curl_setopt($curl, CURLOPT_URL, $query);
  15. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  16. curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  17. $response = curl_exec($curl);
  18. $response = json_decode($response);
  19. curl_close($curl);
  20. if (empty($response->{"error_message"})) {
  21. $ballance = __('Current account balance') . ': ' . $response->{"info"}->{"balance"} . ' RUR';
  22. $msgType = 'info';
  23. } else {
  24. $ballance = $response->{"error_message"};
  25. $msgType = 'warning';
  26. }
  27. //$result.= wf_BackLink(self::URL_ME, '', true);
  28. $result.= $this->instanceSendDog->getUBMsgHelperInstance()->getStyledMessage($ballance, $msgType);
  29. //return ($result);
  30. die(wf_modalAutoForm(__('Balance'), $result, $_POST['modalWindowId'], '', true, 'false', '700'));
  31. }
  32. public function getSMSQueue() {
  33. $this->showErrorFeatureIsNotSupported();
  34. }
  35. public function pushMessages() {
  36. $result = '';
  37. $timestamp = microtime().rand(0, 10000);
  38. $api_key = $this->serviceApiKey;
  39. $login = $this->serviceLogin;
  40. $sender = $this->serviceAlphaName;
  41. $allSmsQueue = $this->smsMessagePack;
  42. if (!empty($allSmsQueue)) {
  43. foreach ($allSmsQueue as $io => $eachsms) {
  44. $phone = $eachsms['number'];
  45. $text = $eachsms['message'];
  46. $signature = md5($timestamp . $api_key);
  47. $data = array(
  48. 'login' => $login,
  49. 'secret' => $signature,
  50. 'to' => $phone,
  51. 'from' => $sender,
  52. 'ts' => $timestamp,
  53. 'text' => $text
  54. );
  55. $postdata = http_build_query($data);
  56. $query = $this->serviceGatewayAddr . "/message?" . $postdata;
  57. $curl = curl_init();
  58. curl_setopt($curl, CURLOPT_URL, $query);
  59. curl_setopt($curl, CURLOPT_ENCODING, "utf-8");
  60. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 120);
  61. curl_setopt($curl, CURLOPT_TIMEOUT, 120);
  62. curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
  63. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  64. curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  65. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  66. curl_setopt($curl, CURLOPT_POST, true);
  67. $response = curl_exec($curl);
  68. curl_close($curl);
  69. //remove old sent message
  70. $this->instanceSendDog->getSmsQueueInstance()->deleteSms($eachsms['filename']);
  71. }
  72. }
  73. }
  74. public function checkMessagesStatuses() {
  75. log_register('Checking statuses for [' . get_class($this) . '] SMS service is not implemented');
  76. }
  77. }
  78. ?>