Skip to content

Commit 951c860

Browse files
dev
1 parent a39194b commit 951c860

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed

composer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "skeeks/cms-smsru-handler",
3+
"description": "Sms провайдер SkeekS CMS",
4+
"keywords": ["yii", "skeeks", "framework", "component", "dadata", "suggest"],
5+
"homepage": "https://cms.skeeks.com/",
6+
"type": "yii2-extension",
7+
"license": "BSD-3-Clause",
8+
"support": {
9+
"issues": "https://skeeks.com/"
10+
},
11+
"authors": [
12+
{
13+
"name": "Semenov Alexander",
14+
"email": "semenov@skeeks.com"
15+
}
16+
],
17+
"require": {
18+
"skeeks/cms": "^5.0 || dev-master"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"skeeks\\cms\\sms\\smsru\\": "src/"
23+
}
24+
},
25+
"extra": {
26+
"config-plugin": {
27+
"web": [
28+
"src/config/common.php",
29+
"src/config/web.php"
30+
],
31+
"console": [
32+
"src/config/common.php",
33+
"src/config/console.php"
34+
]
35+
}
36+
}
37+
}

src/SmsruHandler.php

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
/**
3+
* @link https://cms.skeeks.com/
4+
* @copyright Copyright (c) 2010 SkeekS
5+
* @license https://cms.skeeks.com/license/
6+
* @author Semenov Alexander <semenov@skeeks.com>
7+
*/
8+
9+
namespace skeeks\cms\sms\smsru;
10+
11+
use skeeks\cms\sms\SmsHandler;
12+
use skeeks\yii2\form\fields\FieldSet;
13+
use yii\base\Exception;
14+
use yii\helpers\ArrayHelper;
15+
use yii\httpclient\Client;
16+
17+
/**
18+
*
19+
* @see https://smsimple.ru/api-http/
20+
*
21+
* @author Semenov Alexander <semenov@skeeks.com>
22+
*/
23+
class SmsruHandler extends SmsHandler
24+
{
25+
public $api_key = "";
26+
public $sender = "";
27+
28+
/**
29+
* @return array
30+
*/
31+
static public function descriptorConfig()
32+
{
33+
return array_merge(parent::descriptorConfig(), [
34+
'name' => \Yii::t('skeeks/shop/app', 'sms.ru'),
35+
]);
36+
}
37+
38+
39+
public function rules()
40+
{
41+
return ArrayHelper::merge(parent::rules(), [
42+
[['api_key'], 'required'],
43+
[['api_key'], 'string'],
44+
[['sender'], 'string'],
45+
]);
46+
}
47+
48+
public function attributeLabels()
49+
{
50+
return ArrayHelper::merge(parent::attributeLabels(), [
51+
'api_key' => "API ключ",
52+
'sender' => "Отправитель",
53+
54+
]);
55+
}
56+
57+
public function attributeHints()
58+
{
59+
return ArrayHelper::merge(parent::attributeHints(), [
60+
61+
]);
62+
}
63+
64+
65+
/**
66+
* @return array
67+
*/
68+
public function getConfigFormFields()
69+
{
70+
return [
71+
'main' => [
72+
'class' => FieldSet::class,
73+
'name' => 'Основные',
74+
'fields' => [
75+
'api_key',
76+
'sender',
77+
],
78+
],
79+
];
80+
}
81+
82+
83+
/**
84+
* @see https://smsimple.ru/api-http/
85+
*
86+
* @param $phone
87+
* @param $text
88+
* @param null $sender
89+
* @return $message_id
90+
*/
91+
public function send($phone, $text, $sender = null)
92+
{
93+
$queryString = http_build_query([
94+
'user' => $this->login,
95+
'pass' => $this->password,
96+
'or_id' => $this->sender,
97+
'phone' => $phone,
98+
'message' => $text,
99+
]);
100+
101+
$url = 'https://smsimple.ru/http_send.php?'.$queryString;
102+
103+
104+
$stream_opts = [
105+
"ssl" => [
106+
"verify_peer" => false,
107+
"verify_peer_name" => false,
108+
],
109+
];
110+
111+
print_r($url);
112+
die;
113+
$response = file_get_contents($url, false, stream_context_create($stream_opts));
114+
return $response;
115+
116+
$client = new Client();
117+
$response = $client->createRequest()
118+
->setMethod('GET')
119+
->setUrl($url)
120+
->setOptions([
121+
"ssl" => [
122+
"verify_peer" => false,
123+
"verify_peer_name" => false,
124+
],
125+
])
126+
->send();
127+
128+
if (!$response->isOk) {
129+
throw new Exception($response->content);
130+
}
131+
132+
return $response->content;
133+
}
134+
135+
/**
136+
* @param $message_id
137+
* @return mixed
138+
*/
139+
public function status($message_id)
140+
{
141+
142+
}
143+
}

src/config/config/common.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
return [
3+
'components' => [
4+
'cms' => [
5+
'smsHandlers' => [
6+
\skeeks\cms\sms\smsru\SmsruHandler::class
7+
]
8+
],
9+
],
10+
];

src/config/config/console.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
return [];

src/config/config/web.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
return [];

0 commit comments

Comments
 (0)