procergs / sms-service
此软件包最新版本(3.0.0)没有可用的许可证信息。
PROCERGS SMS 服务
3.0.0
2018-05-25 20:39 UTC
Requires
- php: >=5.4.16
- ci/restclientbundle: ^2.0
- giggsey/libphonenumber-for-php: ~8.0
- psr/log: ^1.0
- symfony/http-foundation: >=2.8
- symfony/http-kernel: >=2.8
Requires (Dev)
- guilhermednt/minimum-coverage-checker: >=1.0.3
- phpunit/phpunit: ^4.8
README
仅限内部使用。如果您不在 PROCERGS 或其软件中工作,这肯定对您没有帮助。
安装
重要:目前此库依赖于 RestClientBundle,因此您需要将其加载到 Symfony 中。一旦 PROCERGS 更新其 PHP 服务器,我们将将其更改为 Guzzle 6 HTTP 客户端。
运行以下命令以添加 composer 依赖项并安装
composer require procergs/sms-service
如果您正在使用 Symfony,请在您的 AppKernel.php
中启用 RestClientBundle
public function registerBundles() { $bundles = array( // ... new Circle\RestClientBundle\CircleRestClientBundle(), ); }
或者直接初始化它
require_once 'vendor/autoload.php'; $optionsHandler = new \Circle\RestClientBundle\Services\CurlOptionsHandler([]); $curl = new \Circle\RestClientBundle\Services\Curl($optionsHandler); $client = new \Circle\RestClientBundle\Services\RestClient($curl);
用法
您可以使用以下代码发送消息
require_once 'vendor/autoload.php'; use libphonenumber\PhoneNumber; use PROCERGS\Sms\SmsService; use PROCERGS\Sms\Model\SmsServiceConfiguration; $client = /* initialize or get HTTP client from Symfony */; $config = new SmsServiceConfiguration( 'https://some.address/send', 'https://some.address/receive', 'https://some.address/status/{id}', 'auth realm', 'SystemID', 'your_secret_key', true ); $service = new SmsService($client, $config); $to = new PhoneNumber(); $to->setCountryCode('55') ->setNationalNumber('51987654321'); try { $response = $service->easySend($to, "hello world!"); var_dump($response); } catch (\Exception $e) { var_dump($e->getMessage()); }