TP5.1集合多短信平台发送短信验证码

安装easy-sms

$ composer require "overtrue/easy-sms"

新建一个配置文件config/easysms.php

<?php
/**
 * Created by PhpStorm.
 * User: Pasa吴
 * Date: 2019/7/17
 * Time: 15:56
 */

return [
    // HTTP 请求的超时时间(秒)
    'timeout'  => 5.0,

    // 默认发送配置
    'default'  => [
        // 网关调用策略,默认:顺序调用
        'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,

        // 默认可用的发送网关
        'gateways' => [
            'aliyun',//阿里大于
            'qcloud',//腾讯云
        ],
    ],
    // 可用的网关配置
    'gateways' => [
        'errorlog' => [
            'file' => __DIR__ . '/easy-sms.log',
        ],
        'qcloud'   => [
            'sdk_app_id' => 'xx', // SDK APP ID
            'app_key'    => 'xx', // APP KEY
            'sign_name'  => '可以不填写', // 对应的是短信签名中的内容(非id)
        ],
        'aliyun' => [
            'access_key_id' => 'xx',
            'access_key_secret' => 'xx',
            'sign_name' => 'xx',
        ],
    ],
];

发送短信服务层
applicationcommonserviceSms.php

<?php
/**
 * Created by PhpStorm.
 * User: Pasa吴
 * Date: 2019/7/17
 * Time: 15:46
 */

namespace app\common\service;

use Overtrue\EasySms\EasySms;
use think\facade\Config;

class Sms extends Base
{

    public function send($mobile,$code,$content=''){
        $easySms = new EasySms(Config::get('easysms.'));

        $easySms->send($mobile, [
            'content'  => '您的验证码为: 6379',
            'template' => 'SMS_137425918',
            'data' => [
                'code' => 6379
            ],
        ]);

//        $easySms->send($mobile, [
//            'template' => '66907',
//            'data' => [$code,'1']//{1}{2}
//            //【看车狗科技有限公司】{1}为您的验证码,请于{2}分钟内填写,如非本人操作,请忽略本短信。
//            //data数组按顺序对应你设置的变量
//        ]);

        return true;
    }


}

发送短信

use app\common\service\Sms AS S_Sms;

(new S_Sms)->send($this->param['mobile'],'1');

Pasa吴技术博客
请先登录后发表评论
  • latest comments
  • 总共0条评论