Blame view

common/components/SmsSender.php 2.23 KB
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
1
2
3
4
5
  <?php
  namespace common\components;
  
  use Yii;
  use yii\base\Component;
f95ceccd   Dmytry Fedorchuk   component config add
6
  use yii\base\InvalidConfigException;
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
7
8
9
10
11
12
13
  
  class SmsSender extends Component
  {
  
      public $tel;
      public $text;
  
4e7e60a6   Dmytry Fedorchuk   SmsSender Component
14
      public function send($tel, $text)
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
15
16
      {
  
4e7e60a6   Dmytry Fedorchuk   SmsSender Component
17
18
          $text = iconv('windows-1251', 'utf-8', htmlspecialchars($text));
          $description = iconv('windows-1251', 'utf-8', htmlspecialchars($tel . ' description'));
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
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
48
          $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
49
          return $response;
c5eb77e5   Dmytry Fedorchuk   SmsSender Compone...
50
51
      }
  }