PHP code example of busyphp / verify-code

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

    

busyphp / verify-code example snippets



return [
    'model' => [
        // 增加以下
        // 消息验证码模型
        'plugin_verify_code' => [
            // 定义账号类型
            'account_types' => [
                'phone' => [
                    'name'   => '短信验证码', // 名称,用于后台设置中展示
                    'expire' => 600,// 验证码过期秒数
                    'repeat' => 60, // 可重发验证码秒数
                    'length' => 6,  // 验证码长度
                    'style'  => \BusyPHP\facade\VerifyCode::STYLE_NUMBER  // 验证码类型
                ]
            ]
        ],
    ]
];

$code = \BusyPHP\verifycode\facade\VerifyCode::create('phone', '13333333333', 'login');

// 自定义发送验证码逻辑
$success = send_sms($code); 

// 发送验证码失败
if (!$success) {
    // 删除
    \BusyPHP\verifycode\facade\VerifyCode::clear('phone', '13333333333', 'login');
}


\BusyPHP\verifycode\facade\VerifyCode::check('phone', '13333333333', 'login', '123456');