1.安装
composer require hyperbolaa/alisms dev-master
2.laravel配置
'providers' => [
// ...
Hyperbolaa\Alisms\AlismsServiceProvider::class,
]
3.运行 `php artisan vendor:publish` 命令,
发布配置文件到你的项目中。
4.app配置
$alisms = app('alisms.yun'); //$alisms = app('alisms.api'); //$alisms = app('alisms.note'); $flag = $alisms->send('register','15588888888',['code'=>$code,'product'=>'手机号']);//code 为模板中的变量名
或者
$flag = $alisms->send('register',$data['phone'],['code'=>$code]); 此处根据短信模板配置 来调整 if($flag === true){ //todo 发送成功处理 }
5.(alisms.yun不行的话 就换成alisms.note)
//在最外面的config/alisms.php中修改配置
'note'=>[//阿里云短信 'access_key_id' => 'xxxxxx',//要改 'access_key_secret' => 'xxxxxx',//要改 'common_sign_name' => '支付宝',//模板签名 要改 'template_code' => [ 'register' => 'SMS_35650882',//模板变量 要改 ] ],
错误代码表
https://help.aliyun.com/document_detail/48054.html
https://github.com/hyperbolaa/Alisms