yiier/yii2-smser

sms for Yii2

Installs: 29

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 4

Forks: 0

Open Issues: 0

Type:yii2-extension

v0.1.1 2018-02-03 07:01 UTC

This package is auto-updated.

Last update: 2024-12-26 00:06:08 UTC


README

sms for Yii2

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiier/yii2-smser "*"

or add

"yiier/yii2-smser": "*"

to the require section of your composer.json file.

Migrations

Run the following command

$ php yii migrate --migrationPath=@yiier/smser/migrations/

Usage

Once the extension is installed, simply modify your application configuration as follows:

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

More detail overtrue/easy-sms 使用

Validator

<?php
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 && update code status

<?php
// 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);