PHP code example of hongyukeji / php-sms

1. Go to this page and download the library: Download hongyukeji/php-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/ */

    

hongyukeji / php-sms example snippets

shell
$ composer 

use Hongyukeji\PhpSms\Sms;

$config = [
    'default' => 'aliyun',
    'gateways' => [
        'yunpian' => [
            'apikey' => '',
        ],
        'aliyun' => [
            'accessKeyId' => '',
            'accessKeySecret' => '',
            'signName' => '',
        ],
        'qcloud' => [
            'appid' => '',
            'appkey' => '',
            'smsSign' => '',
        ],
        'duanxinbao' => [
            'user' => '',
            'pass' => '',
            'signName' => '',
        ],
        'submail' => [
            'appid' => '',
            'appkey' => '',
        ],
        'sendcloud' => [
            'sms_user' => '',
            'sms_key' => '',
        ],
        'ihuyi' => [
            'apiid' => '',
            'apikey' => '',
        ],
        // Other...
    ],
];

// 初始化短信类
$sms = new Sms($config);

// 模板CODE + 模板参数 
// template_code + template_params
$result_template_code = $sms->send('13800138000', 'SMS_88888888', [
    'code' => '1234',
    'time' => '15分钟',
]);
var_dump($result_template_code);

// 模板内容 + 模板参数
// template_content + template_params
$result_template_content = $sms->send(['13800138000', '13900139000'], '您的验证码是%s。有效期为%s,请尽快验证!', [
    'code' => '1234',
    'time' => '15分钟',
], 'duanxinbao');
var_dump($result_template_content);

// $result 结果返回值说明
// code: 0 => 短信发送成功, 1 => 短信发送失败
$result = [
    'code' => '0',
    'message' => '短信发送成功!',
];

'yunpian' => [
    'apikey' => '',
    'driver' => 'Hongyukeji\\PhpSms\\Gateways\\YunpianGateway',
],

'duanxinbao' => [
    'user' => '',
    'pass' => '',
    'signName' => '',
    'driver' => 'Hongyukeji\\PhpSms\\Gateways\\DuanxinbaoGateway',
],

'sendcloud' => [
    'sms_user' => '',
    'sms_key' => '',
    'driver' => 'Hongyukeji\\PhpSms\\Gateways\\SendCloudGateway',
],

'chuanglan' => [
    'api_send_url' => '',
    'api_variable_url' => '',
    'api_balance_query_url' => '',
    'api_account' => '',
    'api_password' => '',
    'sms_sign' => '',
    'driver' => 'Hongyukeji\\PhpSms\\Gateways\\ChuanglanGateway',
],

'qiniu' => [
    'sms_name' => '七牛云',
    'sms_url' => 'https://www.qiniu.com/products/sms',
    'access_key' => '',
    'secret_key' => '',
    'driver' => 'Hongyukeji\\PhpSms\\Gateways\\QiniuGateway',
],

'ucloud' => [
    'sms_name' => '优刻得',
    'sms_url' => 'https://www.ucloud.cn',
    'private_key' => '',
    'public_key' => '',
    'sig_content' => '',
    'project_id' => '',
    'driver' => 'Hongyukeji\\PhpSms\\Gateways\\RonglianCloudGateway',
],