thinkphp6 發送短信,thinkphp6短信通知,阿里雲短信,騰訊雲短信


thinkphp6 sms 短信驅動管理

驅動列表



安裝(自帶阿里雲驅動)

composer 安裝(推薦)


composer require death_satan/thinkphp-sms -vvv

其他安裝請自行摸索

更改配置

修改 config/sms.php 配置文件


<?php
/**
 * @author    : Death-Satan
 * @date      : 2021/8/19
 * @createTime: 15:09
 * @company   : Death撒旦
 * @link      https://www.cnblogs.com/death-satan
 */
return [
    'default'=>env('sms.default','aliyun'),
    'expire'=>env('sms.expire',300),//短信驗證默認過期時間
    'drives'=>[
        //阿里雲配置
        'aliyun'=>[
            'type'=>'Aliyun',
            'accessKeyId'=>null,// 您的AccessKey ID,
            'accessKeySecret'=>null,//// 您的AccessKey Secret,
            'endpoint'=>null,//訪問的域名
            'runtime'=>[
                'maxIdleConns'=>3,
                'connectTimeout'=>10000,
                'readTimeout'=>10000
            ]
        ]
    ]
];

使用

在控制器中使用


<?php
namespace app\controller;

use app\BaseController;
use SaTan\Think\Sms\Sms;

class Index extends BaseController
{
    public function index(Sms $sms)
    {
        //方法1:
        //獲取阿里雲驅動
        $driver = $sms->disk('aliyun');        
        //方法2:
        //獲取驅動
        $driver =$this->app->sms->disk('aliyun');
        //通過驅動發送短信
        $driver->sendSms(123456456,'sign_name','template_code',[
            'code'=>rand(1000,9999)
        ]);
    }
}



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM