Blame view

components/SmsSender.php 2.19 KB
01799a55   Yarik   first commit
1
  <?php
d0c66642   Yarik   Namespaces
2
  namespace artweb\artbox\components;
01799a55   Yarik   first commit
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  
  use yii\base\Component;
  
  class SmsSender extends Component
  {
  
      public $tel;
      public $text;
  
      public function send($tel, $text)
      {
  
         // $text = iconv('windows-1251', 'utf-8', htmlspecialchars($text));
          $description = iconv('windows-1251', 'utf-8', htmlspecialchars($tel . ' description'));
          $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 часа
  
70372c90   Alexey Boroda   -Order module alm...
22
          $source = 'extremstyle'; // Alfaname
01799a55   Yarik   first commit
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
49
          $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);
  
          return $response;
      }
  }