110 lines
2.9 KiB
PHP
Executable File
110 lines
2.9 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: lock
|
|
* Date: 2018/11/4
|
|
* Time: 下午1:39
|
|
* 初始化
|
|
*/
|
|
|
|
namespace app\index\controller;
|
|
|
|
|
|
use app\index\validate\customValidate;
|
|
use think\Controller;
|
|
use think\Request;
|
|
use think\Session;
|
|
|
|
class Common extends Controller
|
|
{
|
|
public static $error_code_name = 'error_code';
|
|
|
|
public static $error_message = 'error_msg';
|
|
|
|
public static $result = array('error_code'=>0);
|
|
|
|
public static $data_name = 'data';
|
|
|
|
public static $insert_id = 'insert_id';
|
|
|
|
public static $forbid_return_where_arr = array('page','pageSize');
|
|
|
|
const DEFAULT_KEY = 'wx_access_token_name';
|
|
|
|
const SELF_DEFAULT_KEY = '0e15ad1bdc3fb96a63a2c28c45625e6a';
|
|
|
|
const SELF_SECRET_SECOND = 10;
|
|
|
|
/**
|
|
* _initialize
|
|
*/
|
|
public function _initialize()
|
|
{
|
|
$session = Session::get('admin');
|
|
if (empty($session))
|
|
{
|
|
$this->redirect('/admin/login');
|
|
}else
|
|
{
|
|
$this->assign('session',$session);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* createAccessToken
|
|
* @return string
|
|
*/
|
|
public function createAccessToken()
|
|
{
|
|
$tmp_time_int = time();
|
|
$tmp_str = self::DEFAULT_KEY.self::SELF_DEFAULT_KEY.$tmp_time_int;
|
|
return md5($tmp_str);
|
|
}
|
|
|
|
/**
|
|
* @param $field_arr
|
|
* array(array('field_name'=>'user_name','type' => 'email','require' => true))
|
|
* @return array
|
|
*/
|
|
public function checkHave($field_arr)
|
|
{
|
|
$return_result = array(self::$error_code_name => 0);
|
|
$rule = array();
|
|
$field = array();
|
|
$data = array();
|
|
$rule_data = array();
|
|
// $post_value_arr = Request::instance()->post();
|
|
$post_value_arr = Request::instance()->request();
|
|
foreach ($field_arr as $field_val)
|
|
{
|
|
$post_value = '';
|
|
if (array_key_exists($field_val['field_name'],$post_value_arr))
|
|
{
|
|
$post_value = $post_value_arr[$field_val['field_name']];
|
|
if(trim($post_value) == "") {
|
|
$data[$field_val['field_name']] = $post_value;
|
|
}else
|
|
{
|
|
$data[$field_val['field_name']] = $post_value;
|
|
}
|
|
}
|
|
if (trim($field_val['rule']) != '') {
|
|
$rule_data[$field_val['field_name']] = $post_value;
|
|
$rule[$field_val['field_name']] = $field_val['rule'];
|
|
$field[$field_val['field_name']] = $field_val['field_name'];
|
|
}
|
|
}
|
|
$validate = new customValidate($rule,[],$field);
|
|
$result = $validate->check($rule_data);
|
|
if(!$result)
|
|
{
|
|
$return_result[self::$error_code_name] = '1';
|
|
$return_result[self::$error_message] = $validate->getError();
|
|
}else{
|
|
$return_result[self::$data_name] = $data;
|
|
}
|
|
return $return_result;
|
|
}
|
|
|
|
|
|
} |