short-messenger
PHP 短信组件包,支持阿里云短信和 SendCloud 短信。
Requirements
short-messenger
依赖于以下工具包或环境
Installation
使用 composer 安装依赖包
composer require hyancat/short-messenger
Usage
Generally
配置
$config = [ 'default' => 'aliyun', 'providers' => [ 'aliyun' => [ 'region' => 'cn-hangzhou', 'access_id' => 'xxx', 'access_key' => 'yyy', ], 'sendcloud' => [ 'sms_user' => 'xxx', 'sms_key' => 'yyy', ], ], ];
代码示例
// 配置驱动 $manager = new SmsManager(); $manager->config($config); $manager->extend('aliyun', function () use ($config) { return new AliyunProvider($config['providers']['aliyun']); }); $manager->extend('sendcloud', function () use ($config) { return new SendCloudProvider($config['providers']['sendcloud']); }); // 创建 Service $smsService = new SmsService($manager); $smsService->send('186xxx', function (ShortMessage $message) { $message->template('template_123') ->signature('SIGNATURE_xx') ->data(['code' => 1234]); });
Laravel or Lumen
添加 ServiceProvider
HyanCatShortMessengerSmsServiceProvider::class
配置 sms.php
[ 'default' => 'aliyun', 'providers' => [ 'aliyun' => [ 'region' => 'cn-hangzhou', 'access_id' => env('ALIYUN_SMS_ACCESS_ID', ''), 'access_key' => env('ALIYUN_SMS_ACCESS_KEY', ''), ], 'sendcloud' => [ 'sms_user' => env('SENDCLOUD_SMS_USER', ''), 'sms_key' => env('SENDCLOUD_SMS_KEY', ''), ], ] ]
在 Laravel 框架下可以使用 artisan 命令创建:
php artisan vendor:publish --provider=HyanCatShortMessengerSmsServiceProvider
代码示例
use HyanCatShortMessengerSmsServiceFacade as SMS; SMS::send('18688888888', function (ShortMessage $message) { $message->template('template_123') ->signature('SIGNATURE_xx') ->data(['code' => 1234]); });
License
The MIT License (MIT)
Copyright (c) 2017 HyanCat <hyancat@live.cn>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。