moocky/aliyunsms
Composer 安装命令:
composer require moocky/aliyunsms
包简介
基于alibabacloud/dysmsapi-20170525 接入短信服务
README 文档
README
基于阿里云 SDK alibabacloud/dysmsapi-20170525 接入短信服务
安装
composer require moocky/aliyunsms
基于laravel框架的使用方法
加载
在config/app的providers中添加 Moocky\Aliyunsms\Providers\LaravelServiceProvider::class
控制台运行
php artisan vendor:publish --provider=Moocky\Aliyunsms\Providers\LaravelServiceProvider
配置
根据新增的aliyunsms.php 文件,在.env文件中添加环境变量:
ALIYUN_ACCESS_KEY_ID=your access key ALIYUN_ACCESS_KEY_SECRET=your access secret ALIYUN_DYSMS_ENDPOINT=endpoint # 短信发送节点,没有配置时为dysmsapi.aliyuncs.com ALIYUN_DYSMS_SIGN_NAME=your sign name # 短信签名,必须配置 ALIYUN_DYSMS_VERIFICATION_TEMPLATE=verification template code # 验证码模板代码,不发送验证可不配置 ALIYUN_DYSMS_SMS_LOG_TABLE=sms_log # 短信日志表名称
创建短信日志表
php artisan aliyunsms:table
php artisan migrate:install # 或 php artisan migrate
使用
namespace App\Http\Controllers; use Moocky\Aliyunsms\Contracts\Aliyunsms; .... class IndexController extends Controller { /** * Show the application dashboard. * * @param \Moocky\Aliyunsms\Contracts\Aliyunsms $aliyunsms 注入 */ public function index(Aliyunsms $aliyunsms) { # 发送普通短信 # # $phone 手机号 # $templateCode 短信模板 # $templateParam 短信参数 # $type 短信类型,默认为normal $aliyunsms->send('13888888888','SMS_112233445566',['rand' => 123456],'normal'); $aliyunsms->send('13888888888','SMS_556677889900'); } public function send() { # 发送普通短信 # # $phone 手机号 # $templateCode 短信模板 # $templateParam 短信参数 # $type 短信类型,默认为normal app('aliyunsms')->send('13888888888','SMS_112233445566',['rand' => 123456],'normal'); app('aliyunsms')->send('13888888888','SMS_556677889900'); } public function verification() { # 发送验证码 # # $phone 手机号 # $type 验证码类型,默认为verification app('aliyunsms')->verification('13888888888','verification'); app('aliyunsms')->verification('13888888888'); } public function verify() { # 校验验证码 # # $phone 手机号 # $rand 验证码 # $type 验证码类型,默认为verification # $expires 验证码有效时间,默认为600秒 app('aliyunsms')->verify('13888888888','123456','verification',1200); app('aliyunsms')->verify('13888888888','123456'); } }
非laravel框架的使用方法
use Moocky\Aliyunsms\Aliyunsms; $config = [ 'access_key_id' => 'your access key', 'access_key_secret' => 'your access secret', 'sign_name' => 'your sign name', 'endpoint' => 'endpoint', 'template_code' => 'SMS_112233445566', 'sms_log_table' => 'sms_log', ]; # 发送普通短信 # # $phone 手机号 # $templateCode 短信模板 # $templateParam 短信参数 # $type 短信类型,默认为normal $aliyunsms = new Aliyunsms($config); $aliyunsms->send('13888888888','SMS_112233445566',['rand' => 123456],'normal'); $aliyunsms->send('13888888888','SMS_556677889900'); # 发送验证码 # # $phone 手机号 # $type 验证码类型,默认为verification $aliyunsms = new Aliyunsms($config); $aliyunsms->verification('13888888888','verification'); $aliyunsms->verification('13888888888'); # 校验验证码 # # $phone 手机号 # $rand 验证码 # $type 验证码类型,默认为verification # $expires 验证码有效时间,默认为600秒 $aliyunsms = new Aliyunsms($config); $aliyunsms->verify('13888888888','123456','verification',1200); $aliyunsms->verify('13888888888','123456');
moocky/aliyunsms 适用场景与选型建议
moocky/aliyunsms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sms」 「laravel」 「lumen」 「AliyunSMS」 「alibabacloud」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moocky/aliyunsms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moocky/aliyunsms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moocky/aliyunsms 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
Alfabank REST API integration
A fork of simplesoftwareio/simple-sms with Verimor driver.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-14