bingher / ali-sms
send aliyun sms
Installs: 1 872
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- alibabacloud/client: ^1.5
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
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]);