bingher/ali-sms
Composer 安装命令:
composer require bingher/ali-sms
包简介
send aliyun sms
README 文档
README
php plugin for aliyun sms,only send sms
install
composer require bingher/ali-sms
use
use bingher\sms\AliSms;
$config = [
'version' => '2017-05-25',
'host' => 'dysmsapi.aliyuncs.com',
'scheme' => 'http',
'region_id' => 'cn-hangzhou',
'access_key' => 'your aliyun accessKeyId',
'access_secret' => 'your aliyun accessSecret',
'product' => '海迈电子档案平台',
'actions' => [
'register' => [
'sign_name' => '注册验证',
'template_code' => 'SMS_67105498',
'template_param' => [
'code' => '',
'product' => '',
]
],
'login' => [
'sign_name' => '登录验证',
'template_code' => 'SMS_67105500',
'template_param' => [
'code' => '',
'product' => '',
]
],
'change_password' => [
'sign_name' => '变更验证',
'template_code' => 'SMS_67105496',
'template_param' => [
'code' => '',
'product' => '',
]
],
],
];
$sms = new AliSms($config);
//注册验证
$sms->register('18759201xxx',['code'=>123456]);
//或者
$sms->register('18759201xxx',['code'=>123456,'product'=>'xxx平台']);
//传参中请根据actions中不同动作的template_param的值设置,如果不传product默认取配置的product值
//登录验证
$sms->login('18759201xxx',['code'=>123456]);
//或者
$sms->login('18759201xxx',['code'=>123456,'product'=>'xxx平台']);
//修改密码
$sms->change_password('18759201xxx',['code'=>123456]);
//或者
$sms->changePassword('18759201xxx',['code'=>123456,'product'=>'xxx平台']);
//AliSms中的短信方法可以根据actions配置自动匹配,如上配置有三个方法分别是:register,login,change_password,用户可以根据自己的业务需求增加其他配置
config remark
| 配置 | 类型 | 默认 | 必须配置 | 说明 |
|---|---|---|---|---|
| version | string | 2017-05-25 |
N | 日期格式,阿里云短信 sdk 版本 |
| host | string | dysmsapi.aliyuncs.com |
N | 阿里云短信服务器域名 |
| scheme | string | http | N | 请求协议,https/http |
| region_id | string | cn-hangzhou |
Y | 阿里云短信服务器所在地区,请从阿里云短信服务获取 |
| access_key | string | Y | 你的阿里云 accessKeyId | |
| access_secret | string | Y | 你的阿里云 accessSecret | |
| product | string | Y | 你的平台产品名称,actions 中 template_param 参数 product 用的默认值 | |
| actions | array | Y | 操作配置,不同动作的配置数组,格式为动作名=>配置项数组,动作名请用全小写下划线格式,如:change_password,如此调用时可以访问$sms->change_password(...);亦可$sms->changePassword(...);,配置项内容请参考阿里云短信模板 |
for thinkphp6
step1 新增配置文件 config/ali_sms.php
<?php
return [
'version' => '2017-05-25',
'host' => 'dysmsapi.aliyuncs.com',
'scheme' => 'http',
'region_id' => 'cn-hangzhou',
'access_key' => '',
'access_secret' => '',
'product' => '海迈电子档案平台',
'actions' => [
'register' => [
'sign_name' => '注册验证',
'template_code' => 'SMS_67105498',
'template_param' => [
'code' => '',
'product' => '',
]
],
'login' => [
'sign_name' => '登录验证',
'template_code' => 'SMS_67105500',
'template_param' => [
'code' => '',
'product' => '',
]
],
'change_password' => [
'sign_name' => '变更验证',
'template_code' => 'SMS_67105496',
'template_param' => [
'code' => '',
'product' => '',
]
],
],
];
step2 使用
example 1
use bingher\sms\ThinkAliSms;
$sms = new ThinkAliSms;
$sms->login('18759201xxx',['code'=>123456]);
//动态配置
$config = [...];
$sms = new ThinkAliSms($config);
$sms->login('18759201xxx',['code'=>123456]);
example 2
use bingher\sms\facade\ThinkAliSms;
ThinkAliSms::login('18759201xxx',['code'=>123456]);
bingher/ali-sms 适用场景与选型建议
bingher/ali-sms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.24k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2019 年 10 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bingher/ali-sms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bingher/ali-sms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-10-17