SmsFly.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. class SmsFly extends SMSServiceApi {
  3. public function __construct($smsServiceId, $smsPack = array()) {
  4. parent::__construct($smsServiceId, $smsPack);
  5. }
  6. public function getBalance() {
  7. $result = '';
  8. $myXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  9. $myXML .= "<request>";
  10. $myXML .= "<operation>GETBALANCE</operation>";
  11. $myXML .= "</request>";
  12. $ch = curl_init();
  13. curl_setopt($ch, CURLOPT_USERPWD, $this->serviceLogin . ':' . $this->servicePassword);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  15. curl_setopt($ch, CURLOPT_POST, 1);
  16. curl_setopt($ch, CURLOPT_URL, $this->serviceGatewayAddr);
  17. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Accept: text/xml"));
  18. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  19. curl_setopt($ch, CURLOPT_POSTFIELDS, $myXML);
  20. $response = curl_exec($ch);
  21. curl_close($ch);
  22. //$result.= wf_BackLink($this->sendDog->getBaseUrl(), '', true);
  23. $result.= $this->instanceSendDog->getUBMsgHelperInstance()->getStyledMessage(__('Current account balance') . ': ' . $response, 'info');
  24. //return ($result);
  25. die(wf_modalAutoForm(__('Balance'), $result, $_POST['modalWindowId'], '', true, 'false', '700'));
  26. }
  27. public function getSMSQueue() {
  28. $this->showErrorFeatureIsNotSupported();
  29. }
  30. public function pushMessages() {
  31. $result = '';
  32. $apiUrl = $this->serviceGatewayAddr;
  33. $source = $this->instanceSendDog->safeEscapeString($this->serviceAlphaName);
  34. $description = "Ubilling_" . zb_rand_string(8);
  35. $start_time = 'AUTO';
  36. $end_time = 'AUTO';
  37. $rate = 1;
  38. $lifetime = 4;
  39. $user = $this->serviceLogin;
  40. $password = $this->servicePassword;
  41. $allSmsQueue = $this->smsMessagePack;
  42. if (!empty($allSmsQueue)) {
  43. foreach ($allSmsQueue as $io => $eachsms) {
  44. $number = str_replace('+', '', $eachsms['number']); //numbers in international format without +
  45. $myXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  46. $myXML .= "<request>";
  47. $myXML .= "<operation>SENDSMS</operation>";
  48. $myXML .= ' <message start_time="' . $start_time . '" end_time="' . $end_time . '" lifetime="' . $lifetime . '" rate="' . $rate . '" desc="' . $description . '" source="' . $source . '">' . "\n";
  49. $myXML .= " <body>" . $eachsms['message'] . "</body>";
  50. $myXML .= " <recipient>" . $number . "</recipient>";
  51. $myXML .= "</message>";
  52. $myXML .= "</request>";
  53. $ch = curl_init();
  54. curl_setopt($ch, CURLOPT_USERPWD, $user . ':' . $password);
  55. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  56. curl_setopt($ch, CURLOPT_POST, 1);
  57. curl_setopt($ch, CURLOPT_URL, $apiUrl);
  58. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Accept: text/xml"));
  59. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  60. curl_setopt($ch, CURLOPT_POSTFIELDS, $myXML);
  61. $result.= curl_exec($ch);
  62. curl_close($ch);
  63. //remove old sent message
  64. $this->instanceSendDog->getSmsQueueInstance()->deleteSms($eachsms['filename']);
  65. }
  66. }
  67. }
  68. public function checkMessagesStatuses() {
  69. log_register('Checking statuses for [' . get_class($this) . '] SMS service is not implemented');
  70. }
  71. }
  72. ?>