PHP code example of yzh52521 / webman-captcha-grid
1. Go to this page and download the library: Download yzh52521/webman-captcha-grid 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/ */
yzh52521 / webman-captcha-grid example snippets
namespace app\controller;
class Test
{
/**
* 生成验证码
* @return array
*/
public function captcha()
{
return json(\yzh52521\GridCaptcha\facade\GridCaptcha::get([
'mobile' => '100xxxxx121'
]));
}
}
namespace app\controller;
use support\Request;
class Test
{
/**
* 效验
* @param Request $request
* @return array|false
*/
public function check(Request $request)
{
/**
* 传参效验
*/
if ($captcha_data = \yzh52521\GridCaptcha\facade\GridCaptcha::check('Qh8kHYF4C....', '1540') === false) {
return json(['message' => '验证码错误', 'code' => 401]);
}
/**
* 传递 Request 对象效验
*/
if ($captcha_data = \yzh52521\GridCaptcha\facade\GridCaptcha::checkRequest($request)) {
return json(['message' => '验证码错误', 'code' => 401]);
}
return $captcha_data;
}
}
//效验完成正确后 您可以进行业务逻辑处理,比如可以获取到上方设置在验证码中的数据 如:上方设置的是手机号,您这里可以获取验证码中的手机号,当效验成功发送短信验证码等...