PHP code example of brayun / yii2-sms

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

    

brayun / yii2-sms example snippets


public function actions()
{
    return [
        'smscode' => [
            'class' => SendAction::className(),
            'tplCode' => 'SMS_94663333',
            'signName' => '我是签名',
            'params' => [
                'code' => rand(1000, 9999)
            ],
            'beforeFunction' => function () {
                if (User::findOne(['mobile' => \Yii::$app->request->post('mobile')])) {
                    return [
                        'code' => 1,
                        'msg' => '手机号码已存在!'
                    ];
                }
            }
        ]
    ];
}


public function rules()
{
    return [
        ...
        ['code', PhoneCodeValidator::className()],
    ];
}

'components' => [
    'sms' => [
        'class' => 'brayun\sms\Application',
        'signName' => '统一签名'
    ],
    ...
]

Yii::$app->sms->send('13000000000','SMS_123456',['code'=>1234], '这里签名可另写');