Blame view

common/components/SmsSender.php 2.19 KB
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
1
2
3
4
5
  <?php
  namespace common\components;
  
  use Yii;
  use yii\base\Component;
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
6
7
8
9
10
11
12
  
  class SmsSender extends Component
  {
  
      public $tel;
      public $text;
  
4e7e60a6   Dmytry Fedorchuk   SmsSender Component
13
      public function send($tel, $text)
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
14
15
      {
  
4e7e60a6   Dmytry Fedorchuk   SmsSender Component
16
17
          $text = iconv('windows-1251', 'utf-8', htmlspecialchars($text));
          $description = iconv('windows-1251', 'utf-8', htmlspecialchars($tel . ' description'));
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
          $start_time = 'AUTO'; // отправить немедленно или ставим дату и время  в формате YYYY-MM-DD HH:MM:SS
          $end_time = 'AUTO'; // автоматически рассчитать системой или ставим дату и время  в формате YYYY-MM-DD HH:MM:SS
          $rate = 1; // скорость отправки сообщений (1 = 1 смс минута). Одиночные СМС сообщения отправляются всегда с максимальной скоростью.
          $lifetime = 4; // срок жизни сообщения 4 часа
  
          $source = 'extremstyle'; // Alfaname
          $recipient = $tel;
          $user = '380674064008';
          $password = 'smsartweb2012';
  
          $myXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
          $myXML .= "<request>";
          $myXML .= "<operation>SENDSMS</operation>";
          $myXML .= '		<message start_time="' . $start_time . '" end_time="' . $end_time . '" lifetime="' . $lifetime . '" rate="' . $rate . '" desc="' . $description . '" source="' . $source . '">' . "\n";
          $myXML .= "		<body>" . $text . "</body>";
          $myXML .= "		<recipient>" . $recipient . "</recipient>";
          $myXML .= "</message>";
          $myXML .= "</request>";
  
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_USERPWD, $user . ':' . $password);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_URL, 'http://sms-fly.com/api/api.php');
          curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Accept: text/xml"));
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $myXML);
          $response = curl_exec($ch);
          curl_close($ch);
  
4e7e60a6   Dmytry Fedorchuk   SmsSender Component
48
          return $response;
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
49
50
      }
  }