1.上文参考 接口安全设计-上
2. 安全设计基础上,增加参数过滤验证规则
<?php
namespace app\api\controller;
use think\Request;
use think\Controller;
// 参数过滤,需要的核心类
use think\Validate;
class Common extends Controller
{
protected $request; //用来处理参数
protected $validater; // 用来验证数据/参数
protected $params; // 过滤后符合要求的参数
// 定义验证规则
protected $rules = array(
'User' => array(
'login'=>array(
'user_name'=>['require','chsDash','max'=>20],
'user_pwd'=>'require|length:32'
),
'reqister'=>array(),
),
);
// 获取 ;$rules['User']['login']
protected function _initialize(){
parent::_initialize();
$this -> request = Request::instance();
// 判断传过来的时间戳是否超时
$this -> check_time($this->request