PHP code example of yiier / yii2-smser

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

    

yiier / yii2-smser example snippets



return [
    // something code
    'components' => [
        'smser' => [
            'class' => 'yiier\smser\Smser',
            'config' => [
                'gateways' => [
                    // 云片网
                    'yunpian' => [
                        'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxx',
                    ],
                ],
            ]
        ]
    ]
];


class SignupForm extends \yii\base\Model
{
    // something code
    public $verifyCode;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            // something code
            // usage is Optional
            ['verifyCode', '\yiier\smser\validators\SmsCodeValidator', 'usage' => 'Signup'],
        ];
    }
}


// send code
Yii::$app->smser->send(18688888888, [
    'content'  => '您的验证码为: 1234',
    'template' => 'SMS_001',
    'data' => ['code' => 1234, 'usage' => 'Signup'], // or 'data' => ['code' => 1234],
]);

// update used status 
\yiier\smser\models\SmsLog::used(18688888888, 1234);

php composer.phar