jbbx2016 / sms-gateway
与 Eurobate 交互的 SMS 网关
1.5.5
2018-06-07 16:29 UTC
Requires
- php: ^5.4 | ^7.0
- ext-iconv: *
- giggsey/libphonenumber-for-php: ^8.3.3
- guzzlehttp/guzzle: ^6.0
- twilio/sdk: ^5.9
README
使用 Eurobate 网关发送 SMS 的库
使用 Composer 安装
composer require jbbx2016/sms-gateway
基本用法
<?php
use JBBx2016\SMSGateway\Common\CountryCodes;
use JBBx2016\SMSGateway\Common\Exceptions\Exception;
use JBBx2016\SMSGateway\Common\PhoneNumber;
use JBBx2016\SMSGateway\Gateways\Eurobate\EurobateSendMessageResponse;
use JBBx2016\SMSGateway\Gateways\Eurobate\EurobateGateway;
use JBBx2016\SMSGateway\Payloads\SMSPayload;
use JBBx2016\SMSGateway\Senders\TextSender;
use JBBx2016\SMSGateway\SMSGatewayApi;
$SMSGatewayApi = new SMSGatewayApi();
$SMSGatewayApi->AddGateway(new EurobateGateway('username', 'password'));
try {
/** @var EurobateSendMessageResponse $Response */
$Response = $SMSGatewayApi->SendMessage(
new TextSender('Avsender'),
new SMSPayload(
new PhoneNumber(CountryCodes::Norway, '98765432'),
"This is the message body"
)
);
$EurobateId = $Response->Id;
} catch (Exception $Exception) {
$this->_Logger->Error('Failed to process SMS - Exception: ' . get_class($Exception) . "(" . $Exception->getMessage() . ")");
}
从号码发送 SMS
<?php
use JBBx2016\SMSGateway\Common\CountryCodes;
use JBBx2016\SMSGateway\Common\PhoneNumber;
use JBBx2016\SMSGateway\Payloads\SMSPayload;
use JBBx2016\SMSGateway\Senders\NumberSender;
$SMSGatewayApi->SendMessage(
new NumberSender('203098765432'),
new SMSPayload(
new PhoneNumber(CountryCodes::Norway, '98765432'),
"This is the message body"
)
);
Eurobate:指定投递报告端点
<?php
use JBBx2016\SMSGateway\Gateways\Eurobate\EurobateGateway;
use JBBx2016\SMSGateway\SMSGatewayApi;
$EurobateGateway = new EurobateGateway('username', 'password');
$EurobateGateway->SetDeliveryReportStatusEndpoint('http:// myhost.com/dlr.php?msgid=MSGID&status=STATUS&operator=OPERATOR&smscode=OPCODE&cbgcode=CBGCODE&stop=STOP');
$SMSGatewayApi = new SMSGatewayApi();
$SMSGatewayApi->AddGateway($EurobateGateway);
异常
JBBx2016\SMSGateway\Common\Exceptions\Exception
:基本异常JBBx2016\SMSGateway\Common\Exceptions\GatewayEndpointConnectionFailedException
:连接到网关端点失败JBBx2016\SMSGateway\Common\Exceptions\GatewayAuthorizationException
:网关授权失败JBBx2016\SMSGateway\Common\Exceptions\NoGatewayFoundException
:如果未找到合适的网关则调用JBBx2016\SMSGateway\Gateways\Eurobate\EurobateException
:Eurobate 网关的异常JBBx2016\SMSGateway\Gateways\Eurobate\Exceptions\IPNotAuthorizedEurobateException
:Eurobate 特定错误