微信截图_20171122110341.png
微信截图_20171122110858.png
config.php
'app_debug' => true,
IAuth.php
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/20
* Time: 13:56
*/
namespace app\common\lib;
use think\Cache;
class IAuth
{
public static function setPassword($data)
{
return md5($data . config('app.password_pre_halt'));
}
public static function setSign($data = [])
{
ksort($data);
$string = http_build_query($data);
$string = (new Aes())->encryt($string);
return $string;
}
/**
* 检查sign是否正常
* @param string $sign
* @param $data
* @return boolean
*/
public static function checkSignPass($data)
{
$str = (new Aes())->decrypt($data['sign']);
if (empty($str)) {
return false;
}
//diid=xx&app_type=3
parse_str($str, $arr);
/**
* array (size=2)
* 'did' => string '12345dg' (length=7)
* 'version' => string '1' (length=1)
*/
//halt($arr);
if (!is_array($arr) || empty($arr['did'])
|| $arr['did'] != $data['did']
) {
return false;
}
if (!config('app_debug')) {
if ((time() - ceil($arr['time'] / 1000)) > config('app.app_sign_time')) {
return false;
}
//int 1
//halt(Cache::get($data['sign']));
//唯一性判定
if (Cache::get($data['sign'])) {
return false;
}
}
return true;
}
}
if (!config('app_debug')) {
if ((time() - ceil($arr['time'] / 1000)) > config('app.app_sign_time')) {
return false;
}
//int 1
//halt(Cache::get($data['sign']));
//唯一性判定
if (Cache::get($data['sign'])) {
return false;
}
}
code.php
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/20
* Time: 14:19
*/
return [
'status_delete' => -1,
'status_normal' => 1,
'status_padding' => 0,
'success'=>1,
'error'=>0,
];
route.php
<?php
use think\Route;
Route::get('test', 'api/test/index');
Route::put('test/:id', 'api/test/update');
Route::resource('test', 'api/test');
Route::get('api/cat', 'api/cat/read');
Cat.php
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/22
* Time: 11:09
*/
namespace app\api\controller;
class Cat extends Common
{
public function read()
{
$cats = config('cat.list');
/**
* array (size=4)
* 1 => string '综艺' (length=6)
* 2 => string '明星' (length=6)
* 3 => string '韩娱' (length=6)
* 4 => string '看点' (length=6)
*/
//halt($cats);
$result []= [
'catid'=>0,
'catname'=>'首页',
];
foreach ($cats as $catid => $catname) {
$result[] = [
'catid' => $catid,
'catname' => $catname,
];
}
return show(config('code.success'), 'OK', $result, 200);
}
}
image.png
网友评论