PHP code example of ztkj / zt-sms

1. Go to this page and download the library: Download ztkj/zt-sms library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ztkj / zt-sms example snippets




use Overtrue\EasySms\EasySms;

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

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

        // 默认可用的发送网关
        'gateways' => [
            'jpush', 'aliyun', 'qcloud'
        ],
    ],
    // 可用的网关配置
    'gateways' => [
        'errorlog' => [
            'file' => '/tmp/easy-sms.log',
        ],
        'jpush' => [
            'app_key' => 'your-app-key',
            'master_secret' => 'your-master-secret',
            'sign_id' => 'your-sign-id', // 签名ID
        ],
        'aliyun' => [
            'access_key_id' => '',
            'access_key_secret' => '',
            'sign_name' => '',
        ],
        'qcloud' => [
            'sdk_app_id' => '', // SDK APP ID
            'secret_id' => '', // SECRET ID
            'secret_key' => '', // SECRET KEY
            'sign_name' => '', // 短信签名
        ],
        //...
    ],
];

$easySms = new EasySms($config);

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

'jpush' => [
    'app_key' => 'your-app-key',
    'master_secret' => 'your-master-secret', 
    'sign_id' => 'your-sign-id', // 签名ID,在极光短信控制台获取
],

// 发送验证码
$easySms->send(13188888888, [
    'template' => 'temp_id', // 模板ID
    'data' => [
        'code' => '1234', // 模板变量
    ],
]);

// 发送纯文本短信
$easySms->send(13188888888, [
    'content' => '您的验证码是:1234',
]);