· 7 years ago · Aug 02, 2018, 06:44 PM
1<?php
2
3namespace SmsaeroApiV2;
4
5 class SmsaeroApiV2
6 {
7 const URL_SMSAERO_API = 'https://gate.smsaero.ru/v2';
8 private $email = 'yandex.ru'; //Ваш логин|email
9 private $api_key = 'F6ebpkmkOYcIsA';
10 private $sign = 'name'; //ПодпиÑÑŒ по умолчанию
11
12 public function __construct($email, $api_key, $sign = false){
13 $this->email = $email;
14 $this->api_key = $api_key;
15 if ($sign) {
16 $this->sign = $sign;
17 }
18 }
19
20
21 private function curl_post($url, array $post = NULL, array $options = array()){
22 $defaults = array(
23 CURLOPT_POST => 1,
24 CURLOPT_HEADER => 0,
25 CURLOPT_URL => $url,
26 CURLOPT_FRESH_CONNECT => 1,
27 CURLOPT_RETURNTRANSFER => 1,
28 CURLOPT_FORBID_REUSE => 1,
29 CURLOPT_TIMEOUT => 10,
30 CURLOPT_POSTFIELDS => http_build_query($post),
31 CURLOPT_SSL_VERIFYPEER => 0,
32 CURLOPT_SSL_VERIFYHOST => 0,
33 CURLOPT_USERPWD => $this->email . ":" . $this->api_key,
34 CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
35 );
36
37 $ch = curl_init();
38 curl_setopt_array($ch, ($options + $defaults));
39 if (!$result = curl_exec($ch)) {
40 return curl_error($ch);
41 }
42 curl_close($ch);
43 return $result;
44 }
45 public function send($number, $text, $channel, $dateSend = null, $callbackUrl = null){
46 return json_decode(self::curl_post(self::URL_SMSAERO_API . '/sms/send/', [
47 is_array($number) ? 'numbers' : 'number' => $number,
48 'sign' => $this->sign,
49 'text' => $text,
50 'channel' => $channel,
51 'dateSend' => $dateSend,
52 'callbackUrl' => $callbackUrl
53 ]), true);
54 }
55}
56
57?>
58
59<div class="form-group">
60 <input type="text" class="form-control" id="number" name="number" placeholder="Введите телефон">
61 </div>
62 <div class="form-group">
63 <input type="text" class="form-control" id="text" name="text" placeholder="текÑÑ‚">
64 </div>
65
66
67 <button type="submit" class="btn">Отправить форму</button>
68 </form>