短信网关 / 客户端
用于使用短信网关HTTP API的PHP客户端。
v1.0.1
2019-03-08 08:17 UTC
Requires
- php: >=5.6
- php-http/client-implementation: ^1.0
- php-http/guzzle6-adapter: ^1.0
- zendframework/zend-diactoros: ^1.3
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-29 20:19:55 UTC
README
此库需要至少PHP版本5.6
安装
要将PHP客户端库安装到您的项目中,我们建议使用Composer。
composer require smsgate/client
如果您是Composer的新用户,以下是一些可能有用的资源
- Composer入门页面来自Composer项目文档。
- Composer入门指南来自ScotchBox的好人们。
发送短信
//use composer's autoload require 'vendor/autoload.php'; //make sure to set the real URL for bulk gate $gate = new SMSGate\Client('https://:9000/bulk_server'); $sms = new SMSGate\SMSRequest; $sms ->setType(SMSGate\Client::TYPE_TEXT) ->setAuthUsername('test') ->setAuthPassword('test') ->setSender('Test Sender') ->setReceiver('41587000201') ->setText('Hello there!') ////make sure to set the real URL for your webhook handler ->setDlrUrl('https://:8000/dlr.php') ->setDlrMask(SMSGate\Client::DLR_MASK_STANDARD); try { $response = $gate->send($sms); } catch (\Exception $exc) { echo "Error sending SMS with code: " . $exc->getCode() . " and message: " . $exc->getMessage(); exit; } echo "SMS sent with ID: " . $response->msgId . " and num of parts: " . $response->numParts;
接收DLRs
//use composer's autoload require 'vendor/autoload.php'; $gate = new SMSGate\Client(''); $dlr = $gate->parseDeliveryReport(); if(!isset($dlr)){ error_log("Cannot parse DLR from the request"); exit; } error_log("Received DLR: " . json_encode($dlr));
检查examples
目录以获取更多详细信息。要本地运行示例,请从命令行运行
cd examples
./run_srv.sh
然后打开https://:8000/