[PHP高可用后端]④②--验证码功能开发
2017-11-29 本文已影响44人
子木同
微信截图_20171129144349.png
route.php
<?php
use think\Route;
Route::get('test', 'api/test/index');
Route::put('test/:id', 'api/test/update');
Route::delete('test/:id', 'api/test/delete');
Route::resource('test', 'api/test');
Route::get('api/:ver/cat', 'api/:ver.cat/read');
Route::get('api/:ver/index', 'api/:ver.index/index');
Route::get('api/:ver/init', 'api/:ver.index/init');
Route::resource('api/:ver/news', 'api/:ver.news');
Route::get('api/:ver/rank', 'api/:ver.rank/index');
Route::get('test/testsend', 'api/test/testSend');
//短信验证码相关
Route::resource('api/:ver/identify', 'api/:ver.identify');
Identify.php(Validate)
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/29
* Time: 14:52
*/
namespace app\common\validate;
use think\Validate;
class Identify extends Validate
{
protected $rule=[
'id'=>'require|number|length:11',
];
}
Identify.php(Controller)
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/29
* Time: 14:49
*/
namespace app\api\controller\v1;
use app\api\controller\Common;
use app\common\lib\Alidayu;
class Identify extends Common
{
/**
* post
* 设置短信验证码
*/
public function save()
{
if (!request()->isPost()) {
return show(config('code.error'), '您提交的数据不合法', [], 403);
}
//检测数据
$validate = validate('Identify');
if (!$validate->check(input('post.'))) {
return show(config('code.error'), $validate->getError(), [], 403);
}
$id = input('param.id');
if (Alidayu::getInstance()->setSmsIdentify($id)) {
return show(config('code.success'), 'OK',[],201);
} else {
return show(config('code.error'), 'error', [], 403);
}
}
}
image.png