laravel下实现阿里云短信服务 (laravel-aliyun-sms)
一、安装
composer require cisco/laravel-aliyunsms dev-master
二、打开config/app.php,添加配置代码
1、‘providers’ 配置组下添加
Cisco\Aliyunsms\AliyunsmsServiceProvider::class
2、‘aliases’ 配置组下添加
'Aliyunsms' => Cisco\Aliyunsms\Facades\Aliyunsms::class
三、运行composer
composer dump-autoload
四、运行php artisan
php artisan vendor:publish --provider="Cisco\Aliyunsms\AliyunsmsServiceProvider"
五、修改config/aliyunsms.php
六、开始调用
<?php
namespace App\Http\Controllers;
use Cisco\Aliyunsms\Facades\Aliyunsms;
class SendController
{
public function send(){
$PhoneNumber = "170****8000"; //手机号
$SignName = "模板签名"; //模板签名
$TemplateCode= "模板code"; //模板CODE
$TemplateParam = [
"code" => rand(100000,999999),
"product" => "dsd"
];
$send = Aliyunsms::sendSms(strval($PhoneNumber), $SignName, $TemplateCode, $TemplateParam);
if ($send->Code == 'OK') {
dump("Success");
} else {
dump("failed");
}
}
}