Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf9f81de

Browse files
committed
Add Yunpian Notifier Bridge
1 parent5010ebd commitf9f81de

File tree

16 files changed

+344
-0
lines changed

16 files changed

+344
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
useSymfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
145145
useSymfony\Component\Notifier\Bridge\Telnyx\TelnyxTransportFactory;
146146
useSymfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
147+
useSymfony\Component\Notifier\Bridge\Yunpian\YunpianTransportFactory;
147148
useSymfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
148149
useSymfony\Component\Notifier\Notifier;
149150
useSymfony\Component\Notifier\Recipient\Recipient;
@@ -2453,6 +2454,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
24532454
TelegramTransportFactory::class =>'notifier.transport_factory.telegram',
24542455
TelnyxTransportFactory::class =>'notifier.transport_factory.telnyx',
24552456
TwilioTransportFactory::class =>'notifier.transport_factory.twilio',
2457+
YunpianTransportFactory::class =>'notifier.transport_factory.yunpian',
24562458
ZulipTransportFactory::class =>'notifier.transport_factory.zulip',
24572459
];
24582460

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
useSymfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
4747
useSymfony\Component\Notifier\Bridge\Telnyx\TelnyxTransportFactory;
4848
useSymfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
49+
useSymfony\Component\Notifier\Bridge\Yunpian\YunpianTransportFactory;
4950
useSymfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
5051
useSymfony\Component\Notifier\Transport\AbstractTransportFactory;
5152
useSymfony\Component\Notifier\Transport\NullTransportFactory;
@@ -204,5 +205,9 @@
204205
->set('notifier.transport_factory.mailjet', MailjetTransportFactory::class)
205206
->parent('notifier.transport_factory.abstract')
206207
->tag('texter.transport_factory')
208+
209+
->set('notifier.transport_factory.yunpian', YunpianTransportFactory::class)
210+
->parent('notifier.transport_factory.abstract')
211+
->tag('texter.transport_factory')
207212
;
208213
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/Testsexport-ignore
2+
/phpunit.xml.distexport-ignore
3+
/.gitattributesexport-ignore
4+
/.gitignoreexport-ignore
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
5.4
5+
---
6+
7+
* Add the bridge
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Yunpian Notifier
2+
===============
3+
4+
Provides[Yunpian](https://www.yunpian.com) integration for Symfony Notifier.
5+
6+
DSN example
7+
-----------
8+
9+
```
10+
YUNPIAN_DSN=yunpian://APIKEY@default
11+
```
12+
13+
where:
14+
-`APIKEY` is your Yunpian API key
15+
16+
Resources
17+
---------
18+
19+
*[Contributing](https://symfony.com/doc/current/contributing/index.html)
20+
*[Report issues](https://github.com/symfony/symfony/issues) and
21+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
22+
in the[main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Yunpian\Tests;
13+
14+
useSymfony\Component\Notifier\Bridge\Yunpian\YunpianTransportFactory;
15+
useSymfony\Component\Notifier\Test\TransportFactoryTestCase;
16+
useSymfony\Component\Notifier\Transport\TransportFactoryInterface;
17+
18+
finalclass YunpianTransportFactoryTestextends TransportFactoryTestCase
19+
{
20+
/**
21+
* @return YunpianTransportFactory
22+
*/
23+
publicfunctioncreateFactory():TransportFactoryInterface
24+
{
25+
returnnewYunpianTransportFactory();
26+
}
27+
28+
publicfunctioncreateProvider():iterable
29+
{
30+
yield [
31+
'yunpian://host.test',
32+
'yunpian://api_key@host.test',
33+
];
34+
}
35+
36+
publicfunctionsupportsProvider():iterable
37+
{
38+
yield [true,'yunpian://api_key@default'];
39+
yield [false,'somethingElse://api_key@default'];
40+
}
41+
42+
publicfunctionunsupportedSchemeProvider():iterable
43+
{
44+
yield ['somethingElse://api_key@default'];
45+
}
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Yunpian\Tests;
13+
14+
useSymfony\Component\Notifier\Bridge\Yunpian\YunpianTransport;
15+
useSymfony\Component\Notifier\Message\ChatMessage;
16+
useSymfony\Component\Notifier\Message\MessageInterface;
17+
useSymfony\Component\Notifier\Message\SmsMessage;
18+
useSymfony\Component\Notifier\Test\TransportTestCase;
19+
useSymfony\Component\Notifier\Transport\TransportInterface;
20+
useSymfony\Contracts\HttpClient\HttpClientInterface;
21+
22+
finalclass YunpianTransportTestextends TransportTestCase
23+
{
24+
/**
25+
* @return YunpianTransport
26+
*/
27+
publicfunctioncreateTransport(HttpClientInterface$client =null):TransportInterface
28+
{
29+
returnnewYunpianTransport('api_key',$client ??$this->createMock(HttpClientInterface::class));
30+
}
31+
32+
publicfunctiontoStringProvider():iterable
33+
{
34+
yield ['yunpian://sms.yunpian.com',$this->createTransport()];
35+
}
36+
37+
publicfunctionsupportedMessagesProvider():iterable
38+
{
39+
yield [newSmsMessage('+0611223344','Hello!')];
40+
}
41+
42+
publicfunctionunsupportedMessagesProvider():iterable
43+
{
44+
yield [newChatMessage('Hello!')];
45+
yield [$this->createMock(MessageInterface::class)];
46+
}
47+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Yunpian;
13+
14+
useSymfony\Component\Notifier\Exception\TransportException;
15+
useSymfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
16+
useSymfony\Component\Notifier\Message\MessageInterface;
17+
useSymfony\Component\Notifier\Message\SentMessage;
18+
useSymfony\Component\Notifier\Message\SmsMessage;
19+
useSymfony\Component\Notifier\Transport\AbstractTransport;
20+
useSymfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
useSymfony\Contracts\HttpClient\Exception\ExceptionInterface;
22+
useSymfony\Contracts\HttpClient\HttpClientInterface;
23+
24+
/**
25+
* @author Mathieu Santostefano <msantostefano@protonmail.com>
26+
*/
27+
class YunpianTransportextends AbstractTransport
28+
{
29+
protectedconstHOST ='sms.yunpian.com';
30+
31+
private$apiKey;
32+
33+
publicfunction__construct(string$apiKey,HttpClientInterface$client =null,EventDispatcherInterface$dispatcher =null)
34+
{
35+
$this->apiKey =$apiKey;
36+
37+
parent::__construct($client,$dispatcher);
38+
}
39+
40+
publicfunction__toString():string
41+
{
42+
returnsprintf('yunpian://%s',$this->getEndpoint());
43+
}
44+
45+
publicfunctionsupports(MessageInterface$message):bool
46+
{
47+
return$messageinstanceof SmsMessage;
48+
}
49+
50+
protectedfunctiondoSend(MessageInterface$message):SentMessage
51+
{
52+
if (!$messageinstanceof SmsMessage) {
53+
thrownewUnsupportedMessageTypeException(__CLASS__, SmsMessage::class,$message);
54+
}
55+
56+
$endpoint =sprintf('https://%s/v2/sms/single_send.json',self::HOST);
57+
$response =$this->client->request('POST',$endpoint, [
58+
'body' => [
59+
'apikey' =>$this->apiKey,
60+
'mobile' =>$message->getPhone(),
61+
'text' =>$message->getSubject(),
62+
],
63+
]);
64+
65+
try {
66+
$data =$response->toArray(false);
67+
}catch (ExceptionInterface$exception) {
68+
thrownewTransportException('Unable to send the SMS.',$response);
69+
}
70+
71+
if (isset($data['code']) &&0 !== (int)$data['code']) {
72+
thrownewTransportException(sprintf('Unable to send SMS: "Code: "%s". Message: "%s"".',$data['code'],$data['msg'] ??'Unknown reason'),$response);
73+
}
74+
75+
returnnewSentMessage($message, (string)$this);
76+
}
77+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp