1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is a part of the Yoqut package. |
5
|
|
|
* |
6
|
|
|
* (c) Sukhrob Khakimov <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that is distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Yoqut\Component\Sms\Sender; |
13
|
|
|
|
14
|
|
|
use Yoqut\Component\Sms\Model\SmsInterface; |
15
|
|
|
use Yoqut\Component\Sms\Model\GatewayInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The default sender implementation |
19
|
|
|
* |
20
|
|
|
* @author Sukhrob Khakimov <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Sender implements SenderInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
*/ |
27
|
|
|
public function send(SmsInterface $sms, GatewayInterface $gateway) |
28
|
|
|
{ |
29
|
|
|
// Get the gateway configurations |
30
|
|
|
$configs = $gateway->getConfigs(); |
31
|
|
|
|
32
|
|
|
// Create a new socket transport |
33
|
|
|
$transport = new \SocketTransport( |
34
|
|
|
array($gateway->getHost()), |
35
|
|
|
$gateway->getPort(), |
36
|
|
|
$configs['persistent'] |
37
|
|
|
); |
38
|
|
|
$transport->setSendTimeout($configs['send_timeout']); |
39
|
|
|
$transport->setRecvTimeout($configs['receive_timeout']); |
40
|
|
|
$transport->debug = $configs['debug']; |
41
|
|
|
|
42
|
|
|
// Create a new SMPP client |
43
|
|
|
$smpp = new \SmppClient($transport); |
44
|
|
|
$smpp->debug = $configs['debug']; |
45
|
|
|
|
46
|
|
|
// Open the connection |
47
|
|
|
$transport->open(); |
48
|
|
|
$smpp->bindTransmitter($gateway->getUsername(), $gateway->getPassword()); |
49
|
|
|
|
50
|
|
|
// Configure a sender, recipient and message |
51
|
|
|
$sender = new \SmppAddress( |
52
|
|
|
$sms->getSender(), |
53
|
|
|
$configs['sender']['ton'], |
54
|
|
|
$configs['sender']['npi'] |
55
|
|
|
); |
56
|
|
|
$recipient = new \SmppAddress( |
57
|
|
|
$sms->getRecipient(), |
58
|
|
|
$configs['recipient']['ton'], |
59
|
|
|
$configs['recipient']['npi'] |
60
|
|
|
); |
61
|
|
|
$message = \GsmEncoder::utf8_to_gsm0338($sms->getMessage()); |
62
|
|
|
|
63
|
|
|
// Send an SMS and close the connection |
64
|
|
|
$messageId = $smpp->sendSMS($sender, $recipient, $message); |
65
|
|
|
$smpp->close(); |
66
|
|
|
|
67
|
|
|
return $messageId; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|