* sender changed to from

This commit is contained in:
Vasilij Dusko | CREATION 2021-03-29 17:49:52 +03:00
parent e20ef1ed35
commit 7f13dbf711
3 changed files with 15 additions and 18 deletions

View File

@ -26,7 +26,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
*/
final class LightSmsTransport extends AbstractTransport
{
protected const HOST = 'www.lightsms.com';
protected const HOST = 'lightsms.com';
private $login;
private $password;
@ -75,11 +75,11 @@ final class LightSmsTransport extends AbstractTransport
'39' => 'Phone number does not exist in this database',
];
public function __construct(string $login, string $password, string $phone, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
public function __construct(string $login, string $password, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
$this->login = $login;
$this->password = $password;
$this->phone = $phone;
$this->from = $from;
parent::__construct($client, $dispatcher);
}
@ -102,19 +102,16 @@ final class LightSmsTransport extends AbstractTransport
$timestamp = time();
$signature = $this->generateSignature([
'message' => $message,
'timestamp' => $timestamp,
]);
$signature = $this->generateSignature($message, $timestamp);
$endpoint = sprintf(
'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s&timestamp=%s',
'https://www.%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s&timestamp=%s',
$this->getEndpoint(),
$this->login,
$signature,
$this->escapePhoneNumber($message->getPhone()),
$this->escapeSubject($message->getSubject()),
$this->phone,
$this->from,
$timestamp
);
@ -143,14 +140,14 @@ final class LightSmsTransport extends AbstractTransport
return $sentMessage;
}
private function generateSignature(array $params): string
private function generateSignature(SmsMessage $message, string $timestamp): string
{
$params = [
'timestamp' => $params['timestamp'],
'timestamp' => $timestamp,
'login' => $this->login,
'phone' => $this->escapePhoneNumber($params['message']->getPhone()),
'sender' => $this->phone,
'text' => $this->escapeSubject($params['message']->getSubject()),
'phone' => $this->escapePhoneNumber($message->getPhone()),
'sender' => $this->from,
'text' => $this->escapeSubject($message->getSubject()),
];
ksort($params);

View File

@ -34,12 +34,12 @@ final class LightSmsTransportFactory extends AbstractTransportFactory
$login = $this->getUser($dsn);
$token = $this->getPassword($dsn);
$phone = $dsn->getRequiredOption('phone');
$from = $dsn->getRequiredOption('from');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();
return (new LightSmsTransport($login, $token, $phone, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
return (new LightSmsTransport($login, $token, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
}
protected function getSupportedSchemes(): array

View File

@ -41,7 +41,7 @@ final class LightSmsTransportFactoryTest extends TransportFactoryTestCase
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://accountSid:authToken@default?phone=37061234567'];
yield ['somethingElse://accountSid:authToken@default']; // missing "phone" option
yield ['somethingElse://login:token@default?phone=37061234567'];
yield ['somethingElse://login:token@default']; // missing "phone" option
}
}