初始化2.0版本

This commit is contained in:
zhaoxiang 2017-04-15 22:04:50 +08:00
parent 303debbe8f
commit a363fe6a07
583 changed files with 23359 additions and 81016 deletions

View File

@ -1,13 +1,17 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
/**
* 系统非常规MD5加密方法
* @param string $str 要加密的字符串
* @param string $auth_key 要加密的字符串
* @return string
* @author jry <598821125@qq.com>
*/
function user_md5($str, $auth_key = ''){
if(!$auth_key){
$auth_key = C('AUTH_KEY');
}
return '' === $str ? '' : md5(sha1($str) . $auth_key);
}
/**
* 判断是否是系统管理员
@ -15,26 +19,25 @@
* @return bool
*/
function isAdministrator( $uid = '' ){
$adminConf = config('base')['USER_ADMINISTRATOR'];
$uid = empty($uid) ? session('uid') : $uid;
if( is_array($adminConf) ){
if( empty($uid) ) $uid = session('uid');
if( is_array(C('USER_ADMINISTRATOR')) ){
if( is_array( $uid ) ){
$m = array_intersect( $adminConf, $uid );
$m = array_intersect( C('USER_ADMINISTRATOR'), $uid );
if( count($m) ){
return TRUE;
}
}else{
if( in_array( $uid, $adminConf ) ){
if( in_array( $uid, C('USER_ADMINISTRATOR') ) ){
return TRUE;
}
}
}else{
if( is_array( $uid ) ){
if( in_array($adminConf,$uid) ){
if( in_array(C('USER_ADMINISTRATOR'),$uid) ){
return TRUE;
}
}else{
if( $uid == $adminConf){
if( $uid == C('USER_ADMINISTRATOR')){
return TRUE;
}
}
@ -42,38 +45,6 @@ function isAdministrator( $uid = '' ){
return FALSE;
}
/**
* CURL post数据
* @param $url
* @param $data
* @param array $urlParam
* @param array $header
* @return mixed
*/
function curlPost( $url, $data, $urlParam = [], $header = [] ){
$ch = curl_init();
if( !empty($urlParam) ){
$url = $url.'?'.http_build_query($urlParam);
}
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
if( !empty($header) ){
$headerStrArr = [];
foreach ($header as $key => $value){
$headerStrArr[] = "$key: $value";
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerStrArr);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
/**
* 把返回的数据集转换成Tree
* @param $list
@ -84,9 +55,9 @@ function curlPost( $url, $data, $urlParam = [], $header = [] ){
* @return array
*/
function listToTree($list, $pk='id', $pid = 'fid', $child = '_child', $root = '0') {
$tree = [];
$tree = array();
if(is_array($list)) {
$refer = [];
$refer = array();
foreach ($list as $key => $data) {
$refer[$data[$pk]] = &$list[$key];
}
@ -106,7 +77,7 @@ function listToTree($list, $pk='id', $pid = 'fid', $child = '_child', $root = '0
}
function formatTree($list, $lv = 0, $title = 'name'){
$formatTree = [];
$formatTree = array();
foreach($list as $key => $val){
$title_prefix = '';
for( $i=0;$i<$lv;$i++ ){
@ -126,4 +97,20 @@ function formatTree($list, $lv = 0, $title = 'name'){
}
}
return $formatTree;
}
}
if (!function_exists('array_column')) {
function array_column($array, $val, $key = null){
$newArr = array();
if( is_null($key) ){
foreach ($array as $index => $item) {
$newArr[] = $item[$val];
}
}else{
foreach ($array as $index => $item) {
$newArr[$item[$key]] = $item[$val];
}
}
return $newArr;
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,8 @@
<?php
return array(
//模板相关配置
'TMPL_ACTION_ERROR' => APP_PATH.'Admin/Tpl/jump.tpl', // 默认错误跳转对应的模板文件
'TMPL_ACTION_SUCCESS' => APP_PATH.'Admin/Tpl/jump.tpl', // 默认成功跳转对应的模板文件
'TMPL_EXCEPTION_FILE' => APP_PATH.'Admin/Tpl/exception.tpl',// 异常页面的模板文件
);

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,91 @@
<?php
/**
*
* @since 2017/03/08 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Controller;
class ApiManageController extends BaseController {
public function index() {
//添加排序 //add by wkj 2017-03-18
$list = D('ApiList')->order('id asc')->select();
$this->assign('list', $list);
$this->display();
}
public function edit() {
if( IS_GET ) {
$id = I('get.id');
if( $id ){
$detail = D('ApiList')->where(array('id' => $id))->find();
$this->assign('detail', $detail);
$this->display('add');
}else{
$this->redirect('add');
}
}elseif( IS_POST ) {
$data = I('post.');
$res = D('ApiList')->where(array('id' => $data['id']))->save($data);
if( $res === false ) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
}
}
public function add() {
if( IS_POST ) {
$data = I('post.');
$res = D('ApiList')->add($data);
if( $res === false ) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
} else {
$data['hash'] = uniqid();
$this->assign('detail', $data);
$this->display();
}
}
public function open() {
if( IS_POST ) {
$id = I('post.id');
if( $id ) {
D('ApiList')->open(array('id' => $id));
$this->ajaxSuccess('操作成功');
} else {
$this->ajaxError('缺少参数');
}
}
}
public function close() {
if( IS_POST ) {
$id = I('post.id');
if( $id ) {
D('ApiList')->close(array('id' => $id));
$this->ajaxSuccess('操作成功');
} else {
$this->ajaxError('缺少参数');
}
}
}
public function del() {
if( IS_POST ) {
$id = I('post.id');
if( $id ) {
D('ApiList')->del(array('id' => $id));
$this->ajaxSuccess('操作成功');
} else {
$this->ajaxError('缺少参数');
}
}
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
*
* @since 2017/03/06 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Controller;
use Home\ORG\Str;
class AppController extends BaseController {
public function index(){
$list = D('ApiApp')->select();
$this->assign('list', $list);
$this->display();
}
public function edit(){
if( IS_GET ){
$id = I('get.id');
if( $id ){
$detail = D('ApiApp')->where(array('id' => $id))->find();
$this->assign('detail', $detail);
$this->display('add');
}else{
$this->redirect('add');
}
}elseif( IS_POST ){
$data = I('post.');
$res = D('ApiApp')->where(array('id' => $data['id']))->save($data);
if( $res === false ){
$this->ajaxError('操作失败');
}else{
$this->ajaxSuccess('添加成功');
}
}
}
public function add(){
if( IS_POST ){
$data = I('post.');
$res = D('ApiApp')->add($data);
if( $res === false ){
$this->ajaxError('操作失败');
}else{
$this->ajaxSuccess('添加成功');
}
}else{
$data['app_id'] = Str::randString(8, 1);
$data['app_secret'] = Str::randString(32);
$this->assign('detail', $data);
$this->display();
}
}
public function open(){
if( IS_POST ){
$id = I('post.id');
if( $id ){
D('ApiApp')->open(array('id' => $id));
$this->ajaxSuccess('操作成功');
}else{
$this->ajaxError('缺少参数');
}
}
}
public function close(){
if( IS_POST ){
$id = I('post.id');
if( $id ){
D('ApiApp')->close(array('id' => $id));
$this->ajaxSuccess('操作成功');
}else{
$this->ajaxError('缺少参数');
}
}
}
public function del(){
if( IS_POST ){
$id = I('post.id');
if( $id ){
D('ApiApp')->del(array('id' => $id));
$this->ajaxSuccess('操作成功');
}else{
$this->ajaxError('缺少参数');
}
}
}
}

View File

@ -0,0 +1,176 @@
<?php
/**
* 工程基类
* @since 2017/02/28 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Controller;
use Think\Controller;
use Admin\ORG\Auth;
class BaseController extends Controller {
protected $userInfo;
protected $allMenu;
protected $uid;
private $url;
private $menuInfo;
public function _initialize(){
//初始化系统
$this->uid = session('uid');
$this->assign('uid', $this->uid);
$this->iniSystem();
//控制器初始化
if(method_exists($this, 'myInit')){
$this->myInit();
}
}
/**
* 自定义初始化函数
*/
public function myInit(){}
/**
* Ajax正确返回自动添加debug数据
* @param $msg
* @param array $data
* @param int $code
*/
public function ajaxSuccess( $msg, $code = 1, $data = array() ){
$returnData = array(
'code' => $code,
'msg' => $msg,
'data' => $data
);
if( !empty($this->debug) ){
$returnData['debug'] = $this->debug;
}
$this->ajaxReturn($returnData, 'json');
}
/**
* Ajax错误返回自动添加debug数据
* @param $msg
* @param array $data
* @param int $code
*/
public function ajaxError( $msg, $code = 0, $data = array() ){
$returnData = array(
'code' => $code,
'msg' => $msg,
'data' => $data
);
if( !empty($this->debug) ){
$returnData['debug'] = $this->debug;
}
$this->ajaxReturn($returnData, 'json');
}
/**
* 将二维数组变成指定key
* @param $array
* @param $keyName
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array
*/
protected function buildArrByNewKey($array, $keyName = 'id') {
$list = array();
foreach ($array as $item) {
$list[$item[$keyName]] = $item;
}
return $list;
}
private function iniSystem() {
$this->url = CONTROLLER_NAME . '/' . ACTION_NAME;
$this->isForbid();
if (CONTROLLER_NAME != 'Login') {
$this->allMenu = D('ApiMenu')->order('sort asc')->select();
$this->menuInfo = D('ApiMenu')->where(array('url' => $this->url))->find();
if (empty($this->menuInfo)) {
if (IS_AJAX) {
$this->ajaxError('当前URL非法');
} else {
$this->error('当前URL非法');
}
}
$this->checkLogin();
$this->checkRule();
$this->iniLog();
}
}
/**
* 封号或者封IP等特殊需求才用到的
* @return bool
*/
private function isForbid() {
return true;
}
/**
* 检测登录
*/
private function checkLogin() {
if (isset($this->uid) && !empty($this->uid)) {
$sidNow = session_id();
$sidOld = S($this->uid);
if (isset($sidOld) && !empty($sidOld)) {
if ($sidOld !== $sidNow) {
$this->error("您的账号在别的地方登录了,请重新登录!", U('Login/index'));
} else {
S($this->uid, $sidNow, C('ONLINE_TIME'));
$this->userInfo = $userInfo = D('ApiUser')->where(array('id' => $this->uid))->find();
$this->assign('userInfo', $this->userInfo);
}
} else {
$this->error("登录超时,请重新登录!", U('Login/index'));
}
} else {
$this->redirect('Login/index');
}
}
/**
* 检测权限
*/
private function checkRule() {
$isAdmin = isAdministrator();
if ($isAdmin) {
return true;
} else {
if ($this->menuInfo['level'] !== 0) {
$authObj = new Auth();
$check = $authObj->check(strtolower($this->url), $this->uid);
if (!$check) {
$this->ajaxError(L('_VALID_ACCESS_'));
}
}
}
}
/**
* 根据菜单级别进行区别Log记录当然如果有更加细节的控制也可以在这个函数内实现
*/
private function iniLog() {
$data = array(
'actionName' => $this->menuInfo['name'],
'uid' => $this->uid,
'nickname' => $this->userInfo['nickname'],
'addTime' => time(),
'url' => $this->menuInfo['url'],
'data' => json_encode($_REQUEST)
);
D('ApiUserAction')->add($data);
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
*
* @since 2017/04/01 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Controller;
class FieldsInfoManageController extends BaseController {
public function index() {
$list = D('ApiFieldsInfo')->order('id asc')->select();
$this->assign('list', $list);
$this->display();
}
public function edit() {
if( IS_GET ) {
$id = I('get.id');
if( $id ){
$detail = D('ApiFieldsInfo')->where(array('id' => $id))->find();
$this->assign('detail', $detail);
$this->display('add');
}else{
$this->redirect('add');
}
}elseif( IS_POST ) {
$data = I('post.');
$res = D('ApiFieldsInfo')->where(array('id' => $data['id']))->save($data);
if( $res === false ) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
}
}
public function add() {
if( IS_POST ) {
$data = I('post.');
$res = D('ApiFieldsInfo')->add($data);
if( $res === false ) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
} else {
$data['hash'] = uniqid();
$this->assign('detail', $data);
$this->display();
}
}
public function del() {
if( IS_POST ) {
$id = I('post.id');
if( $id ) {
D('ApiFieldsInfo')->where(array('id' => $id))->delete();
$this->ajaxSuccess('操作成功');
} else {
$this->ajaxError('缺少参数');
}
}
}
}

View File

@ -0,0 +1,188 @@
<?php
/**
*
* @since 2017/03/09 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Controller;
use Home\ORG\DataType;
class FieldsManageController extends BaseController {
private $dataType = array(
DataType::TYPE_INTEGER => 'Integer',
DataType::TYPE_STRING => 'String',
DataType::TYPE_BOOLEAN => 'Boolean',
DataType::TYPE_ENUM => 'Enum',
DataType::TYPE_FLOAT => 'Float',
DataType::TYPE_FILE => 'File',
DataType::TYPE_MOBILE => 'Mobile',
DataType::TYPE_OBJECT => 'Object',
DataType::TYPE_ARRAY => 'Array'
);
public function index() {
}
public function request() {
$hash = I('get.hash');
$where['type'] = 0;
if (!empty($hash)) {
$where['hash'] = $hash;
}
$res = D('ApiFields')->where($where)->select();
$this->assign('dataType', $this->dataType);
$this->assign('list', $res);
$this->assign('type', 0);
$this->display('index');
}
public function response() {
$hash = I('get.hash');
$where['type'] = 1;
if (!empty($hash)) {
$where['hash'] = $hash;
}
$res = D('ApiFields')->where($where)->select();
$this->assign('dataType', $this->dataType);
$this->assign('list', $res);
$this->assign('type', 1);
$this->display('index');
}
public function add() {
if (IS_POST) {
$data = I('post.');
$data['fieldName'] = $data['showName'];
$res = D('ApiFields')->add($data);
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
} else {
$this->assign('dataType', $this->dataType);
$this->display();
}
}
public function edit() {
if (IS_POST) {
$data = I('post.');
$data['fieldName'] = $data['showName'];
$res = D('ApiFields')->where(array('id' => $data['id']))->save($data);
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
} else {
$id = I('get.id');
if ($id) {
$detail = D('ApiFields')->where(array('id' => $id))->find();
$this->assign('detail', $detail);
$this->assign('dataType', $this->dataType);
$this->display('add');
}
}
}
public function del() {
if (IS_POST) {
$id = I('post.id');
if ($id) {
D('ApiFields')->where(array('id' => $id))->delete();
$this->ajaxSuccess('操作成功');
} else {
$this->ajaxError('缺少参数');
}
}
}
public function upload() {
if (IS_POST) {
$hash = I('post.hash');
$jsonStr = I('post.jsonStr');
$jsonStr = html_entity_decode($jsonStr);
$data = json_decode($jsonStr, true);
D('ApiList')->where(array('hash' => $hash))->save(array('returnStr' => json_encode($data)));
$this->handle($data['data'], $dataArr);
D('ApiFields')->where(array(
'hash' => $hash,
'type' => I('post.type')
))->delete();
D('ApiFields')->addAll($dataArr);
$this->ajaxSuccess('操作成功');
} else {
$this->display();
}
}
private function handle($data, &$dataArr, $prefix = 'data', $index = 'data') {
if (!$this->isAssoc($data)) {
$addArr = array(
'fieldName' => $index,
'showName' => $prefix,
'hash' => I('post.hash'),
'isMust' => 1,
'dataType' => DataType::TYPE_ARRAY,
'type' => I('post.type')
);
$dataArr[] = $addArr;
$prefix .= '[]';
if (is_array($data[0])) {
$this->handle($data[0], $dataArr, $prefix);
}
} else {
$addArr = array(
'fieldName' => $index,
'showName' => $prefix,
'hash' => I('post.hash'),
'isMust' => 1,
'dataType' => DataType::TYPE_OBJECT,
'type' => I('post.type')
);
$dataArr[] = $addArr;
$prefix .= '{}';
foreach ($data as $index => $datum) {
$myPre = $prefix . $index;
$addArr = array(
'fieldName' => $index,
'showName' => $myPre,
'hash' => I('post.hash'),
'isMust' => 1,
'dataType' => DataType::TYPE_STRING,
'type' => I('post.type')
);
if (is_numeric($datum)) {
if (preg_match('/^\d*$/', $datum)) {
$addArr['dataType'] = DataType::TYPE_INTEGER;
} else {
$addArr['dataType'] = DataType::TYPE_FLOAT;
}
$dataArr[] = $addArr;
} elseif (is_array($datum)) {
$this->handle($datum, $dataArr, $myPre, $index);
} else {
$addArr['dataType'] = DataType::TYPE_STRING;
$dataArr[] = $addArr;
}
}
}
}
/**
* 判断是否是关联数组true表示是关联数组
* @param array $arr
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return bool
*/
private function isAssoc(array $arr) {
if (array() === $arr) return false;
return array_keys($arr) !== range(0, count($arr) - 1);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Admin\Controller;
use Admin\ORG\Auth;
class IndexController extends BaseController {
public function index() {
$isAdmin = isAdministrator();
$list = array();
$menuAll = $this->allMenu;
foreach ($menuAll as $key => $menu) {
if($menu['hide'] != 0){
unset($menuAll[$key]);
}
}
foreach ($menuAll as $menu) {
if($isAdmin){
$menu['url'] = U($menu['url']);
$list[] = $menu;
}else{
$authObj = new Auth();
$authList = $authObj->getAuthList($this->uid);
if (in_array(strtolower($menu['url']), $authList) || $menu['url'] == '') {
$menu['url'] = U($menu['url']);
$list[] = $menu;
}
}
}
$this->assign('list', $list);
$this->display();
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* @since 2017-04-13
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Controller;
class LogController extends BaseController {
public function index() {
$this->display();
}
public function ajaxGetIndex() {
$postData = I('post.');
$start = $postData['start'] ? $postData['start'] : 0;
$limit = $postData['length'] ? $postData['length'] : 20;
$draw = $postData['draw'];
$where = array();
$getInfo = I('get.');
if (isset($getInfo['type']) && !empty($getInfo['type'])) {
if (isset($getInfo['keyword']) && !empty($getInfo['keyword'])) {
switch ($getInfo['type']) {
case 1:
$where['url'] = array('like', '%' . $getInfo['keyword'] . '%');
break;
case 2:
$where['nickname'] = array('like', '%' . $getInfo['keyword'] . '%');
break;
case 3:
$where['uid'] = $getInfo['keyword'];
break;
}
}
}
$total = D('ApiUserAction')->where($where)->count();
$info = D('ApiUserAction')->where($where)->limit($start, $limit)->select();
$data = array(
'draw' => $draw,
'recordsTotal' => $total,
'recordsFiltered' => $total,
'data' => $info
);
$this->ajaxReturn($data, 'json');
}
public function del() {
$id = I('post.id');
$res = D('ApiUserAction')->where(array('id' => $id))->delete();
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('操作成功');
}
}
public function showDetail() {
if (IS_GET) {
$id = I('get.id');
$listInfo = D('ApiUserAction')->where(array('id' => $id))->find();
$this->assign('detail', $listInfo);
$this->display();
}
}
}

View File

@ -0,0 +1,81 @@
<?php
namespace Admin\Controller;
/**
* 登录控制器
* @since 2016-01-16
* @author zhaoxiang <zhaoxiang051405@outlook.com>
*/
class LoginController extends BaseController {
public function index() {
$this->display();
}
public function login() {
$pass = user_md5(I('post.password'));
$user = I('post.username');
$userInfo = D('ApiUser')->where(array('username' => $user, 'password' => $pass))->find();
if (!empty($userInfo)) {
if ($userInfo['status']) {
//保存用户信息和登录凭证
S($userInfo['id'], session_id(), C('ONLINE_TIME'));
session('uid', $userInfo['id']);
//更新用户数据
$userData = D('ApiUserData')->where(array('uid' => $userInfo['id']))->find();
$data = array();
if ($userData) {
$data['loginTimes'] = $userData['loginTimes'] + 1;
$data['lastLoginIp'] = get_client_ip(1);
$data['lastLoginTime'] = NOW_TIME;
D('ApiUserData')->where(array('uid' => $userInfo['id']))->save($data);
} else {
$data['loginTimes'] = 1;
$data['uid'] = $userInfo['id'];
$data['lastLoginIp'] = get_client_ip(1);
$data['lastLoginTime'] = NOW_TIME;
D('ApiUserData')->add($data);
}
$this->ajaxSuccess('登录成功');
} else {
$this->ajaxError('用户已被封禁,请联系管理员');
}
} else {
$this->ajaxError('用户名密码不正确');
}
}
public function logOut() {
S(session('uid'), null);
session('[destroy]');
$this->success('退出成功', U('Login/index'));
}
public function changeUser() {
if (IS_POST) {
$data = I('post.');
$newData = array();
if (!empty($data['nickname'])) {
$newData['nickname'] = $data['nickname'];
}
if (!empty($data['password'])) {
$newData['password'] = user_md5($data['password']);
$newData['updateTime'] = time();
}
$res = D('ApiUser')->where(array('id' => session('uid')))->save($newData);
if ($res === false) {
$this->ajaxError('修改失败');
} else {
$this->ajaxSuccess('修改成功');
}
} else {
$userInfo = D('ApiUser')->where(array('id' => session('uid')))->find();
$this->assign('uname', $userInfo['username']);
$this->display('add');
}
}
}

View File

@ -0,0 +1,116 @@
<?php
namespace Admin\Controller;
/**
* 菜单管理控制器
* @since 2016-01-16
* @author zhaoxiang <zhaoxiang051405@outlook.com>
*/
class MenuController extends BaseController {
/**
* 获取菜单列表
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function index() {
$list = D('ApiMenu')->order('sort asc')->select();
$list = formatTree(listToTree($list));
$this->assign('list', $list);
$this->display();
}
/**
* 新增菜单
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function add() {
if (IS_POST) {
$data = I('post.');
$data['hide'] = isset($data['hide']) ? 1 : 0;
$res = D('ApiMenu')->add($data);
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
} else {
$originList = D('ApiMenu')->order('sort asc')->select();
$fid = '';
$id = I('get.id');
if (!empty($id)) {
$fid = $id;
}
$options = array_column(formatTree(listToTree($originList)), 'showName', 'id');
$this->assign('options', $options);
$this->assign('fid', $fid);
$this->display();
}
}
/**
* 显示菜单
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function open() {
$id = I('post.id');
$res = D('ApiMenu')->where(array('id' => $id))->save(array('hide' => 0));
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
}
/**
* 隐藏菜单
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function close() {
$id = I('post.id');
$res = D('ApiMenu')->where(array('id' => $id))->save(array('hide' => 1));
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
}
/**
* 编辑菜单
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function edit() {
if (IS_GET) {
$originList = D('ApiMenu')->order('sort asc')->select();
$list = $this->buildArrByNewKey($originList);
$listInfo = $list[I('get.id')];
$options = array_column(formatTree(listToTree($originList)), 'showName', 'id');
$this->assign('detail', $listInfo);
$this->assign('options', $options);
$this->display('add');
} elseif (IS_POST) {
$postData = I('post.');
$postData['hide'] = isset($postData['hide']) ? 1 : 0;
$res = D('ApiMenu')->where(array('id' => $postData['id']))->save($postData);
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('编辑成功');
}
}
}
public function del() {
$id = I('post.id');
$childNum = D('ApiMenu')->where(array('fid' => $id))->count();
if ($childNum) {
$this->ajaxError("当前菜单存在子菜单,不可以被删除!");
} else {
D('ApiMenu')->where(array('id' => $id))->delete();
$this->ajaxSuccess('编辑成功');
}
}
}

View File

@ -0,0 +1,208 @@
<?php
namespace Admin\Controller;
/**
* 权限管理控制器
* @since 2016-01-16
* @author zhaoxiang <zhaoxiang051405@outlook.com>
*/
class PermissionController extends BaseController {
public function index() {
$listInfo = D('ApiAuthGroup')->select();
$this->assign('list', $listInfo);
$this->display();
}
public function add() {
if (IS_POST) {
$res = D('ApiAuthGroup')->add(I('post.'));
if ($res === false) {
$this->ajaxError(L('_OPERATION_FAIL_'));
} else {
$this->ajaxSuccess(L('_OPERATION_SUCCESS_'));
}
} else {
$this->display();
}
}
public function close() {
$id = I('post.id');
if ($id == C('ADMIN_GROUP')) {
$this->ajaxError(L('_VALID_ACCESS_'));
}
$res = D('ApiAuthGroup')->where(array('id' => $id))->save(array('status' => 0));
if ($res === false) {
$this->ajaxError(L('_OPERATION_FAIL_'));
} else {
$this->ajaxSuccess(L('_OPERATION_SUCCESS_'));
}
}
public function open() {
$id = I('post.id');
$res = D('ApiAuthGroup')->where(array('id' => $id))->save(array('status' => 1));
if ($res === false) {
$this->ajaxError(L('_OPERATION_FAIL_'));
} else {
$this->ajaxSuccess(L('_OPERATION_SUCCESS_'));
}
}
public function edit() {
if (IS_GET) {
$detail = D('ApiAuthGroup')->where(array('id' => I('get.id')))->find();
$this->assign('detail', $detail);
$this->display('add');
} elseif (IS_POST) {
$res = D('ApiAuthGroup')->where(array('id' => I('post.id')))->save(I('post.'));
if ($res === false) {
$this->ajaxError(L('_OPERATION_FAIL_'));
} else {
$this->ajaxSuccess(L('_OPERATION_SUCCESS_'));
}
} else {
$this->ajaxError(L('_ERROR_ACTION_'));
}
}
public function del() {
$id = I('post.id');
if ($id == C('ADMIN_GROUP')) {
$this->error(L('_VALID_ACCESS_'));
}
$res = D('ApiAuthGroup')->where(array('id' => $id))->delete();
if ($res === false) {
$this->ajaxError(L('_OPERATION_FAIL_'));
} else {
$this->ajaxSuccess(L('_OPERATION_SUCCESS_'));
}
}
/**
* 将管理员加入组的组列表显示
*/
public function group() {
if (IS_POST) {
$data = I('post.');
$groupAccess = array_keys($data['groupAccess']);
$groupAccess = implode(',', $groupAccess);
$oldArr = D('ApiAuthGroupAccess')->where(array('uid' => $data['uid']))->find();
if ($oldArr) {
$insert = D('ApiAuthGroupAccess')->where(array('uid' => $data['uid']))->save(array('groupId' => $groupAccess));
} else {
$insert = D('ApiAuthGroupAccess')->add(array('uid' => $data['uid'], 'groupId' => $groupAccess));
}
if ($insert) {
$this->ajaxSuccess(L('_OPERATION_SUCCESS_'));
} else {
$this->ajaxError(L('_OPERATION_FAIL_'));
}
} elseif (IS_GET) {
$uid = I('get.uid');
$groupAccess = D('ApiAuthGroupAccess')->where(array('uid' => $uid))->find();
$groupAccess = explode(',', $groupAccess['groupId']);
$allGroup = D('ApiAuthGroup')->select();
$this->assign('allGroup', $allGroup);
$this->assign('groupAccess', $groupAccess);
$this->display();
} else {
$this->ajaxError('非法操作');
}
}
/**
* 显示当前组下面全部的用户
*/
public function member() {
$groupId = I('get.group_id');
if ($groupId) {
$uidArr = array();
$allGroups = D('ApiAuthGroupAccess')->select();
foreach ($allGroups as $allGroup) {
$gidArr = explode(',', $allGroup['groupId']);
if (in_array($groupId, $gidArr)) {
$uidArr[] = $allGroup['uid'];
}
}
if (!empty($uidArr)) {
$res = D('ApiUser')->where(array('api_user.id' => array('in', $uidArr)))->join('api_user_data on api_user.id = api_user_data.uid', 'left')->select();
} else {
$res = array();
}
$this->assign('list', $res);
$this->display();
} else {
$this->ajaxError('非法操作');
}
}
/**
* 删除指定组下面的指定用户
*/
public function delMember() {
if (IS_POST) {
$uid = I('post.uid');
$groupId = I('post.groupId');
$oldInfo = D('ApiAuthGroupAccess')->where(array('uid' => $uid))->find();
$oldGroupArr = explode(',', $oldInfo['groupId']);
$key = array_search($groupId, $oldGroupArr);
unset($oldGroupArr[$key]);
$newData = implode(',', $oldGroupArr);
$res = D('ApiAuthGroupAccess')->where(array('uid' => $uid))->save(array('groupId' => $newData));
if ($res === false) {
$this->ajaxError(L('_OPERATION_FAIL_'));
} else {
$this->ajaxSuccess(L('_OPERATION_SUCCESS_'));
}
} else {
$this->ajaxError('非法操作');
}
}
/**
* 当前用户组权限节点配置
*/
public function rule() {
if (IS_POST) {
$postData = I('post.');
$needAdd = array();
$has = D('ApiAuthRule')->where(array('groupId' => $postData['groupId']))->select();
$hasRule = array_column($has, 'url');
$needDel = array_flip($hasRule);
foreach ($postData['rule'] as $key => $value) {
if (!empty($value)) {
if (!in_array($value, $hasRule)) {
$data['url'] = $value;
$data['groupId'] = $postData['groupId'];
$needAdd[] = $data;
} else {
unset($needDel[$value]);
}
}
}
if (count($needAdd)) {
D('ApiAuthRule')->addAll($needAdd);
}
if (count($needDel)) {
$urlArr = array_keys($needDel);
D('ApiAuthRule')->where(array('groupId' => $postData['groupId'], 'url' => array('in', $urlArr)))->delete();
}
$this->ajaxSuccess('操作成功');
} elseif (IS_GET) {
$groupId = I('get.group_id');
$has = D('ApiAuthRule')->where(array('groupId' => $groupId))->select();
$hasRule = array_column($has, 'url');
$originList = D('ApiMenu')->order('sort asc')->select();
$list = listToTree($originList);
$this->assign('hasRule', $hasRule);
$this->assign('list', $list);
$this->display();
} else {
$this->ajaxError('非法操作');
}
}
}

View File

@ -0,0 +1,91 @@
<?php
/**
* 用户管理控制器
* @since 2016-01-21
* @author zhaoxiang <zhaoxiang051405@outlook.com>
*/
namespace Admin\Controller;
class UserController extends BaseController {
public function index() {
$listInfo = D('ApiUser')->select();
$userData = D('ApiUserData')->select();
$userData = $this->buildArrByNewKey($userData, 'uid');
foreach ($listInfo as $key => $value) {
if ($userData) {
$listInfo[$key]['lastLoginIp'] = long2ip($userData[$value['id']]['lastLoginIp']);
$listInfo[$key]['loginTimes'] = $userData[$value['id']]['loginTimes'];
$listInfo[$key]['lastLoginTime'] = date('Y-m-d H:i:s', $userData[$value['id']]['lastLoginTime']);
}
}
$this->assign('list', $listInfo);
$this->display();
}
public function add() {
if (IS_POST) {
$data = I('post.');
$has = D('ApiUser')->where(array('username' => $data['username']))->count();
if ($has) {
$this->ajaxError('用户名已经存在,请重设!');
}
$data['password'] = user_md5($data['password']);
$data['regIp'] = get_client_ip(1);
$data['regTime'] = time();
$res = D('ApiUser')->add($data);
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
} else {
$this->display();
}
}
public function close() {
$id = I('post.id');
$isAdmin = isAdministrator($id);
if ($isAdmin) {
$this->ajaxError('超级管理员不可以被操作');
}
$res = D('ApiUser')->where(array('id' => $id))->save(array('status' => 0));
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('操作成功');
}
}
public function open() {
$id = I('post.id');
$isAdmin = isAdministrator($id);
if ($isAdmin) {
$this->ajaxError('超级管理员不可以被操作');
}
$res = D('ApiUser')->where(array('id' => $id))->save(array('status' => 1));
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('操作成功');
}
}
public function del() {
$id = I('post.id');
$isAdmin = isAdministrator($id);
if ($isAdmin) {
$this->ajaxError('超级管理员不可以被操作');
}
$res = D('ApiUser')->where(array('id' => $id))->delete();
if ($res === false) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('操作成功');
}
}
}

View File

@ -0,0 +1,139 @@
<?php
/**
* 用户日志管理控制器
* @since 2016-01-25
* @author zhaoxiang <zhaoxiang051405@outlook.com>
*/
namespace Home\Controller;
class UserLogController extends HomeController{
public function index(){
$tableField = [
[
'name' => 'actionName',
'info' => '行为名称',
'type' => 'text'
],
[
'name' => 'nickName',
'info' => '执行者',
'type' => 'text'
],
[
'name' => 'actionTime',
'info' => '操作时间',
'type' => 'text'
],
[
'name' => 'actionIp',
'info' => '操作IP',
'type' => 'text'
],
[
'name' => 'action',
'info' => '操作',
'type' => 'rightButton'
]
];
$typeRule = [
'rightButton' => [
'action' => [
[
'desc' => '查看',
'href' => 'UserLog/show',
'class'=> 'secondary',
'param'=> '_id',
'icon' => 'eye',
'ajax' => 0,
'show' => ''
],
[
'desc' => '删除',
'href' => 'UserLog/del',
'class'=> 'danger',
'param'=> '_id',
'icon' => 'trash',
'ajax' => 2,
'show' => ''
]
]
]
];
$topList = [
'topButton' => [
[
'href' => 'UserLog/del',
'class'=> 'am-btn-danger del-all',
'title'=> '删除',
'icon' => 'trash',
'ajax' => 1,
],
]
];
$listNum = D('UserAction')->count();
$listLimit = $this->_getPage($listNum, 20);
$listInfo = D('UserAction')->order('actionTime desc')->limit($listLimit[0],$listLimit[1])->select();
foreach( $listInfo as $key => $value ){
$listInfo[$key]['actionTime'] = date('Y-m-d H:i:s', $value['actionTime']);
$listInfo[$key]['actionIp'] = long2ip($value['actionIp']);
}
$this->_prepareListInfo( $listInfo, $tableField, $typeRule );
$this->_prepareTopList( $topList );
$this->assign('tableField', $tableField);
$this->display();
}
public function show(){
if( IS_GET ){
$map['_id'] = I('get._id');
$res = D('UserAction')->where($map)->find();
$formData = [
[
'type' => 'text',
'info' => '行为名称:',
'attr' => 'disabled',
'value'=> $res['actionName'],
],
[
'type' => 'text',
'info' => '执行者:',
'attr' => 'disabled',
'value'=> $res['nickName'],
],
[
'type' => 'text',
'info' => '操作时间:',
'attr' => 'disabled',
'value'=> date('Y-m-d H:i:s',$res['actionTime']),
],
[
'type' => 'text',
'info' => '操作IP',
'attr' => 'disabled',
'value'=> long2ip($res['actionIp']),
],
[
'type' => 'textarea',
'info' => '受影响的URL',
'attr' => 'readonly',
'value'=> $res['actionUrl'],
],
[
'type' => 'textarea',
'info' => 'POST数据',
'attr' => 'readonly rows="5"',
'value'=> $res['data'],
],
];
$this->assign('formData', $formData);
$this->display();
}else{
$this->error( L('_ERROR_ACTION_') );
}
}
public function del(){
$this->_del('UserAction', $_REQUEST['_id'], 'UserLog/index');
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,23 @@
<?php
/**
*
* @since 2017/03/07 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Model;
class ApiAppModel extends BaseModel {
public function open( $where ){
return $this->where( $where )->save( array('app_status' => 1) );
}
public function close( $where ){
return $this->where( $where )->save( array('app_status' => 0) );
}
public function del( $where ){
return $this->where( $where )->delete();
}
}

View File

@ -0,0 +1,11 @@
<?php
/**
* 权限组包含和用户之间的关系表
* Author: 赵翔 <756958008@qq.com>
* Date: 16/1/16
*/
namespace Admin\Model;
class AuthGroupAccessModel extends BaseModel{
}

View File

@ -0,0 +1,13 @@
<?php
/**
* 权限组表模型
* Author: 赵翔 <756958008@qq.com>
* Date: 16/1/16
*/
namespace Admin\Model;
class AuthGroupModel extends BaseModel{
}

View File

@ -0,0 +1,12 @@
<?php
/**
* 权限和URL和Menu的关联表
* Author: 赵翔 <756958008@qq.com>
* Date: 16/1/16
*/
namespace Admin\Model;
class AuthRuleModel extends BaseModel{
}

View File

@ -0,0 +1,13 @@
<?php
/**
*
* @since 2017/04/01 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Model;
class ApiFieldsInfoModel extends BaseModel {
}

View File

@ -0,0 +1,13 @@
<?php
/**
*
* @since 2017/03/09 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Model;
class ApiFieldsModel extends BaseModel {
}

View File

@ -0,0 +1,23 @@
<?php
/**
*
* @since 2017/03/07 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Model;
class ApiListModel extends BaseModel {
public function open( $where ){
return $this->where( $where )->save( array('status' => 1) );
}
public function close( $where ){
return $this->where( $where )->save( array('status' => 0) );
}
public function del( $where ){
return $this->where( $where )->delete();
}
}

View File

@ -0,0 +1,11 @@
<?php
/**
* 权限和URL和Menu的关联表
* Author: 赵翔 <756958008@qq.com>
* Date: 16/1/16
*/
namespace Admin\Model;
class MenuModel extends BaseModel{
}

View File

@ -0,0 +1,10 @@
<?php
/**
* 用户信息查询
*/
namespace Admin\Model;
class UserDataModel extends BaseModel{
}

View File

@ -0,0 +1,10 @@
<?php
/**
* 用户操作
*/
namespace Admin\Model;
class UserModel extends BaseModel{
}

View File

@ -0,0 +1,15 @@
<?php
/**
*
* @since 2017/03/07 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Model;
use Think\Model;
class BaseModel extends Model {
Protected $autoCheckFields = false;
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,143 @@
<?php
namespace Admin\ORG;
/**
* 权限认证类
* @since 2016-01-16
* @author zhaoxiang <zhaoxiang051405@outlook.com>
*/
class Auth {
protected $_config = array(
'AUTH_ON' => true, //认证开关
'AUTH_TYPE' => 1, //认证方式1为时时认证2为登录认证。
'AUTH_GROUP' => 'ApiAuthGroup', //用户组数据表名
'AUTH_GROUP_ACCESS' => 'ApiAuthGroupAccess', //用户组明细表
'AUTH_RULE' => 'ApiAuthRule', //权限规则表
'AUTH_USER' => 'ApiUser' //用户信息表
);
public function __construct() {
$conf = C('AUTH_CONFIG');
if ($conf) {
$together = array_intersect_key($conf, $this->_config);
$this->_config = array_merge($this->_config, $together);
}
}
/**
* 权限检测
* @param string | array $name 获得权限 可以是字符串或数组或逗号分割,只要数组中有一个条件通过则通过
* @param string $uid 认证的用户id
* @param string $relation
* @return bool
*/
public function check($name, $uid, $relation = 'or') {
if (!$this->_config['AUTH_ON']) {
return true;
}
$authList = $this->getAuthList($uid);
if (is_string($name)) {
if (strpos($name, ',') !== false) {
$name = explode(',', $name);
} else {
$name = array($name);
}
}
$list = array();
foreach ($authList as $val) {
if (in_array($val, $name))
$list[] = $val;
}
if ($relation == 'or' && !empty($list)) {
return true;
}
$diff = array_diff($name, $list);
if ($relation == 'and' && empty($diff)) {
return true;
}
return false;
}
/**
* 获取用户组信息
* @param $uid
* @return mixed
*/
protected function getGroups($uid) {
static $groups = array();
if (isset($groups[$uid])) {
return $groups[$uid];
}
$ids = array();$userGroups = array();
$group_access = D($this->_config['AUTH_GROUP_ACCESS'])->where(array('uid' => $uid))->find();
if($group_access){
$groupInfoArr = D($this->_config['AUTH_GROUP'])->where(array('id' => array('in', $group_access['groupId'])))->select();
foreach ($groupInfoArr as $value) {
if ($value['status'] == 1) {
$ids[] = $value['id'];
$userGroups[] = $value;
}
}
}
$groups[$uid]['detail'] = $userGroups; //包含组全部信息
$groups[$uid]['id'] = $ids; //只包含组ID信息
return $groups[$uid];
}
/**
* 获取权限列表
* @param $uid
* @return array
*/
public function getAuthList($uid) {
static $_authList = array();
if (isset($_authList[$uid])) {
return $_authList[$uid];
}
if (isset($_SESSION[$uid]['_AUTH_LIST_'])) {
return $_SESSION[$uid]['_AUTH_LIST_'];
}
$groups = $this->getGroups($uid);
if (empty($groups['id'])) {
$_authList[$uid] = array();
return array();
}
$rules = D($this->_config['AUTH_RULE'])->where(array(
'groupId' => array('in', $groups['id']),
'status' => 1
))->select();
$rules = array_column($rules, 'url');
$rules = array_unique($rules);
if (empty($rules)) {
$_authList[$uid] = array();
return array();
}
$authList = array();
foreach ($rules as $r) {
$authList[] = strtolower($r);
}
$_authList[$uid] = $authList;
if ($this->_config['AUTH_TYPE'] == 2) {
$_SESSION[$uid]['_AUTH_LIST_'] = $authList;
}
return $_authList[$uid];
}
}

View File

@ -0,0 +1,33 @@
<?php
if(C('LAYOUT_ON')) {
echo '{__NOLAYOUT__}';
}
?>
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title><?php echo C('APP_NAME') ?> - 系统发生错误</title>
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://staticfile.qnssl.com/semantic-ui/2.1.6/semantic.min.css">
<script src="https://staticfile.qnssl.com/semantic-ui/2.1.6/semantic.min.js"></script>
</head>
<body>
<div class="ui very padded piled red text container segment" style="margin-top:3%; max-width: none !important;">
<h1 class="ui orange header huge"><i class="warning sign icon"></i></h1>
<h2 class="ui header huge"><?php echo strip_tags($e['message']);?></h2>
<?php if(isset($e['file'])) {?>
<h4>错误位置</h4>
<p>FILE: <?php echo $e['file'] ;?> &#12288;LINE: <?php echo $e['line'];?></p>
<?php }?>
<?php if(isset($e['trace'])) {?>
<h4>TRACE</h4>
<p><?php echo nl2br($e['trace']);?></p>
<?php }?>
<div class="ui clearing divider"></div>
<div class="ui right aligned container">
<p><a href=""><?php echo C('APP_NAME') ?></a><sup><?php echo C('APP_VERSION') ?></sup> { Fast & Simple API Framework } -- [ MANAGE YOUR API EASY ]</p>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,63 @@
<?php
if(C('LAYOUT_ON')) {
echo '{__NOLAYOUT__}';
}
?>
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title><?php echo C('APP_NAME') ?> - 跳转提示</title>
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://staticfile.qnssl.com/semantic-ui/2.1.6/semantic.min.css">
<script src="https://staticfile.qnssl.com/semantic-ui/2.1.6/semantic.min.js"></script>
</head>
<body>
<div class="ui card" style="text-align:center;width:40%;position: fixed;top: 20%;left: 30%">
<?php if(isset($message)) {?>
<div class="ui green inverted segment" style="margin: 0px;">
<i class="ui check circle icon massive"></i>
</div>
<?php }else{?>
<div class="ui red inverted segment" style="margin: 0px;">
<i class="ui remove circle icon massive"></i>
</div>
<?php }?>
<div class="content" style="line-height: 2em">
<?php if(isset($message)) {?>
<span class="header"><?php echo($message); ?></span>
<?php }else{?>
<span class="header"><?php echo($error); ?></span>
<?php }?>
<div class="meta">
将在<span id="left"><?php echo($waitSecond); ?></span>S后自动跳转
</div>
</div>
<span style="display: none" id="href"><?php echo($jumpUrl); ?></span>
<div class="ui bottom attached indicating progress" id="amanege-bar">
<div class="bar"></div>
</div>
</div>
</body>
<script type="text/javascript">
(function(){
var wait = 0,left = $('#left').text();
var href = $('#href').text();
var each = 100/left;
var interval = setInterval(function(){
wait = wait + each;
left = left - 1;
if(wait > 100) {
location.href = href;
clearInterval(interval);
return ;
}
$('#left').text(left);
$('#amanege-bar').progress({
percent: wait
});
}, 1000);
})();
</script>
</html>

View File

@ -0,0 +1,182 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>接口管理 - 新增接口</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<div class="layui-form-item">
<label class="layui-form-label">接口名称</label>
<div class="layui-input-block">
<input type="text" name="apiName" required value="{:(isset($detail['apiName'])?$detail['apiName']:'')}" lay-verify="required" placeholder="请输入应用名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">请求方式</label>
<div class="layui-input-inline">
<select name="method">
<switch name="detail['method']" >
<case value="0" break="1">
<option value="1">POST</option>
<option value="2">GET</option>
<option value="0" selected>不限</option>
</case>
<case value="1" break="1">
<option value="1" selected>POST</option>
<option value="2">GET</option>
<option value="0">不限</option>
</case>
<case value="2" break="1">
<option value="1">POST</option>
<option value="2" selected>GET</option>
<option value="0">不限</option>
</case>
<default />
<option value="1">POST</option>
<option value="2">GET</option>
<option value="0">不限</option>
</switch>
</select>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">接口映射</label>
<div class="layui-input-inline">
<input name="hash" value="{$detail['hash']}" readonly class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">系统自动生成,不允许修改</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">AccessToken</label>
<div class="layui-input-inline">
<select name="accessToken">
<switch name="detail['accessToken']" >
<case value="0" break="1">
<option value="1">验证Token</option>
<option value="0" selected>忽略Token</option>
</case>
<case value="1" break="1">
<option value="1" selected>验证Token</option>
<option value="0">忽略Token</option>
</case>
<default />
<option value="1">验证Token</option>
<option value="0">忽略Token</option>
</switch>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">用户登录</label>
<div class="layui-input-inline">
<select name="needLogin">
<switch name="detail['needLogin']" >
<case value="0" break="1">
<option value="1">验证登录</option>
<option value="0" selected>忽略登录</option>
</case>
<case value="1" break="1">
<option value="1" selected>验证登录</option>
<option value="0">忽略登录</option>
</case>
<default />
<option value="1">验证登录</option>
<option value="0">忽略登录</option>
</switch>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">测试模式</label>
<div class="layui-input-inline">
<select name="isTest">
<switch name="detail['isTest']" >
<case value="0" break="1">
<option value="1">开启测试</option>
<option value="0" selected>关闭测试</option>
</case>
<case value="1" break="1">
<option value="1" selected>开启测试</option>
<option value="0">关闭测试</option>
</case>
<default />
<option value="0">关闭测试</option>
<option value="1">开启测试</option>
</switch>
</select>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">应用描述</label>
<div class="layui-input-block">
<textarea name="info" placeholder="请输入内容" class="layui-textarea">{:(isset($detail['info'])?$detail['info']:'')}</textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("edit")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
<else />
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("add")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</if>
</block>

View File

@ -0,0 +1,119 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>应用管理 - API列表</legend>
<div class="layui-field-box">
<span class="layui-btn layui-btn-normal api-add"><i class="layui-icon">&#xe608;</i> 新增</span>
<a class="layui-btn layui-btn-warm" href="{:U('/wikiList')}" target="_blank"><i class="layui-icon">&#xe641;</i> 接口文档</a>
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th width="10%">接口名称</th>
<th width="10%">接口映射</th>
<th width="10%">接口状态</th>
<th width="10%">请求方式</th>
<th width="20%">接口说明</th>
<th width="40%">操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['apiName']}</td>
<td>{$vo['hash']}</td>
<td>
<if condition="$vo['status']">
<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">生效</span>
<else />
<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>
</if>
</td>
<td>
<switch name="vo['method']" >
<case value="0" break="1">
<span style="border-radius: 2px;background-color: #009688;padding:5px 10px;color: #ffffff">不限</span>
</case>
<case value="1" break="1">
<span style="border-radius: 2px;background-color: #2F4056;padding:5px 10px;color: #ffffff">POST</span>
</case>
<case value="2" break="1">
<span style="border-radius: 2px;background-color: #01AAED;padding:5px 10px;color: #ffffff">GET</span>
</case>
</switch>
</td>
<td>{$vo['info']}</td>
<td>
<if condition="$vo['status']">
<span class="layui-btn layui-btn-danger confirm" data-info="你确定禁用当前API么" data-id="{$vo['id']}" data-url="{:U('close')}">禁用</span>
<else />
<span class="layui-btn confirm" data-info="你确定启用当前API么" data-id="{$vo['id']}" data-url="{:U('open')}">启用</span>
</if>
<span data-url="{:U('FieldsManage/request', array('hash' => $vo['hash']))}" class="layui-btn field layui-btn-primary">请求参数</span>
<span data-url="{:U('edit', array('id' => $vo['id']))}" class="layui-btn edit layui-btn-normal">编辑</span>
<span data-url="{:U('FieldsManage/response', array('hash' => $vo['hash']))}" class="layui-btn field layui-btn-warm">返回参数</span>
<span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前API么" data-url="{:U('del')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.api-add').on('click', function () {
layer.open({
type: 2,
area: ['60%', '80%'],
maxmin: true,
content: '{:U("add")}'
});
});
$('.edit').on('click', function () {
var ownObj = $(this);
layer.open({
type: 2,
area: ['60%', '80%'],
maxmin: true,
content: ownObj.attr('data-url')
});
});
$('.field').on('click', function () {
var ownObj = $(this);
layer.open({
type: 2,
area: ['90%', '90%'],
maxmin: true,
content: ownObj.attr('data-url')
});
});
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1,101 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>应用管理 - 新增应用</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<div class="layui-form-item">
<label class="layui-form-label">应用名称</label>
<div class="layui-input-block">
<input type="text" name="app_name" required value="{:(isset($detail['app_name'])?$detail['app_name']:'')}" lay-verify="required" placeholder="请输入应用名称" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">AppId</label>
<div class="layui-input-inline" style="width: 300px;">
<input name="app_id" value="{$detail['app_id']}" readonly class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">系统自动生成,不允许修改</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">AppSecret</label>
<div class="layui-input-inline" style="width: 300px;">
<input name="app_secret" value="{$detail['app_secret']}" readonly class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">系统自动生成,不允许修改</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">应用描述</label>
<div class="layui-input-block">
<textarea name="app_info" placeholder="请输入内容" class="layui-textarea">{:(isset($detail['app_info'])?$detail['app_info']:'')}</textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("edit")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
<else />
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("add")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</if>
</block>

View File

@ -0,0 +1,95 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>应用管理 - 应用列表</legend>
<div class="layui-field-box">
<span class="layui-btn layui-btn-normal api-add"><i class="layui-icon">&#xe608;</i> 新增</span>
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th>应用名称</th>
<th>AppId</th>
<th>AppSecret</th>
<th>应用说明</th>
<th>应用状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['app_name']}</td>
<td>{$vo['app_id']}</td>
<td>{$vo['app_secret']}</td>
<td>{$vo['app_info']}</td>
<td>
<if condition="$vo['app_status']">
<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">生效</span>
<else />
<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>
</if>
</td>
<td>
<if condition="$vo['app_status']">
<span class="layui-btn layui-btn-danger confirm" data-info="你确定禁用当前APP么" data-id="{$vo['id']}" data-url="{:U('close')}">禁用</span>
<else />
<span class="layui-btn confirm" data-info="你确定启用当前APP么" data-id="{$vo['id']}" data-url="{:U('open')}">启用</span>
</if>
<span data-url="{:U('edit', array('id' => $vo['id']))}" class="layui-btn edit layui-btn-normal">编辑</span>
<span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前APP么" data-url="{:U('del')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.api-add').on('click', function () {
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: '{:U("add")}'
});
});
$('.edit').on('click', function () {
var ownObj = $(this);
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: ownObj.attr('data-url')
});
});
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1,129 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>接口管理 - {:(I('get.id')?'编辑':'新增')}{:(I('get.type') == 1?'返回':'请求')}字段</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<input type="hidden" name="hash" value="{:(isset($detail['hash'])?$detail['hash']:I('get.hash'))}">
<input type="hidden" name="type" value="{:(isset($detail['type'])?$detail['type']:I('get.type'))}">
<div class="layui-form-item">
<label class="layui-form-label">字段名称</label>
<div class="layui-input-block">
<input type="text" name="showName" required value="{:(isset($detail['showName'])?$detail['showName']:'')}" lay-verify="required" placeholder="请输入字段名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据类型</label>
<div class="layui-input-inline">
<select name="dataType">
<volist name="dataType" id="vo">
<if condition="(isset($detail['dataType'])) AND ($key eq $detail['dataType'])">
<option value="{$key}" selected>{$vo}</option>
<else />
<option value="{$key}">{$vo}</option>
</if>
</volist>
</select>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">默认值</label>
<div class="layui-input-block">
<input name="default" value="{$detail['default']}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否必填</label>
<div class="layui-input-block">
<if condition="(isset($detail['isMust'])) AND ($detail['isMust'] eq 0) ">
<input type="radio" name="isMust" value="1" title="必填">
<input type="radio" name="isMust" value="0" title="不必填" checked>
<else />
<input type="radio" name="isMust" value="1" title="必填" checked>
<input type="radio" name="isMust" value="0" title="不必填">
</if>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">规则细节</label>
<div class="layui-input-block">
<textarea name="range" placeholder="请输入符合要求的JSON字符串" class="layui-textarea">{:(isset($detail['range'])?$detail['range']:'')}</textarea>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">字段说明</label>
<div class="layui-input-block">
<textarea name="info" placeholder="请输入内容" class="layui-textarea">{:(isset($detail['info'])?$detail['info']:'')}</textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button onclick="history.go(-1);" class="layui-btn layui-btn-primary">返回</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("edit")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
location.href = "{:(I('get.type') == 1?U('response', array('hash' => $detail['hash'])):U('request', array('hash' => $detail['hash'])))}";
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
<else />
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("add")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
location.href = "{:(I('get.type') == 1?U('response', array('hash' => I('get.hash'))):U('request', array('hash' => I('get.hash'))))}";
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</if>
</block>

View File

@ -0,0 +1,61 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>接口管理 - {:($type == 1?'返回':'请求')}字段列表</legend>
<div class="layui-field-box">
<a class="layui-btn layui-btn-normal" href='{:U("add")}'><i class="layui-icon">&#xe608;</i> 新增</a>
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th>字段名称</th>
<th>字段说明</th>
<th width="150px">操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['field']}</td>
<td>{$vo['info']}</td>
<td>
<a href="{:U('edit', array('id' => $vo['id']))}" class="layui-btn layui-btn-normal">编辑</a>
<span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前字段么?" data-url="{:U('del')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1,94 @@
<extend name="Public/base" />
<block name="main">
<link rel="stylesheet" href="__PUBLIC__/jsonFormater/jsonFormater.css">
<script type="text/javascript" src="__PUBLIC__/jsonFormater/jsonFormater.js"></script>
<fieldset class="layui-elem-field">
<legend>接口管理 - 返回字段[批量覆盖]</legend>
<div class="layui-field-box">
<form class="layui-form">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<input type="hidden" name="hash" value="{:(isset($detail['hash'])?$detail['hash']:I('get.hash'))}">
<input type="hidden" name="type" value="{:(isset($detail['type'])?$detail['type']:I('get.type'))}">
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">数据模版</label>
<div class="layui-input-block">
<textarea name="jsonStr" required id="RawJson" rows="7" placeholder="请输入内容" class="layui-textarea"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<span class="layui-btn layui-btn-danger" id="format">JSON格式化</span>
<span class="layui-btn layui-btn-normal" id="collapseAll">全部收起</span>
<span class="layui-btn layui-btn-warm" id="expandAll">全部展开</span>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">格式化数据</label>
<div class="layui-input-block">
<pre style="max-height: 300px;overflow: auto;" class="layui-code" id="Canvas"></pre>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button onclick="history.go(-1);" class="layui-btn layui-btn-primary">返回</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
$(document).ready(function () {
var format = function () {
var options = {
dom: '#Canvas',
isCollapsible: true,
quoteKeys: true,
tabSize: 2,
imgCollapsed: "__PUBLIC__/images/jsonFormater/Collapsed.gif",
imgExpanded: "__PUBLIC__/images/jsonFormater/Expanded.gif"
};
window.jf = new JsonFormater(options);
jf.doFormat($('#RawJson').val());
};
$('#format').click(function () {
format();
});
$('#expandAll').click(function () {
window.jf.expandAll();
});
$('#collapseAll').click(function () {
window.jf.collapseLevel(2);
});
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("upload")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
location.href = "{:(I('get.type') == 1?U('response', array('hash' => I('get.hash'))):U('request', array('hash' => I('get.hash'))))}";
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
});
</script>
</block>

View File

@ -0,0 +1,129 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>接口管理 - {:(I('get.id')?'编辑':'新增')}{:(I('get.type') == 1?'返回':'请求')}字段</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<input type="hidden" name="hash" value="{:(isset($detail['hash'])?$detail['hash']:I('get.hash'))}">
<input type="hidden" name="type" value="{:(isset($detail['type'])?$detail['type']:I('get.type'))}">
<div class="layui-form-item">
<label class="layui-form-label">字段名称</label>
<div class="layui-input-block">
<input type="text" name="showName" required value="{:(isset($detail['showName'])?$detail['showName']:'')}" lay-verify="required" placeholder="请输入字段名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据类型</label>
<div class="layui-input-inline">
<select name="dataType">
<volist name="dataType" id="vo">
<if condition="(isset($detail['dataType'])) AND ($key eq $detail['dataType'])">
<option value="{$key}" selected>{$vo}</option>
<else />
<option value="{$key}">{$vo}</option>
</if>
</volist>
</select>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">默认值</label>
<div class="layui-input-block">
<input name="default" value="{$detail['default']}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否必填</label>
<div class="layui-input-block">
<if condition="(isset($detail['isMust'])) AND ($detail['isMust'] eq 0) ">
<input type="radio" name="isMust" value="1" title="必填">
<input type="radio" name="isMust" value="0" title="不必填" checked>
<else />
<input type="radio" name="isMust" value="1" title="必填" checked>
<input type="radio" name="isMust" value="0" title="不必填">
</if>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">规则细节</label>
<div class="layui-input-block">
<textarea name="range" placeholder="请输入符合要求的JSON字符串" class="layui-textarea">{:(isset($detail['range'])?$detail['range']:'')}</textarea>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">字段说明</label>
<div class="layui-input-block">
<textarea name="info" placeholder="请输入内容" class="layui-textarea">{:(isset($detail['info'])?$detail['info']:'')}</textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button onclick="history.go(-1);" class="layui-btn layui-btn-primary">返回</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("edit")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
location.href = "{:(I('get.type') == 1?U('response', array('hash' => $detail['hash'])):U('request', array('hash' => $detail['hash'])))}";
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
<else />
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("add")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
location.href = "{:(I('get.type') == 1?U('response', array('hash' => I('get.hash'))):U('request', array('hash' => I('get.hash'))))}";
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</if>
</block>

View File

@ -0,0 +1,78 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>接口管理 - {:($type == 1?'返回':'请求')}字段列表</legend>
<div class="layui-field-box">
<a class="layui-btn layui-btn-normal" href='{:U("add", array("hash" => I("get.hash"), "type" => $type))}'><i class="layui-icon">&#xe608;</i> 新增</a>
<if condition="$type eq 1">
<a class="layui-btn layui-btn-warm" href='{:U("upload", array("hash" => I("get.hash"), "type" => $type))}'><i class="layui-icon">&#xe62f;</i> 上传</a>
</if>
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th>字段名称</th>
<th>数据类型</th>
<th>是否必须</th>
<th width="50px">默认值</th>
<th width="35%">字段说明</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['showName']}</td>
<td>
<span style="border-radius: 2px;background-color: #009688;padding:5px 10px;color: #ffffff">{$dataType[$vo['dataType']]}</span>
</td>
<td>
<if condition="$vo['isMust']">
<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">必须</span>
<else />
<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">不必须</span>
</if>
</td>
<td>{$vo['default']}</td>
<td>{$vo['info']}</td>
<td>
<a href="{:U('edit', array('id' => $vo['id'], 'type' => $type))}" class="layui-btn layui-btn-normal">编辑</a>
<span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前字段么?" data-url="{:U('del')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1,94 @@
<extend name="Public/base" />
<block name="main">
<link rel="stylesheet" href="__PUBLIC__/jsonFormater/jsonFormater.css">
<script type="text/javascript" src="__PUBLIC__/jsonFormater/jsonFormater.js"></script>
<fieldset class="layui-elem-field">
<legend>接口管理 - 返回字段[批量覆盖]</legend>
<div class="layui-field-box">
<form class="layui-form">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<input type="hidden" name="hash" value="{:(isset($detail['hash'])?$detail['hash']:I('get.hash'))}">
<input type="hidden" name="type" value="{:(isset($detail['type'])?$detail['type']:I('get.type'))}">
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">数据模版</label>
<div class="layui-input-block">
<textarea name="jsonStr" required id="RawJson" rows="7" placeholder="请输入内容" class="layui-textarea"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<span class="layui-btn layui-btn-danger" id="format">JSON格式化</span>
<span class="layui-btn layui-btn-normal" id="collapseAll">全部收起</span>
<span class="layui-btn layui-btn-warm" id="expandAll">全部展开</span>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">格式化数据</label>
<div class="layui-input-block">
<pre style="max-height: 300px;overflow: auto;" class="layui-code" id="Canvas"></pre>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button onclick="history.go(-1);" class="layui-btn layui-btn-primary">返回</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
$(document).ready(function () {
var format = function () {
var options = {
dom: '#Canvas',
isCollapsible: true,
quoteKeys: true,
tabSize: 2,
imgCollapsed: "__PUBLIC__/images/jsonFormater/Collapsed.gif",
imgExpanded: "__PUBLIC__/images/jsonFormater/Expanded.gif"
};
window.jf = new JsonFormater(options);
jf.doFormat($('#RawJson').val());
};
$('#format').click(function () {
format();
});
$('#expandAll').click(function () {
window.jf.expandAll();
});
$('#collapseAll').click(function () {
window.jf.collapseLevel(2);
});
layui.use('form', function(){
var form = layui.form();
form.on('submit(formDemo)', function(data){
$.ajax({
type: "POST",
url: '{:U("upload")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
location.href = "{:(I('get.type') == 1?U('response', array('hash' => I('get.hash'))):U('request', array('hash' => I('get.hash'))))}";
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
});
</script>
</block>

View File

@ -0,0 +1,118 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>{:C('APP_NAME')}管理后台</title>
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
</head>
<body>
<!-- 布局容器 -->
<div class="layui-layout layui-layout-admin">
<!-- 头部 -->
<div class="layui-header">
<div class="layui-main">
<!-- logo -->
<a href="/" style="color: #c2c2c2; font-size: 18px; line-height: 60px;">{:C('APP_NAME')}管理后台</a>
<!-- 水平导航 -->
<ul class="layui-nav" style="position: absolute; top: 0; right: 0; background: none;">
<li class="layui-nav-item">
<a href="javascript:;">
进入前台
</a>
</li>
<li class="layui-nav-item">
<a href="javascript:;">
管理员
</a>
<dl class="layui-nav-child">
<dd class="api-add">
<a href="javascript:;">
个人信息
</a>
</dd>
<dd>
<a href="{:U('Login/logOut')}">
退出登录
</a>
</dd>
</dl>
</li>
</ul>
</div>
</div>
<!-- 侧边栏 -->
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<ul class="layui-nav layui-nav-tree" lay-filter="left-nav" style="border-radius: 0;">
</ul>
</div>
</div>
<!-- 主体 -->
<div class="layui-body">
<!-- 顶部切换卡 -->
<div class="layui-tab layui-tab-brief" lay-filter="top-tab" lay-allowClose="true" style="margin: 0;">
<ul class="layui-tab-title"></ul>
<div class="layui-tab-content"></div>
</div>
</div>
<!-- 底部 -->
<div class="layui-footer" style="text-align: center; line-height: 44px;">
<strong>Copyright &copy; 2014-{:date('Y')} <a href="">{:C('COMPANY_NAME')}</a>.</strong> All rights reserved.
</div>
</div>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script type="text/javascript">
layui.config({
base: '__PUBLIC__/js/'
});
layui.use(['cms'], function() {
var cms = layui.cms('left-nav', 'top-tab');
cms.addNav(JSON.parse('{:json_encode($list)}'), 0, 'id', 'fid', 'name', 'url');
cms.bind(60 + 41 + 20 + 44); //头部高度 + 顶部切换卡标题高度 + 顶部切换卡内容padding + 底部高度
cms.clickLI(0);
});
layui.use(['layer'], function() {
$('.api-add').on('click', function () {
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: '{:U("Login/changeUser")}'
});
});
var updateTime = '{$userInfo["updateTime"]}';
if( updateTime == 0 ){
layer.open({
title: '初次登陆请重置密码!',
type: 2,
area: ['60%', '60%'],
maxmin: true,
closeBtn:0,
content: '{:U("Login/changeUser")}'
});
}else{
var nickname = '{$userInfo["nickname"]}';
if( !nickname ){
layer.open({
title: '初次登陆请补充真实姓名!',
type: 2,
area: ['60%', '60%'],
maxmin: true,
closeBtn:0,
content: '{:U("Login/changeUser")}'
});
}
}
});
</script>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Welcome
</body>
</html>

View File

@ -0,0 +1,162 @@
<extend name="Public/base" />
<block name="main">
<script type="text/javascript" src="__PUBLIC__/dataTable/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/css/dataTable.css">
<fieldset class="layui-elem-field">
<legend>日志列表</legend>
<div class="layui-field-box">
<form class="layui-form" id="form-admin-add" action="">
<div class="layui-form-item">
<div class="layui-inline">
<select name="type">
<option value="">请选择查询方式</option>
<option value="1">操作URL</option>
<option value="2">用户昵称</option>
<option value="3">用户ID</option>
</select>
</div>
<div class="layui-inline">
<div class="layui-input-inline" style="width: 300px;">
<input type="text" name="keyword" placeholder="请输入关键词" class="layui-input">
</div>
</div>
<div class="layui-inline">
<span class="layui-btn sub">查询</span>
</div>
</div>
</form>
<table class="layui-table" id="list-admin" lay-even>
<thead>
<tr>
<th>行为名称</th>
<th>用户ID</th>
<th>用户昵称</th>
<th>操作URL</th>
<th>执行时间</th>
<th>操作</th>
</tr>
</thead>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
/**
* 格式化时间戳
* @param fmt
* @returns {*}
* @constructor
*/
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
layui.use(['layer', 'form'], function() {
$(document).on('click', '.confirm', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
$(document).on('click', '.edit', function () {
var ownObj = $(this);
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: ownObj.attr('data-url')+'&id='+ownObj.attr('data-id')
});
});
var myFun = function (query) {
query = query || '';
return $('#list-admin').DataTable({
ordering: false,
autoWidth: false,
searching:false,
serverSide: true,
ajax: {
url:'{:U("ajaxGetIndex")}' + query,
type: 'POST',
dataSrc: function ( json ) {
if( json.code == 0 ){
parent.layer.msg(json.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}else{
return json.data;
}
}
},
columnDefs:[
{
"targets":4,
"render": function(data){
return new Date(data*1000).Format("yyyy-MM-dd hh:mm:ss");
}
},
{
"targets":5,
"render":function(data, type, row){
var returnStr = '';
returnStr += '<span class="layui-btn edit layui-btn-normal" ' +
'data-id="' + row.id +'" data-url="{:U(\'showDetail\')}">查看</span>';
returnStr += '<span class="layui-btn layui-btn-danger confirm" ' +
'data-id="' + row.id +'" data-info="你确定删除当前菜单么?" data-url="{:U(\'del\')}">删除</span>';
return returnStr;
}
}
],
iDisplayLength : 20,
aLengthMenu : [20, 30, 50],
columns: [
{"data": "actionName"},
{"data": "uid"},
{"data": "nickname" },
{"data": "url" },
{"data": "addTime" },
{"data": null }
]
});
};
var myTable = myFun();
$('.sub').on("click", function(){
myTable.destroy();
myTable = myFun('&'+ $('#form-admin-add').serialize());
});
});
</script>
</block>

View File

@ -0,0 +1,51 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>日志详情</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<div class="layui-form-item">
<label class="layui-form-label">行为名称</label>
<div class="layui-input-block">
<input disabled type="text" value="{:(isset($detail['actionName'])?$detail['actionName']:'')}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">操作用户ID</label>
<div class="layui-input-block">
<input disabled type="text" value="{:(isset($detail['uid'])?$detail['uid']:'')}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">用户昵称</label>
<div class="layui-input-block">
<input disabled type="text" value="{:(isset($detail['nickname'])?$detail['nickname']:'')}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">操作时间</label>
<div class="layui-input-block">
<input disabled type="text" value="{:(isset($detail['addTime'])?date('Y-m-d H:i:s', $detail['addTime']):'')}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">操作URL</label>
<div class="layui-input-block">
<input disabled type="text" value="{:(isset($detail['url'])?$detail['url']:'')}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">请求数据</label>
<div class="layui-input-block">
<textarea disabled class="layui-textarea">{:(isset($detail['data'])?$detail['data']:'')}</textarea>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use('form', function(){});
</script>
</block>

View File

@ -0,0 +1,61 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>个人信息维护</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<div class="layui-form-item">
<label class="layui-form-label">账号名</label>
<div class="layui-input-block">
<input type="text" name="username" value="{$uname}" readonly class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">真实姓名</label>
<div class="layui-input-block">
<input type="text" name="nickname" value="" placeholder="请输入新的姓名,留空表示不修改" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">账号密码</label>
<div class="layui-input-block">
<input type="password" name="password" value="" placeholder="请输入新的密码,留空表示不修改" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("changeUser")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</block>

View File

@ -0,0 +1,118 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>{:C('APP_NAME')}管理后台</title>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/layui/css/layui.css" />
<style>
/* login */
.login-body {
background: url("__PUBLIC__/images/bg.png") repeat fixed;
}
.login-box {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 320px;
height: 241px;
max-height: 300px;
}
.login-body .login-box h3{
color: #444;
font-size: 22px;
text-align: center;
}
.login-box .layui-input[type='number'] {
display: inline-block;
width: 50%;
vertical-align: top;
}
.login-box img {
display: inline-block;
width: 46%;
height: 38px;
border: none;
vertical-align: top;
cursor: pointer;
margin-left: 4%;
}
.login-box button.btn-reset{
width: 95px;
}
.login-box button.btn-submit{
width: 190px;
}
.login-box .version{
font-size: 12px;
}
</style>
</head>
<body class="login-body">
<div class="login-box">
<form class="layui-form layui-form-pane">
<div class="layui-form-item">
<h3>{:C('APP_NAME')}管理后台&nbsp;<span class="version">{:C('APP_VERSION')}</span></h3>
</div>
<div class="layui-form-item">
<label class="layui-form-label">用户名:</label>
<div class="layui-input-inline">
<input type="text" name="username" required class="layui-input" lay-verify="username" placeholder="请输入用户名"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码:</label>
<div class="layui-input-inline">
<input type="password" name="password" required class="layui-input" lay-verify="password" placeholder="请输入密码"/>
</div>
</div>
<div class="layui-form-item">
<button type="reset" class="layui-btn btn-reset layui-btn-danger" >重置</button>
<button type="button" class="layui-btn btn-submit" lay-submit="" lay-filter="sub">立即登录</button>
</div>
</form>
</div>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script type="text/javascript">
layui.use(['form', 'layer'], function () {
var $ = layui.jquery,form = layui.form(),layer = layui.layer;
// 登录表单验证
form.verify({
username: function (value) {
if (value == "") {
return "请输入用户名";
}
},
password: function (value) {
if (value == "") {
return "请输入密码";
}
}
});
form.on('submit(sub)', function (data) {
$.post("{:U('Login/login')}",data.field,function(res){
if(res.code > 0){
layer.msg(res.msg,{time:1800},function(){
location.href = "{:U('Index/index')}";
});
}else{
layer.msg(res.msg,{time:1800});
$('#verify').click();
}
});
return false;
})
})
</script>
</body>
</html>

View File

@ -0,0 +1,109 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>菜单管理 - {:(isset($detail['id'])?'编辑':'新增')}菜单</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 菜单名称</label>
<div class="layui-input-block">
<input type="text" name="name" required value="{:(isset($detail['name'])?$detail['name']:'')}" lay-verify="required" placeholder="请输入菜单名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 父级菜单</label>
<div class="layui-input-block">
<select name="fid" lay-verify="">
<option value="0">顶级菜单</option>
<volist name="options" id="vo">
<option value="{$key}" {:($detail['fid'] == $key?'selected':'')}>{$vo}</option>
</volist>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 是否隐藏</label>
<div class="layui-input-block">
<input type="checkbox" name="hide" lay-skin="switch" lay-text="隐藏|显示" {:((isset($detail['hide']) && $detail['hide']==1)?'checked':'')}>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">菜单URL</label>
<div class="layui-input-block">
<input type="text" name="url" value="{:(isset($detail['url'])?$detail['url']:'')}" placeholder="请输入菜单URL" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">菜单排序</label>
<div class="layui-input-block">
<input type="text" name="sort" value="{:(isset($detail['sort'])?$detail['sort']:'')}" placeholder="请输入正整数,越大排名越靠后" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<if condition="isset($detail['id'])">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("edit")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
<else />
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("add")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</if>
</block>

View File

@ -0,0 +1,93 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>菜单管理 - 菜单列表</legend>
<div class="layui-field-box">
<span class="layui-btn layui-btn-normal api-add"><i class="layui-icon">&#xe608;</i> 新增</span>
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th>菜单名称</th>
<th>排序</th>
<th>菜单URL</th>
<th>隐藏</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['showName']}</td>
<td>{$vo['sort']}</td>
<td>{$vo['url']}</td>
<td>
<if condition="$vo['hide']">
<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">隐藏</span>
<else />
<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">显示</span>
</if>
</td>
<td>
<if condition="$vo['hide']">
<span class="layui-btn confirm" data-info="你确定显示当前菜单么?" data-id="{$vo['id']}" data-url="{:U('open')}">显示</span>
<else />
<span class="layui-btn layui-btn-danger confirm" data-info="你确定隐藏当前菜单么?" data-id="{$vo['id']}" data-url="{:U('close')}">隐藏</span>
</if>
<span data-url="{:U('edit', array('id' => $vo['id']))}" class="layui-btn edit layui-btn-normal">编辑</span>
<span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前菜单么?" data-url="{:U('del')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.api-add').on('click', function () {
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: '{:U("add")}'
});
});
$('.edit').on('click', function () {
var ownObj = $(this);
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: ownObj.attr('data-url')
});
});
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1,86 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>权限管理 - {:(isset($detail['id'])?'编辑':'新增')}权限组</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 权限组名称</label>
<div class="layui-input-block">
<input type="text" name="name" required value="{:(isset($detail['name'])?$detail['name']:'')}" lay-verify="required" placeholder="请输入权限组名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">权限组描述</label>
<div class="layui-input-block">
<textarea name="description" placeholder="请输入权限组描述" class="layui-textarea">{:(isset($detail['description'])?$detail['description']:'')}</textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<if condition="isset($detail['id'])">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("edit")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
<else />
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("add")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</if>
</block>

View File

@ -0,0 +1,56 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>授权管理</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<input type="hidden" name="uid" value="{:I('get.uid')}">
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 请选择组</label>
<div class="layui-input-block">
<volist name="allGroup" id="vo">
<if condition="in_array($vo['id'], $groupAccess)">
<input type="checkbox" name="groupAccess[{$vo['id']}]" value="{$vo['id']}" title="{$vo['name']}" checked>
<else />
<input type="checkbox" name="groupAccess[{$vo['id']}]" value="{$vo['id']}" title="{$vo['name']}">
</if>
</volist>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("group")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</block>

View File

@ -0,0 +1,99 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>权限管理 - 权限组列表</legend>
<div class="layui-field-box">
<span class="layui-btn layui-btn-normal api-add"><i class="layui-icon">&#xe608;</i> 新增</span>
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th>权限组</th>
<th>描述</th>
<th>访问授权</th>
<th>成员授权</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['name']}</td>
<td>{$vo['description']}</td>
<td>
<span data-url="{:U('rule', array('group_id' => $vo['id']))}" class="layui-btn edit">访问授权</span>
</td>
<td>
<span data-url="{:U('member', array('group_id' => $vo['id']))}" class="layui-btn edit">成员授权</span>
</td>
<td>
<if condition="$vo['status']">
<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">启用</span>
<else />
<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>
</if>
</td>
<td>
<if condition="$vo['status']">
<span class="layui-btn layui-btn-danger confirm" data-info="你确定禁用当前权限组么?" data-id="{$vo['id']}" data-url="{:U('close')}">禁用</span>
<else />
<span class="layui-btn confirm" data-info="你确定启用当前权限组么?" data-id="{$vo['id']}" data-url="{:U('open')}">启用</span>
</if>
<span data-url="{:U('edit', array('id' => $vo['id']))}" class="layui-btn edit layui-btn-normal">编辑</span>
<span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前权限组么?" data-url="{:U('del')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.api-add').on('click', function () {
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: '{:U("add")}'
});
});
$('.edit').on('click', function () {
var ownObj = $(this);
layer.open({
type: 2,
area: ['80%', '66%'],
maxmin: true,
content: ownObj.attr('data-url')
});
});
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1,73 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>权限管理 - 权限组成员列表</legend>
<div class="layui-field-box">
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th>用户账号</th>
<th>用户昵称</th>
<th>登录次数</th>
<th>最后登录时间</th>
<th>最后登录IP</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['username']}</td>
<td>{$vo['nickname']}</td>
<td>{:intval($vo['loginTimes'])}</td>
<td>{:(empty($vo['lastLoginTime'])?'该用户未曾登录过':date('Y-m-d H:i:s', $vo['lastLoginTime']))}</td>
<td>{:(empty($vo['lastLoginIp'])?'该用户未曾登录过':long2ip($vo['lastLoginIp']))}</td>
<td>
<if condition="$vo['status']">
<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">启用</span>
<else />
<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>
</if>
</td>
<td>
<span class="layui-btn layui-btn-danger confirm" data-uid="{$vo['uid']}" data-info="你确定踢出当前用户么?" data-url="{:U('delMember')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {uid:ownObj.attr('data-uid'),groupId:{:I("get.group_id")}},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1,74 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>权限管理 - 权限组细节配置</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<input type="hidden" name="groupId" value="{:I('get.group_id')}">
<volist name="list" id="vo">
<div class="layui-form-item">
<input lay-skin="primary" type="checkbox" lay-filter="admin-check" name="rule[{$vo['id']}]" value="{$vo['url']}" title="{$vo['name']}" {:(in_array($vo['url'], $hasRule)?'checked':'')}>
</div>
<if condition="count($vo['_child'])">
<div class="layui-form-item">
<div style="margin-left: 50px;">
<volist name="vo['_child']" id="child">
<input lay-skin="primary" type="checkbox" lay-filter="admin-check" fid="{$vo['url']}" name="rule[{$child['id']}]" value="{$child['url']}" title="{$child['name']}" {:(in_array($child['url'], $hasRule)?'checked':'')}>
<if condition="count($child['_child'])">
<div style="margin-left: 50px;">
<volist name="child['_child']" id="_child">
<input lay-skin="primary" type="checkbox" pid="{$vo['url']}" fid="{$child['url']}" name="rule[{$_child['id']}]" value="{$_child['url']}" title="{$_child['name']}" {:(in_array($_child['url'], $hasRule)?'checked':'')}>
</volist>
</div>
</if>
</volist>
</div>
</div>
</if>
</volist>
<div class="layui-form-item">
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('checkbox(admin-check)', function(data){
var $el = data.elem;
if( $el.checked ){
$('input[fid="'+data.elem.value+'"]').attr('checked','checked');
$('input[pid="'+data.elem.value+'"]').attr('checked','checked');
form.render();
}else{
$('input[fid="'+data.elem.value+'"]').removeAttr('checked');
$('input[pid="'+data.elem.value+'"]').removeAttr('checked');
form.render();
}
});
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("rule")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</block>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>{:C('APP_NAME')}管理后台</title>
<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<block name="myCss"></block>
</head>
<body>
<div style="margin: 15px;">
<block name="main"></block>
</div>
<block name="myScript"></block>
</body>
</html>

View File

@ -0,0 +1,95 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>用户管理 - {:(isset($detail['id'])?'编辑':'新增')}用户</legend>
<div class="layui-field-box">
<form class="layui-form" action="">
<if condition="isset($detail['id'])">
<input type="hidden" name="id" value="{$detail['id']}">
</if>
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 账号名</label>
<div class="layui-input-block">
<input type="text" name="username" required value="{:(isset($detail['username'])?$detail['username']:'')}" lay-verify="required" placeholder="请输入账号名" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 真实姓名</label>
<div class="layui-input-block">
<input type="text" name="nickname" required value="{:(isset($detail['nickname'])?$detail['nickname']:'')}" lay-verify="required" placeholder="请输入真实姓名" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span style="color:red">*</span> 用户密码</label>
<div class="layui-input-inline">
<input type="password" name="password" required lay-verify="required" value="{:(isset($detail['password'])?'':'123456')}" placeholder="请输入密码" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">默认:123456</div>
<div class="layui-input-block">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</fieldset>
</block>
<block name="myScript">
<if condition="isset($detail['id'])">
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("edit")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
<else />
<script>
layui.use('form', function(){
var form = layui.form();
form.on('submit(admin-form)', function(data){
$.ajax({
type: "POST",
url: '{:U("add")}',
data: data.field,
success: function(msg){
if( msg.code == 1 ){
parent.location.reload();
}else{
parent.layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
return false;
});
});
</script>
</if>
</block>

View File

@ -0,0 +1,97 @@
<extend name="Public/base" />
<block name="main">
<fieldset class="layui-elem-field">
<legend>用户管理 - 用户列表</legend>
<div class="layui-field-box">
<span class="layui-btn layui-btn-normal api-add"><i class="layui-icon">&#xe608;</i> 新增</span>
<table class="layui-table" lay-even>
<thead>
<tr>
<th>#</th>
<th>用户账号</th>
<th>用户昵称</th>
<th>登录次数</th>
<th>最后登录时间</th>
<th>最后登录IP</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<volist name="list" id="vo">
<tr>
<td>{$i}</td>
<td>{$vo['username']}</td>
<td>{$vo['nickname']}</td>
<td>{:intval($vo['loginTimes'])}</td>
<td>{:(empty($vo['lastLoginTime'])?'该用户未曾登录过':$vo['lastLoginTime'])}</td>
<td>{:(empty($vo['lastLoginIp'])?'该用户未曾登录过':$vo['lastLoginIp'])}</td>
<td>
<if condition="$vo['status']">
<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">启用</span>
<else />
<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>
</if>
</td>
<td>
<if condition="$vo['status']">
<span class="layui-btn layui-btn-danger confirm" data-info="你确定禁用当前用户么?" data-id="{$vo['id']}" data-url="{:U('close')}">禁用</span>
<else />
<span class="layui-btn confirm" data-info="你确定启用当前用户么?" data-id="{$vo['id']}" data-url="{:U('open')}">启用</span>
</if>
<span data-url="{:U('Permission/group', array('uid' => $vo['id']))}" class="layui-btn edit layui-btn-normal">授权</span>
<span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前菜单么?" data-url="{:U('del')}">删除</span>
</td>
</tr>
</volist>
</tbody>
</table>
</div>
</fieldset>
</block>
<block name="myScript">
<script>
layui.use(['layer'], function() {
$('.api-add').on('click', function () {
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: '{:U("add")}'
});
});
$('.edit').on('click', function () {
var ownObj = $(this);
layer.open({
type: 2,
area: ['60%', '60%'],
maxmin: true,
content: ownObj.attr('data-url')
});
});
$('.confirm').on('click', function () {
var ownObj = $(this);
layer.confirm(ownObj.attr('data-info'), {
btn: ['确定','取消'] //按钮
}, function(){
$.ajax({
type: "POST",
url: ownObj.attr('data-url'),
data: {id:ownObj.attr('data-id')},
success: function(msg){
if( msg.code == 1 ){
location.reload();
}else{
layer.msg(msg.msg, {
icon: 5,
shade: [0.6, '#393D49'],
time:1500
});
}
}
});
});
});
});
</script>
</block>

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,52 @@
<?php
/**
* 获取HTTP全部头信息
*/
if (!function_exists('apache_request_headers')) {
function apache_request_headers(){
$arh = array();
$rx_http = '/\AHTTP_/';
foreach ($_SERVER as $key => $val) {
if (preg_match($rx_http, $key)) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = explode('_', $arh_key);
if (count($rx_matches) > 0 and strlen($arh_key) > 2) {
foreach ($rx_matches as $ak_key => $ak_val)
$rx_matches[$ak_key] = ucfirst($ak_val);
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return $arh;
}
}
/**
* @param $url
* @param int $timeOut
* @return bool|mixed
*/
if (!function_exists('curlGet')) {
function curlGet($url, $timeOut = 10){
$oCurl = curl_init();
if (stripos($url, "https://") !== false) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1);
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($oCurl, CURLOPT_TIMEOUT, $timeOut);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if (intval($aStatus["http_code"]) == 200) {
return $sContent;
} else {
return false;
}
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,35 @@
<?php
return array(
'URL_MODEL' => 2,
'APP_VERSION' => 'v1.0',
'APP_NAME' => 'apiAdmin',
'USER_ADMINISTRATOR' => array(1,2),
'AUTH_KEY' => 'I&TC{pft>L,C`wFQ>&#ROW>k{Kxlt1>ryW(>r<#R',
'COMPANY_NAME' => 'ApiAdmin开发维护团队',
'URL_ROUTER_ON' => true,
'URL_ROUTE_RULES' => array(
'wiki/:hash' => 'Home/Wiki/apiField',
'api/:hash' => 'Home/Api/index',
'wikiList' => 'Home/Wiki/apiList',
'errorList' => 'Home/Wiki/errorCode',
'calculation' => 'Home/Wiki/calculation'
),
'LANG_SWITCH_ON' => true, // 开启语言包功能
'LANG_LIST' => 'zh-cn', // 允许切换的语言列表 用逗号分隔
'VAR_LANGUAGE' => 'l', // 默认语言切换变量
/* 数据库设置 */
'DB_TYPE' => 'mysql', // 数据库类型
'DB_HOST' => '127.0.0.1', // 服务器地址
'DB_NAME' => 'demo', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => '123456' // 密码
);

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,273 @@
# ************************************************************
# Sequel Pro SQL dump
# Version 4541
#
# http://www.sequelpro.com/
# https://github.com/sequelpro/sequelpro
#
# Host: 192.168.105.105 (MySQL 5.5.40-log)
# Database: rent
# Generation Time: 2017-04-15 12:45:48 +0000
# ************************************************************
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
# Dump of table api_app
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_app`;
CREATE TABLE `api_app` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`app_id` varchar(50) NOT NULL DEFAULT '' COMMENT '应用id',
`app_secret` varchar(50) NOT NULL DEFAULT '' COMMENT '应用密码',
`app_name` varchar(50) NOT NULL DEFAULT '' COMMENT '应用名称',
`app_status` tinyint(2) NOT NULL DEFAULT '1' COMMENT '应用状态0表示禁用1表示启用',
`app_info` tinytext NOT NULL COMMENT '应用说明',
PRIMARY KEY (`id`),
UNIQUE KEY `app_id` (`app_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='appId和appSecret表';
# Dump of table api_auth_group
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_auth_group`;
CREATE TABLE `api_auth_group` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL COMMENT '组名称',
`description` varchar(50) NOT NULL COMMENT '组描述',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '组状态为1正常为0禁用',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限组';
# Dump of table api_auth_group_access
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_auth_group_access`;
CREATE TABLE `api_auth_group_access` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`uid` mediumint(8) unsigned NOT NULL,
`groupId` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `uid` (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户和组的对应关系';
# Dump of table api_auth_rule
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_auth_rule`;
CREATE TABLE `api_auth_rule` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`url` char(80) NOT NULL DEFAULT '' COMMENT '规则唯一标识',
`groupId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '权限所属组的ID',
`auth` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '权限数值',
`status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态为1正常为0禁用',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限细节';
# Dump of table api_fields
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_fields`;
CREATE TABLE `api_fields` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fieldName` varchar(50) NOT NULL DEFAULT '' COMMENT '字段名称',
`hash` varchar(50) NOT NULL DEFAULT '' COMMENT '对应接口的唯一标识',
`dataType` tinyint(2) NOT NULL DEFAULT '0' COMMENT '数据类型来源于DataType类库',
`default` varchar(500) NOT NULL DEFAULT '' COMMENT '默认值',
`isMust` tinyint(2) NOT NULL DEFAULT '0' COMMENT '是否必须 0为不必须1为必须',
`range` varchar(500) NOT NULL DEFAULT '' COMMENT '范围Json字符串根据数据类型有不一样的含义',
`info` varchar(500) NOT NULL DEFAULT '' COMMENT '字段说明',
`type` tinyint(2) NOT NULL DEFAULT '0' COMMENT '字段用处0为request1为response',
`showName` varchar(50) NOT NULL DEFAULT '' COMMENT 'wiki显示用字段',
PRIMARY KEY (`id`),
KEY `hash` (`hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用于保存各个API的字段规则';
# Dump of table api_fields_info
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_fields_info`;
CREATE TABLE `api_fields_info` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一主键',
`field` varchar(50) NOT NULL DEFAULT '' COMMENT '字段名',
`info` varchar(300) NOT NULL DEFAULT '' COMMENT '字段说明',
PRIMARY KEY (`id`),
UNIQUE KEY `field` (`field`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='字段说明对应关系';
# Dump of table api_list
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_list`;
CREATE TABLE `api_list` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`apiName` varchar(50) NOT NULL DEFAULT '' COMMENT 'api索引保存了类和方法',
`hash` varchar(50) NOT NULL DEFAULT '' COMMENT 'api唯一标识',
`accessToken` tinyint(2) NOT NULL DEFAULT '1' COMMENT '是否需要认证AccessToken 1需要0不需要',
`needLogin` tinyint(2) NOT NULL DEFAULT '1' COMMENT '是否需要认证用户token 1需要 0不需要',
`status` tinyint(2) NOT NULL DEFAULT '1' COMMENT 'API状态0表示禁用1表示启用',
`method` tinyint(2) NOT NULL DEFAULT '2' COMMENT '请求方式0不限1Post2Get',
`info` varchar(500) NOT NULL DEFAULT '' COMMENT 'api中文说明',
`isTest` tinyint(2) NOT NULL DEFAULT '0' COMMENT '是否是测试模式0:生产模式1测试模式',
`returnStr` text COMMENT '返回数据示例',
PRIMARY KEY (`id`),
UNIQUE KEY `hash` (`hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用于维护接口信息';
# Dump of table api_menu
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_menu`;
CREATE TABLE `api_menu` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT '' COMMENT '菜单名',
`fid` int(11) NOT NULL COMMENT '父级菜单ID',
`url` varchar(50) NOT NULL DEFAULT '' COMMENT '链接',
`auth` tinyint(2) NOT NULL DEFAULT '0' COMMENT '访客权限',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
`hide` tinyint(2) NOT NULL DEFAULT '0' COMMENT '是否显示',
`icon` varchar(50) NOT NULL DEFAULT '' COMMENT '菜单图标',
`level` tinyint(2) NOT NULL DEFAULT '0' COMMENT '菜单认证等级',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='目录信息';
LOCK TABLES `api_menu` WRITE;
/*!40000 ALTER TABLE `api_menu` DISABLE KEYS */;
INSERT INTO `api_menu` (`id`, `name`, `fid`, `url`, `auth`, `sort`, `hide`, `icon`, `level`)
VALUES
(1,'欢迎页',0,'Index/welcome',0,0,0,'',0),
(2,'系统配置',0,'',0,1,0,'',0),
(3,'菜单维护',2,'Menu/index',0,0,0,'',0),
(4,'用户管理',2,'User/index',0,1,0,'',0),
(5,'权限管理',2,'Permission/index',0,2,0,'',0),
(6,'操作日志',2,'Log/index',0,3,0,'',0),
(7,'应用管理',0,'',0,2,0,'',0),
(8,'应用列表',7,'App/index',0,0,0,'',0),
(9,'接口列表',7,'ApiManage/index',0,1,0,'',0),
(10,'字段注解',7,'FieldsInfoManage/index',0,2,1,'',0),
(11,'首页',0,'Index/index',0,0,1,'',0),
(12,'新增菜单',3,'Menu/add',0,0,1,'',0),
(13,'编辑菜单',3,'Menu/edit',0,0,1,'',0),
(14,'隐藏菜单',3,'Menu/close',0,0,1,'',0),
(15,'显示菜单',3,'Menu/open',0,0,1,'',0),
(16,'删除菜单',3,'Menu/del',0,0,1,'',0),
(17,'新增用户',4,'User/add',0,0,1,'',0),
(18,'账号封停',4,'User/close',0,0,1,'',0),
(19,'账号解封',4,'User/open',0,0,1,'',0),
(20,'账号删除',4,'User/del',0,0,1,'',0),
(21,'编辑应用',8,'App/edit',0,0,1,'',0),
(22,'新增应用',8,'App/add',0,0,1,'',0),
(23,'启用应用',8,'App/open',0,0,1,'',0),
(24,'禁用应用',8,'App/close',0,0,1,'',0),
(25,'删除应用',8,'App/del',0,0,1,'',0),
(26,'新增接口',9,'ApiManage/add',0,0,1,'',0),
(27,'启用接口',9,'ApiManage/open',0,0,1,'',0),
(28,'禁用接口',9,'ApiManage/close',0,0,1,'',0),
(29,'编辑接口',9,'ApiManage/edit',0,0,1,'',0),
(30,'删除接口',9,'ApiManage/del',0,0,1,'',0),
(31,'返回字段编辑',9,'FieldsManage/response',0,0,1,'',0),
(32,'请求字段编辑',9,'FieldsManage/request',0,0,1,'',0),
(33,'新增字段',9,'FieldsManage/add',0,0,1,'',0),
(34,'字段编辑',9,'FieldsManage/edit',0,0,1,'',0),
(35,'批量上传返回字段',9,'FieldsManage/upload',0,0,1,'',0),
(36,'Ajax查询Log列表',6,'Log/ajaxGetIndex',0,0,1,'',0),
(37,'日志删除',6,'Log/del',0,0,1,'',0),
(38,'日志详情查看',6,'Log/showDetail',0,0,1,'',0),
(39,'添加权限组',5,'Permission/add',0,0,1,'',0),
(40,'禁用权限组',5,'Permission/close',0,0,1,'',0),
(41,'启用权限组',5,'Permission/open',0,0,1,'',0),
(42,'编辑权限组',5,'Permission/edit',0,0,1,'',0),
(43,'删除权限组',5,'Permission/del',0,0,1,'',0),
(44,'用户入组',5,'Permission/group',0,0,1,'',0),
(45,'组用户列表',5,'Permission/member',0,0,1,'',0),
(46,'踢出成员',5,'Permission/delMember',0,0,1,'',0),
(47,'权限组权限配置',5,'Permission/rule',0,0,1,'',0);
/*!40000 ALTER TABLE `api_menu` ENABLE KEYS */;
UNLOCK TABLES;
# Dump of table api_user
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_user`;
CREATE TABLE `api_user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(64) NOT NULL DEFAULT '' COMMENT '用户名',
`nickname` varchar(64) NOT NULL DEFAULT '' COMMENT '用户昵称',
`password` char(32) NOT NULL DEFAULT '' COMMENT '用户密码',
`regTime` int(10) NOT NULL DEFAULT '0' COMMENT '注册时间',
`regIp` varchar(11) NOT NULL DEFAULT '' COMMENT '注册IP',
`updateTime` int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '账号状态 0封号 1正常',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管理员认证信息';
INSERT INTO `api_user` (`username`, `nickname`, `password`, `regTime`, `regIp`, `updateTime`, `status`)
VALUES
('root', 'root', '912601e4ad1b308c9ae41877cf6ca754', 1492004246, '3682992231', 1492236545, 1);
# Dump of table api_user_action
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_user_action`;
CREATE TABLE `api_user_action` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`actionName` varchar(50) NOT NULL DEFAULT '' COMMENT '行为名称',
`uid` int(11) NOT NULL DEFAULT '0' COMMENT '操作用户ID',
`nickname` varchar(50) NOT NULL DEFAULT '' COMMENT '用户昵称',
`addTime` int(11) NOT NULL DEFAULT '0' COMMENT '操作时间',
`data` text COMMENT '用户提交的数据',
`url` varchar(200) NOT NULL DEFAULT '' COMMENT '操作URL',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户操作日志';
# Dump of table api_user_data
# ------------------------------------------------------------
DROP TABLE IF EXISTS `api_user_data`;
CREATE TABLE `api_user_data` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`loginTimes` int(11) NOT NULL COMMENT '账号登录次数',
`lastLoginIp` varchar(11) NOT NULL DEFAULT '' COMMENT '最后登录IP',
`lastLoginTime` int(11) NOT NULL COMMENT '最后登录时间',
`uid` varchar(11) NOT NULL DEFAULT '' COMMENT '用户ID',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管理员数据表';
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

View File

@ -0,0 +1,20 @@
<?php
/**
*
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\Api;
class Base {
protected $city;
protected $userInfo;
public function __construct() {
$this->city = C('CITY');
$this->userInfo = C('USER_INFO');
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* 和Token相关的全部接口
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\Api;
use Admin\Model\ApiAppModel;
use Home\ORG\ApiLog;
use Home\ORG\Crypt;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
class BuildToken extends Base {
public function getAccessToken($param) {
if (empty($param['app_id'])) {
Response::error(ReturnCode::EMPTY_PARAMS, '缺少app_id');
}
$appObj = new ApiAppModel();
$appInfo = $appObj->where(array('app_id' => $param['app_id'], 'app_status' => 1))->find();
if (empty($appInfo)) {
Response::error(ReturnCode::INVALID, '应用ID非法');
}
$crypt = new Crypt();
$signature = $param['signature'];
unset($param['signature']);
$sign = $crypt->getAuthToken($appInfo['app_secret'], $param);
Response::debug($sign);
if ($sign !== $signature) {
Response::error(ReturnCode::INVALID, '身份令牌验证失败');
}
$expires = C('ACCESS_TOKEN_EXPIRES');
$accessToken = S($param['device_id']);
if ($accessToken) {
S($accessToken, null);
S($param['device_id'], null);
}
$accessToken = $crypt->getAccessToken($appInfo['app_id'], $appInfo['app_secret']);
$appInfo['device_id'] = $param['device_id'];
ApiLog::setAppInfo($appInfo);
S($accessToken, $appInfo, $expires);
S($param['device_id'], $accessToken, $expires);
$return['access_token'] = $accessToken;
$return['expires_in'] = $expires;
return $return;
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
*
* @since 2017/03/10 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\Api;
use Home\ORG\JPush;
class Test extends Base {
public function index() {
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,14 @@
<?php
return array(
//默认每页显示数量
'DEFAULT_PER_PAGE' => 10,
//AccessToken有效期单位
'ACCESS_TOKEN_EXPIRES' => 7200,
//UserToken有效期单位
'USER_TOKEN_EXPIRES' => null,
);

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,151 @@
<?php
/**
* Api入口
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\Controller;
use Home\ORG\ApiLog;
use Home\ORG\Filter;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
use Think\Log;
class ApiController extends BaseController {
private $apiDetail; //api配置API路由是否需要登录是否需要AccessToken
private $apiRequest; //请求参数规则
private $apiResponse; //返回参数规则
private $param; //根据API配置过滤后的传入参数
private $header; //http request header信息
public function index() {
$getArr = I('get.');
$postArr = I('post.');
$this->apiDetail = M('ApiList')->where(array('hash' => $getArr['hash'], 'status' => 1))->find();
if (empty($this->apiDetail)) {
Response::error(ReturnCode::NOT_EXISTS, '非法的API标识');
}
ApiLog::setApiInfo($this->apiDetail);
$this->apiRequest = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 0))->select();
$this->apiResponse = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 1))->select();
$returnType = M('ApiFields')->where(array('hash' => $getArr['hash'], 'showName' => 'data', 'type' => 1))->find();
Response::setDataType($returnType['dataType']);
$this->header = apache_request_headers();
$this->header = array_change_key_case($this->header, CASE_UPPER);
ApiLog::setHeader($this->header);
if ($this->apiDetail['accessToken'] && !$this->apiDetail['isTest']) {
$this->checkAccessToken();
}
if (!$this->apiDetail['isTest']) {
$this->checkVersion();
}
$this->checkLogin();
unset($getArr['hash']);
switch ($this->apiDetail['method']) {
case 0:
$this->param = array_merge($getArr, $postArr);
break;
case 1:
$this->param = $postArr;
break;
case 2:
$this->param = $getArr;
break;
}
ApiLog::setRequest($this->param);
$this->iniApi();
}
/**
* 系统初始化函数(登陆状态检测,权限检测,初始化菜单)
*/
private function iniApi() {
$filterObj = new Filter();
if (!$this->apiDetail['isTest']) {
$this->checkRule();
$filterObj->request($this->param, $this->apiRequest);
}
ApiLog::setRequestAfterFilter($this->param);
list($className, $actionName) = explode('/', $this->apiDetail['apiName']);
$moduleName = MODULE_NAME . '\\Api\\' . $className;
$reflection = new \ReflectionClass($moduleName);
if (!$reflection->hasMethod($actionName)) {
Response::error(ReturnCode::EXCEPTION, '服务器端配置异常');
}
$method = $reflection->getMethod($actionName);
$handle = $reflection->newInstance();
$data = $method->invokeArgs($handle, array($this->param));
if (!$this->apiDetail['isTest']) {
$data = $filterObj->response($data, $this->apiResponse);
}
Response::success($data);
}
/**
* Api接口合法性检测
*/
private function checkAccessToken() {
$access_token = $this->header['ACCESS-TOKEN'];
if (!isset($access_token) || !$access_token) {
Response::error(ReturnCode::ACCESS_TOKEN_TIMEOUT, '缺少参数access-token');
} else {
$appInfo = S($access_token);
if (!$appInfo) {
Response::error(ReturnCode::ACCESS_TOKEN_TIMEOUT, 'access-token已过期');
}
ApiLog::setAppInfo($appInfo);
}
}
/**
* Api版本参数校验
*/
private function checkVersion() {
$version = $this->header['VERSION'];
if (!isset($version) || !$version) {
Response::error(ReturnCode::EMPTY_PARAMS, '缺少参数version');
} else {
if ($version != C('APP_VERSION')) {
Response::error(ReturnCode::VERSION_INVALID, 'API版本不匹配');
}
}
}
/**
* 检测用户登录情况 检测通过请赋予USER_INFO值
*/
private function checkLogin() {
if ($this->apiDetail['needLogin']) {
if (!isset($this->header['USER-TOKEN']) || !$this->header['USER-TOKEN']) {
Response::error(ReturnCode::AUTH_ERROR, '缺少user-token');
}
}
if (isset($this->header['USER-TOKEN']) && $this->header['USER-TOKEN']) {
$userInfo = S($this->header['USER-TOKEN']);
if (!is_array($userInfo) || !isset($userInfo['passport_uid'])) {
Response::error(ReturnCode::AUTH_ERROR, 'user-token不匹配');
}
C('USER_INFO', $userInfo);
}
}
/**
* 权限检测&权限验证(暂时预留)
*/
private function checkRule() {
}
}

View File

@ -0,0 +1,14 @@
<?php
/**
* 工程基类
* @since 2017/02/28 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {
}

View File

@ -0,0 +1,10 @@
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
echo 'welcome';
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* 文档自动生成
* @since 2017/03/01 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\Controller;
use Home\ORG\DataType;
use Home\ORG\ReturnCode;
use Think\Controller;
class WikiController extends Controller {
public function apiList(){
$listData = M('ApiList')->select();
$this->assign('list', $listData);
$this->display();
}
public function apiField(){
$hash = I('get.hash');
if( empty($hash) ){
$this->redirect('apiList');
}else{
$request = M('ApiFields')->where(array('hash' => $hash, 'type' => 0))->select();
$response = M('ApiFields')->where(array('hash' => $hash, 'type' => 1))->select();
$apiInfo = M('ApiList')->where(array('hash' => $hash))->find();
$this->assign('apiInfo', $apiInfo);
$dataType = array(
DataType::TYPE_INTEGER => 'Integer',
DataType::TYPE_STRING => 'String',
DataType::TYPE_BOOLEAN => 'Boolean',
DataType::TYPE_ENUM => 'Enum',
DataType::TYPE_FLOAT => 'Float',
DataType::TYPE_FILE => 'File',
DataType::TYPE_ARRAY => 'Array',
DataType::TYPE_OBJECT => 'Object',
DataType::TYPE_MOBILE => 'Mobile'
);
$this->assign('dataType', $dataType);
$this->assign('request', $request);
$this->assign('response', $response);
$this->display();
}
}
public function errorCode(){
$codeArr = ReturnCode::getConstants();
$errorInfo = array(
ReturnCode::SUCCESS => '请求成功',
ReturnCode::INVALID => '非法操作',
ReturnCode::DB_SAVE_ERROR => '数据存储失败',
ReturnCode::DB_READ_ERROR => '数据读取失败',
ReturnCode::CACHE_SAVE_ERROR => '缓存存储失败',
ReturnCode::CACHE_READ_ERROR => '缓存读取失败',
ReturnCode::FILE_SAVE_ERROR => '文件读取失败',
ReturnCode::LOGIN_ERROR => '登录失败',
ReturnCode::NOT_EXISTS => '不存在',
ReturnCode::JSON_PARSE_FAIL => 'JSON数据格式错误',
ReturnCode::TYPE_ERROR => '类型错误',
ReturnCode::NUMBER_MATCH_ERROR => '数字匹配失败',
ReturnCode::EMPTY_PARAMS => '丢失必要数据',
ReturnCode::DATA_EXISTS => '数据已经存在',
ReturnCode::AUTH_ERROR => '权限认证失败',
ReturnCode::OTHER_LOGIN => '别的终端登录',
ReturnCode::VERSION_INVALID => 'API版本非法',
ReturnCode::PARAM_INVALID => '数据类型非法',
ReturnCode::ACCESS_TOKEN_TIMEOUT => '身份令牌过期',
ReturnCode::SESSION_TIMEOUT => 'SESSION过期',
ReturnCode::UNKNOWN => '未知错误',
ReturnCode::EXCEPTION => '系统异常',
ReturnCode::CURL_ERROR => 'CURL操作异常'
);
$this->assign('errorInfo', $errorInfo);
$this->assign('codeArr', $codeArr);
$this->display();
}
public function calculation(){
$this->display();
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,15 @@
<?php
/**
*
* @since 2017/03/10 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\Model;
use Think\Model;
class BaseModel extends Model {
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,61 @@
<?php
/**
* @since 2017-04-14
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG;
class ApiLog {
private static $appInfo = null;
private static $apiInfo = null;
private static $request = null;
private static $requestAfterFilter = null;
private static $response = null;
private static $header = null;
public static function setAppInfo($data) {
self::$appInfo = $data['app_id'] . "({$data['app_name']}) {$data['device_id']}";
}
public static function setHeader($data) {
$userToken = (isset($data['USER-TOKEN']) && !empty($data['USER-TOKEN']))?$data['USER-TOKEN']:'null';
$accessToken = (isset($data['ACCESS-TOKEN']) && !empty($data['ACCESS-TOKEN']))?$data['ACCESS-TOKEN']:'null';
self::$header = $accessToken.' '.$userToken.' '.$data['VERSION'];
}
public static function setApiInfo($data) {
self::$apiInfo = $data['apiName'] . ' ' . $data['hash'];
}
public static function setRequest($data) {
if (is_array($data)) {
$data = json_encode($data);
}
self::$request = $data;
}
public static function setRequestAfterFilter($data) {
if (is_array($data)) {
$data = json_encode($data);
}
self::$requestAfterFilter = $data;
}
public static function setResponse($data) {
if (is_array($data)) {
$data = json_encode($data);
}
self::$response = $data;
}
public static function save() {
$logPath = APP_PATH . '/ApiLog/' . date('YmdH') . '.log';
$logStr = self::$apiInfo . ' ' . date('H:i:s') . ' ' . self::$request . ' ' . self::$header . ' '
. self::$response . ' ' . self::$requestAfterFilter . ' ' . self::$appInfo."\n";
@file_put_contents($logPath, $logStr, FILE_APPEND);
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Api身份秘钥计算
* @since 2017/02/28 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG;
class Crypt {
/**
* 根据AppSecret和数据生成相对应的身份认证秘钥
* @param $appSecret
* @param $data
* @return string
*/
public function getAuthToken( $appSecret, $data ){
if(empty($data)){
return '';
}else{
$preArr = array_merge($data, array('app_secret' => $appSecret));
ksort($preArr);
$preStr = http_build_query($preArr);
return md5($preStr);
}
}
/**
* 计算出唯一的身份令牌
* @param $appId
* @param $appSecret
* @return string
*/
public function getAccessToken( $appId, $appSecret ){
$preStr = $appSecret.$appId.time().Str::keyGen();
return md5($preStr);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* 数据类型维护
* 特别注意:这里的数据类型包含但不限于常规数据类型,可能会存在系统自己定义的数据类型
* @since 2017/03/01 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG;
class DataType {
const TYPE_INTEGER = 1;
const TYPE_STRING = 2;
const TYPE_ARRAY = 3;
const TYPE_FLOAT = 4;
const TYPE_BOOLEAN = 5;
const TYPE_FILE = 6;
const TYPE_ENUM = 7;
const TYPE_MOBILE = 8;
const TYPE_OBJECT = 9;
//JPush推送消息类型
const PUSH_SYSTEM_DATA = 1;
const PUSH_ACTIVITY_DATA = 2;
}

View File

@ -0,0 +1,569 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Home\ORG;
/**
* 日期时间操作类
* @category ORG
* @package ORG
* @subpackage Date
* @author liu21st <liu21st@gmail.com>
* @version $Id: Date.class.php 2662 2012-01-26 06:32:50Z liu21st $
*/
class Date {
/**
* 日期的时间戳
* @var integer
* @access protected
*/
protected $date;
/**
* 时区
* @var integer
* @access protected
*/
protected $timezone;
/**
*
* @var integer
* @access protected
*/
protected $year;
/**
*
* @var integer
* @access protected
*/
protected $month;
/**
*
* @var integer
* @access protected
*/
protected $day;
/**
*
* @var integer
* @access protected
*/
protected $hour;
/**
*
* @var integer
* @access protected
*/
protected $minute;
/**
*
* @var integer
* @access protected
*/
protected $second;
/**
* 星期的数字表示
* @var integer
* @access protected
*/
protected $weekday;
/**
* 星期的完整表示
* @var string
* @access protected
*/
protected $cWeekday;
/**
* 一年中的天数 0365
* @var integer
* @access protected
*/
protected $yDay;
/**
* 月份的完整表示
* @var string
* @access protected
*/
protected $cMonth;
/**
* 日期CDATE表示
* @var string
* @access protected
*/
protected $CDATE;
/**
* 日期的YMD表示
* @var string
* @access protected
*/
protected $YMD;
/**
* 时间的输出表示
* @var string
* @access protected
*/
protected $CTIME;
// 星期的输出
protected $Week = array("","","","","","","");
/**
* 架构函数
* 创建一个Date对象
* @param mixed $date 日期
* @static
* @access public
*/
public function __construct($date='') {
//分析日期
$this->date = $this->parse($date);
$this->setDate($this->date);
}
/**
* 日期分析
* 返回时间戳
* @static
* @access public
* @param mixed $date 日期
* @return string
*/
public function parse($date) {
if (is_string($date)) {
if (($date == "") || strtotime($date) == -1) {
//为空默认取得当前时间戳
$tmpDate = time();
} else {
//把字符串转换成UNIX时间戳
$tmpDate = strtotime($date);
}
} elseif (is_null($date)) {
//为空默认取得当前时间戳
$tmpDate = time();
} elseif (is_numeric($date)) {
//数字格式直接转换为时间戳
$tmpDate = $date;
} else {
if (get_class($date) == "Date") {
//如果是Date对象
$tmpDate = $date->date;
} else {
//默认取当前时间戳
$tmpDate = time();
}
}
return $tmpDate;
}
/**
* 验证日期数据是否有效
* @access public
* @param mixed $date 日期数据
* @return string
*/
public function valid($date) {
}
/**
* 日期参数设置
* @static
* @access public
* @param integer $date 日期时间戳
* @return void
*/
public function setDate($date) {
$dateArray = getdate($date);
$this->date = $dateArray[0]; //时间戳
$this->second = $dateArray["seconds"]; //秒
$this->minute = $dateArray["minutes"]; //分
$this->hour = $dateArray["hours"]; //时
$this->day = $dateArray["mday"]; //日
$this->month = $dateArray["mon"]; //月
$this->year = $dateArray["year"]; //年
$this->weekday = $dateArray["wday"]; //星期 06
$this->cWeekday = '星期'.$this->Week[$this->weekday];//$dateArray["weekday"]; //星期完整表示
$this->yDay = $dateArray["yday"]; //一年中的天数 0365
$this->cMonth = $dateArray["month"]; //月份的完整表示
$this->CDATE = $this->format("%Y-%m-%d");//日期表示
$this->YMD = $this->format("%Y%m%d"); //简单日期
$this->CTIME = $this->format("%H:%M:%S");//时间表示
return ;
}
/**
* 日期格式化
* 默认返回 1970-01-01 11:30:45 格式
* @access public
* @param string $format 格式化参数
* @return string
*/
public function format($format = "%Y-%m-%d %H:%M:%S") {
return strftime($format, $this->date);
}
/**
* 是否为闰年
* @static
* @access public
* @return string
*/
public function isLeapYear($year='') {
if(empty($year)) {
$year = $this->year;
}
return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0));
}
/**
* 计算日期差
*
* w - weeks
* d - days
* h - hours
* m - minutes
* s - seconds
* @static
* @access public
* @param mixed $date 要比较的日期
* @param string $elaps 比较跨度
* @return integer
*/
public function dateDiff($date, $elaps = "d") {
$__DAYS_PER_WEEK__ = (7);
$__DAYS_PER_MONTH__ = (30);
$__DAYS_PER_YEAR__ = (365);
$__HOURS_IN_A_DAY__ = (24);
$__MINUTES_IN_A_DAY__ = (1440);
$__SECONDS_IN_A_DAY__ = (86400);
//计算天数差
$__DAYSELAPS = ($this->parse($date) - $this->date) / $__SECONDS_IN_A_DAY__ ;
switch ($elaps) {
case "y"://转换成年
$__DAYSELAPS = $__DAYSELAPS / $__DAYS_PER_YEAR__;
break;
case "M"://转换成月
$__DAYSELAPS = $__DAYSELAPS / $__DAYS_PER_MONTH__;
break;
case "w"://转换成星期
$__DAYSELAPS = $__DAYSELAPS / $__DAYS_PER_WEEK__;
break;
case "h"://转换成小时
$__DAYSELAPS = $__DAYSELAPS * $__HOURS_IN_A_DAY__;
break;
case "m"://转换成分钟
$__DAYSELAPS = $__DAYSELAPS * $__MINUTES_IN_A_DAY__;
break;
case "s"://转换成秒
$__DAYSELAPS = $__DAYSELAPS * $__SECONDS_IN_A_DAY__;
break;
}
return $__DAYSELAPS;
}
/**
* 人性化的计算日期差
* @static
* @access public
* @param mixed $time 要比较的时间
* @param mixed $precision 返回的精度
* @return string
*/
public function timeDiff( $time ,$precision=false) {
if(!is_numeric($precision) && !is_bool($precision)) {
static $_diff = array('y'=>'年','M'=>'个月','d'=>'天','w'=>'周','s'=>'秒','h'=>'小时','m'=>'分钟');
return ceil($this->dateDiff($time,$precision)).$_diff[$precision].'前';
}
$diff = abs($this->parse($time) - $this->date);
static $chunks = array(array(31536000,'年'),array(2592000,'个月'),array(604800,'周'),array(86400,'天'),array(3600 ,'小时'),array(60,'分钟'),array(1,'秒'));
$count =0;
$since = '';
for($i=0;$i<count($chunks);$i++) {
if($diff>=$chunks[$i][0]) {
$num = floor($diff/$chunks[$i][0]);
$since .= sprintf('%d'.$chunks[$i][1],$num);
$diff = (int)($diff-$chunks[$i][0]*$num);
$count++;
if(!$precision || $count>=$precision) {
break;
}
}
}
return $since.'前';
}
/**
* 返回周的某一天 返回Date对象
* @access public
* @return Date
*/
public function getDayOfWeek($n){
$week = array(0=>'sunday',1=>'monday',2=>'tuesday',3=>'wednesday',4=>'thursday',5=>'friday',6=>'saturday');
return (new Date($week[$n]));
}
/**
* 计算周的第一天 返回Date对象
* @access public
* @return Date
*/
public function firstDayOfWeek() {
return $this->getDayOfWeek(1);
}
/**
* 计算月份的第一天 返回Date对象
* @access public
* @return Date
*/
public function firstDayOfMonth() {
return (new Date(mktime(0, 0, 0,$this->month,1,$this->year )));
}
/**
* 计算年份的第一天 返回Date对象
* @access public
* @return Date
*/
public function firstDayOfYear() {
return (new Date(mktime(0, 0, 0, 1, 1, $this->year)));
}
/**
* 计算周的最后一天 返回Date对象
* @access public
* @return Date
*/
public function lastDayOfWeek() {
return $this->getDayOfWeek(0);
}
/**
* 计算月份的最后一天 返回Date对象
* @access public
* @return Date
*/
public function lastDayOfMonth() {
return (new Date(mktime(0, 0, 0, $this->month + 1, 0, $this->year )));
}
/**
* 计算年份的最后一天 返回Date对象
* @access public
* @return Date
*/
public function lastDayOfYear() {
return (new Date(mktime(0, 0, 0, 1, 0, $this->year + 1)));
}
/**
* 计算月份的最大天数
* @access public
* @return integer
*/
public function maxDayOfMonth() {
$result = $this->dateDiff(strtotime($this->dateAdd(1,'m')),'d');
return $result;
}
/**
* 取得指定间隔日期
*
* yyyy -
* q - 季度
* m -
* y - day of year
* d -
* w -
* ww - week of year
* h - 小时
* n - 分钟
* s -
* @access public
* @param integer $number 间隔数目
* @param string $interval 比较类型
* @return Date
*/
public function dateAdd($number = 0, $interval = "d") {
$hours = $this->hour;
$minutes = $this->minute;
$seconds = $this->second;
$month = $this->month;
$day = $this->day;
$year = $this->year;
switch ($interval) {
case "yyyy":
//---Add $number to year
$year += $number;
break;
case "q":
//---Add $number to quarter
$month += ($number*3);
break;
case "m":
//---Add $number to month
$month += $number;
break;
case "y":
case "d":
case "w":
//---Add $number to day of year, day, day of week
$day += $number;
break;
case "ww":
//---Add $number to week
$day += ($number*7);
break;
case "h":
//---Add $number to hours
$hours += $number;
break;
case "n":
//---Add $number to minutes
$minutes += $number;
break;
case "s":
//---Add $number to seconds
$seconds += $number;
break;
}
return (new Date(mktime($hours,
$minutes,
$seconds,
$month,
$day,
$year)));
}
/**
* 日期数字转中文
* 用于日和月、周
* @static
* @access public
* @param integer $number 日期数字
* @return string
*/
public function numberToCh($number) {
$number = intval($number);
$array = array('一','二','三','四','五','六','七','八','九','十');
$str = '';
if($number ==0) { $str .= "" ;}
if($number < 10){
$str .= $array[$number-1] ;
}
elseif($number < 20 ){
$str .= "".$array[$number-11];
}
elseif($number < 30 ){
$str .= "二十".$array[$number-21];
}
else{
$str .= "三十".$array[$number-31];
}
return $str;
}
/**
* 年份数字转中文
* @static
* @access public
* @param integer $yearStr 年份数字
* @param boolean $flag 是否显示公元
* @return string
*/
public function yearToCh( $yearStr ,$flag=false ) {
$array = array('零','一','二','三','四','五','六','七','八','九');
$str = $flag? '公元' : '';
for($i=0;$i<4;$i++){
$str .= $array[substr($yearStr,$i,1)];
}
return $str;
}
/**
* 判断日期 所属 干支 生肖 星座
* type 参数XZ 星座 GZ 干支 SX 生肖
*
* @static
* @access public
* @param string $type 获取信息类型
* @return string
*/
public function magicInfo($type) {
$result = '';
$m = $this->month;
$y = $this->year;
$d = $this->day;
switch ($type) {
case 'XZ'://星座
$XZDict = array('摩羯','宝瓶','双鱼','白羊','金牛','双子','巨蟹','狮子','处女','天秤','天蝎','射手');
$Zone = array(1222,122,222,321,421,522,622,722,822,922,1022,1122,1222);
if((100*$m+$d)>=$Zone[0]||(100*$m+$d)<$Zone[1])
$i=0;
else
for($i=1;$i<12;$i++){
if((100*$m+$d)>=$Zone[$i]&&(100*$m+$d)<$Zone[$i+1])
break;
}
$result = $XZDict[$i].'座';
break;
case 'GZ'://干支
$GZDict = array(
array('甲','乙','丙','丁','戊','己','庚','辛','壬','癸'),
array('子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥')
);
$i= $y -1900+36 ;
$result = $GZDict[0][$i%10].$GZDict[1][$i%12];
break;
case 'SX'://生肖
$SXDict = array('鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪');
$result = $SXDict[($y-4)%12];
break;
}
return $result;
}
public function __toString() {
return $this->format();
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* API数据过滤
* @since 2017/02/28 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG;
use Home\ORG\Filter\ArrayFilter;
use Home\ORG\Filter\EnumFilter;
use Home\ORG\Filter\FloatFilter;
use Home\ORG\Filter\IntegerFilter;
use Home\ORG\Filter\OtherFilter;
use Home\ORG\Filter\StringFilter;
class Filter {
/**
* 返回参数过滤(主要是将返回参数的数据类型给规范)
* @param array $data
* @param array $rule
* @return array
*/
public function response($data, $rule = array()) {
$newRule = array();
foreach ($rule as $item) {
$newRule[$item['showName']] = $item['dataType'];
}
if (is_array($data)) {
$this->handle($data, $newRule);
} elseif (empty($data)) {
if ($newRule['data'] == DataType::TYPE_OBJECT) {
$data = (object)array();
} elseif ($newRule['data'] == DataType::TYPE_ARRAY) {
$data = array();
}
}
return $data;
}
private function handle(&$data, $rule, $prefix = 'data') {
if (empty($data)) {
if ($rule[$prefix] == DataType::TYPE_OBJECT) {
$data = (object)array();
}
} else {
if ($rule[$prefix] == DataType::TYPE_OBJECT) {
$prefix .= '{}';
foreach ($data as $index => &$datum) {
$myPre = $prefix . $index;
switch ($rule[$myPre]) {
case DataType::TYPE_INTEGER:
$datum = intval($datum);
break;
case DataType::TYPE_FLOAT:
$datum = floatval($datum);
break;
case DataType::TYPE_STRING:
$datum = strval($datum);
break;
default:
$this->handle($datum, $rule, $myPre);
break;
}
}
} else {
$prefix .= '[]';
if (is_array($data[0])) {
foreach ($data as &$datum) {
$this->handle($datum, $rule, $prefix);
}
}
}
}
}
/**
* 请求参数过滤(主要是判断字段的合法性)
* @param $data
* @param array $rule
*/
public function request(&$data, $rule = array()) {
$newData = array();
foreach ($rule as $value) {
if (!isset($data[$value['fieldName']])) {
if ($value['isMust']) {
Response::error(ReturnCode::EMPTY_PARAMS, '缺少必要参数:' . $value['fieldName']);
} else {
if ($value['default'] === '') {
continue;
} else {
$data[$value['fieldName']] = $value['default'];
}
}
}
if (isset($data[$value['fieldName']])) {
$newData[$value['fieldName']] = $data[$value['fieldName']];
}
if ($value['range']) {
$value['range'] = htmlspecialchars_decode($value['range']);
}
switch ($value['dataType']) {
case DataType::TYPE_INTEGER:
$checkObj = new IntegerFilter();
if ($value['isMust'] && $newData[$value['fieldName']] == '') {
Response::error(ReturnCode::EMPTY_PARAMS, '字段[' . $value['fieldName'] . ']不能为空');
}
if ($newData[$value['fieldName']] != '') {
$checkObj->parse($newData[$value['fieldName']], json_decode($value['range'], true), $value['fieldName']);
}
break;
case DataType::TYPE_STRING:
$checkObj = new StringFilter();
if ($value['isMust'] && $newData[$value['fieldName']] == '') {
Response::error(ReturnCode::EMPTY_PARAMS, '字段[' . $value['fieldName'] . ']不能为空');
}
$newData[$value['fieldName']] = trim($newData[$value['fieldName']]);
if ($newData[$value['fieldName']] != '') {
$checkObj->parse($newData[$value['fieldName']], json_decode($value['range'], true), $value['fieldName']);
}
break;
case DataType::TYPE_ENUM:
$checkObj = new EnumFilter();
if ($value['isMust'] && $newData[$value['fieldName']] == '') {
Response::error(ReturnCode::EMPTY_PARAMS, '字段[' . $value['fieldName'] . ']不能为空');
}
if ($newData[$value['fieldName']] != '') {
$checkObj->parse($newData[$value['fieldName']], json_decode($value['range'], true), $value['fieldName']);
}
break;
case DataType::TYPE_FLOAT:
$checkObj = new FloatFilter();
if ($value['isMust'] && empty($newData[$value['fieldName']]) && $newData[$value['fieldName']] != 0) {
Response::error(ReturnCode::EMPTY_PARAMS, '字段[' . $value['fieldName'] . ']不能为空');
}
$newData[$value['fieldName']] = trim($newData[$value['fieldName']]);
$checkObj->parse($newData[$value['fieldName']], json_decode($value['range'], true), $value['fieldName']);
break;
case DataType::TYPE_ARRAY:
$checkObj = new ArrayFilter();
$checkObj->parse($newData[$value['fieldName']], json_decode($value['range'], true), $value['fieldName']);
break;
case DataType::TYPE_MOBILE:
$checkObj = new OtherFilter();
$newData[$value['fieldName']] = trim($newData[$value['fieldName']]);
$checkObj->isMobile($newData[$value['fieldName']], json_decode($value['range'], true), $value['fieldName']);
break;
}
}
$data = $newData;
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
*
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\Filter;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
class ArrayFilter extends Base {
public function parse(&$value, $rule, $fieldName) {
$this->fieldName = $fieldName;
if(!is_array($value)) {
Response::error(ReturnCode::TYPE_ERROR, "字段[{$fieldName}]字段类型不合法期望数据类型为Array");
} elseif (!empty($rule)) {
$this->filterByRange(count($value), $rule);
}
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
*
* @since 2017/03/01 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\Filter;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
class Base {
protected $fieldName;
protected function filterByRange($value, $rule) {
$this->checkSetting($rule);
$this->checkMin($value, $rule);
$this->checkMax($value, $rule);
}
protected function checkSetting($rule) {
if (isset($rule['min']) && isset($rule['max']) && $rule['min'] > $rule['max']) {
Response::error(ReturnCode::NUMBER_MATCH_ERROR, "字段[{$this->fieldName}]的系统配置矛盾,请检测");
}
}
protected function checkMin($value, $rule) {
if (isset($rule['min']) && $value < $rule['min']) {
Response::error(ReturnCode::NUMBER_MATCH_ERROR, "字段[{$this->fieldName}]不合法,系统要求最小值为:". $rule['min']);
}
}
protected function checkMax($value, $rule) {
if (isset($rule['max']) && $value > $rule['max']) {
Response::error(ReturnCode::NUMBER_MATCH_ERROR, "字段[{$this->fieldName}]不合法,系统要求最大值为:". $rule['max']);
}
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
*
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\Filter;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
class EnumFilter extends Base {
public function parse(&$value, $rule, $fieldName){
$this->fieldName = $fieldName;
if( !empty($rule) && !in_array($value, $rule) ){
Response::error(ReturnCode::PARAM_INVALID, "字段[{$fieldName}]取值超出允许范围");
}
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
*
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\Filter;
class FloatFilter extends Base {
public function parse(&$value, $rule, $fieldName){
$this->fieldName = $fieldName;
$value = floatval($value);
if( !empty($rule) ){
$this->filterByRange($value, $rule);
}
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
*
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\Filter;
class IntegerFilter extends Base {
public function parse(&$value, $rule, $fieldName){
$this->fieldName = $fieldName;
$value = intval($value);
if( !empty($rule) ){
$this->filterByRange($value, $rule);
}
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
*
* @since 2017/03/14 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\Filter;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
class OtherFilter extends Base {
public function isMobile(&$value, $rule, $fieldName){
$this->fieldName = $fieldName;
if( !preg_match('/^1[34578]\d{9}$/', $value) ){
Response::error(ReturnCode::PARAM_INVALID, "请输入正确的11位手机号码");
}
}
}

View File

@ -0,0 +1,24 @@
<?php
/**
*
* @since 2017/03/02 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\Filter;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
class StringFilter extends Base {
public function parse(&$value, $rule, $fieldName){
$this->fieldName = $fieldName;
if (!is_string($value)) {
Response::error(ReturnCode::TYPE_ERROR, "字段[$fieldName]数据类型不合法期望类型应该为String");
} else {
if( !empty($rule) ){
$this->filterByRange(strlen($value), $rule);
}
}
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
*
* @since 2017/03/24 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\JPush;
class Config {
const APP_KEY = '884fc6fb9fb466e11def006a';
const MASTER_SECRET = '11c72c7fad4110472a688973';
//推送API
const API_PUSH = 'https://api.jpush.cn/v3/push';
//推送校验 API
const API_VALIDATE = 'https://api.jpush.cn/v3/push/validate';
//送达统计
const API_RECEIVED = 'https://report.jpush.cn/v3/received';
//消息统计
const API_MESSAGE = 'https://report.jpush.cn/v3/messages';
//用户统计
const API_USERS = 'https://report.jpush.cn/v3/users';
//查询设备的别名与标签(设置设备的别名与标签)
const API_DEVICES = 'https://device.jpush.cn/v3/devices';
//查询别名(删除别名)
const API_ALIASES = 'https://device.jpush.cn/v3/aliases';
//查询标签列表(判断设备与标签绑定关系/更新标签/删除标签)
const API_TAG = 'https://device.jpush.cn/v3/tags';
//获取用户在线状态
const API_STATUS = 'https://device.jpush.cn/v3/devices/status/';
//定时任务相关
const API_SCHEDULES = 'https://api.jpush.cn/v3/schedules';
const HTTP_POST = 1;
const HTTP_GET = 2;
const HTTP_PUT = 3;
const HTTP_DELETE = 4;
const PLATFORM_ANDROID = 'android';
const PLATFORM_IOS = 'ios';
const DISABLE_SOUND = "_disable_Sound";
const DISABLE_BADGE = 0x10000;
const USER_AGENT = 'JPush-API-PHP-Client';
const CONNECT_TIMEOUT = 1;
//请求最长耗时
const READ_TIMEOUT = 120;
//重连次数
const DEFAULT_MAX_RETRY_TIMES = 3;
const DEFAULT_LOG_FILE = "./jpush.log";
}

View File

@ -0,0 +1,13 @@
<?php
/**
*
* @since 2017/03/24 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\JPush;
class Device {
}

View File

@ -0,0 +1,146 @@
<?php
/**
*
* @since 2017/03/24 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\JPush;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
class Http {
public static function get($url) {
$response = self::sendRequest($url, Config::HTTP_GET, $body = null);
return self::processResp($response);
}
public static function post($url, $body) {
$response = self::sendRequest($url, Config::HTTP_POST, $body);
return self::processResp($response);
}
public static function put($url, $body) {
$response = self::sendRequest($url, Config::HTTP_PUT, $body);
return self::processResp($response);
}
public static function delete($url) {
$response = self::sendRequest($url, Config::HTTP_DELETE, $body = null);
return self::processResp($response);
}
private static function sendRequest($url, $method, $body = null, $times = 1) {
if (!defined('CURL_HTTP_VERSION_2_0')) {
define('CURL_HTTP_VERSION_2_0', 3);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, Config::USER_AGENT);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::CONNECT_TIMEOUT);
curl_setopt($ch, CURLOPT_TIMEOUT, Config::READ_TIMEOUT); // 请求最长耗时
// 设置SSL版本 1=CURL_SSLVERSION_TLSv1, 不指定使用默认值,curl会自动获取需要使用的CURL版本
// curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 如果报证书相关失败,可以考虑取消注释掉该行,强制指定证书版本
//curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
// 设置Basic认证
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, Config::APP_KEY . ':' . Config::MASTER_SECRET);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
// 设置Post参数
switch ($method) {
case Config::HTTP_POST:
curl_setopt($ch, CURLOPT_POST, true);
break;
case Config::HTTP_DELETE:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
case Config::HTTP_PUT:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
break;
}
if (!is_null($body)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Connection: Keep-Alive'
));
$output = curl_exec($ch);
$response = array();
$errorCode = curl_errno($ch);
$msg = '';
if (isset($body['options']['sendno'])) {
$sendNo = $body['options']['sendno'];
$msg = 'sendno: ' . $sendNo;
}
if ($errorCode) {
if ($times < Config::DEFAULT_MAX_RETRY_TIMES) {
return self::sendRequest($url, $method, $body, ++$times);
} else {
if ($errorCode === 28) {
Response::error(ReturnCode::CURL_ERROR, $msg . "Response timeout. Your request has probably be received by JPush Server,please check that whether need to be pushed again.");
} elseif ($errorCode === 56) {
Response::error(ReturnCode::CURL_ERROR, $msg . "Response timeout, maybe cause by old CURL version. Your request has probably be received by JPush Server, please check that whether need to be pushed again.");
} else {
Response::error(ReturnCode::CURL_ERROR, $msg . "Connect timeout, Please retry later. Error:" . $errorCode . " " . curl_error($ch));
}
}
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headerText = substr($output, 0, $headerSize);
$body = substr($output, $headerSize);
$headers = array();
foreach (explode("\r\n", $headerText) as $i => $line) {
if (!empty($line)) {
if ($i === 0) {
$headers[0] = $line;
} else if (strpos($line, ": ")) {
list ($key, $value) = explode(': ', $line);
$headers[$key] = $value;
}
}
}
$response['headers'] = $headers;
$response['body'] = $body;
$response['httpCode'] = $httpCode;
}
curl_close($ch);
return $response;
}
public static function processResp($response) {
$data = json_decode($response['body'], true);
if (is_null($data)) {
Response::error(ReturnCode::CURL_ERROR, '未收到返回数据');
} elseif ($response['httpCode'] === 200) {
$result = array();
$result['body'] = $data;
$result['httpCode'] = $response['httpCode'];
$result['headers'] = $response['headers'];
return $result;
}
}
}

View File

@ -0,0 +1,444 @@
<?php
/**
* JPush推送实现
* @since 2017/03/24 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\JPush;
use Home\ORG\Response;
use Home\ORG\ReturnCode;
use Home\ORG\Str;
class Push {
private $platform = 'all';
private $tag = null;
private $tagAnd = null;
private $alias = null;
private $registrationId = null;
private $extras = null;
private $notificationAlert = null;
private $androidNotification = null;
private $iosNotification = null;
private $message = null;
private $options = null;
/**
* 增加推送到苹果
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function ios() {
if (is_array($this->platform)) {
if (!in_array(Config::PLATFORM_IOS, $this->platform)) {
array_push($this->platform, Config::PLATFORM_IOS);
}
} else {
$this->platform = array(Config::PLATFORM_IOS);
}
return $this;
}
/**
* 推送至安卓
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function android() {
if (is_array($this->platform)) {
if (!in_array(Config::PLATFORM_ANDROID, $this->platform)) {
array_push($this->platform, Config::PLATFORM_ANDROID);
}
} else {
$this->platform = array(Config::PLATFORM_ANDROID);
}
return $this;
}
/**
* 设置推送tag仅允许传入字符串和一维索引数组
* @param string|array $param
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function addTag($param) {
if (is_null($this->tag)) {
if (is_array($this->tag)) {
$this->tag = $param;
} else {
$this->tag = array($param);
}
} else {
if (is_array($param)) {
foreach ($param as $item) {
if (!in_array($item, $this->tag)) {
array_push($this->tag, $item);
}
}
} else {
if (!in_array($param, $this->tag)) {
array_push($this->tag, $param);
}
}
}
return $this;
}
/**
* 设置推送tag_and仅允许传入字符串和一维索引数组
* @param string|array $param
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function addTagAnd($param) {
if (is_null($this->tagAnd)) {
if (is_array($this->tagAnd)) {
$this->tagAnd = $param;
} else {
$this->tagAnd = array($param);
}
} else {
if (is_array($param)) {
foreach ($param as $item) {
if (!in_array($item, $this->tagAnd)) {
array_push($this->tagAnd, $item);
}
}
} else {
if (!in_array($param, $this->tagAnd)) {
array_push($this->tagAnd, $param);
}
}
}
return $this;
}
/**
* 设置推送alias仅允许传入字符串和一维索引数组
* @param string|array $param
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function addAlias($param) {
if (is_null($this->alias)) {
if (is_array($this->alias)) {
$this->alias = $param;
} else {
$this->alias = array($param);
}
} else {
if (is_array($param)) {
foreach ($param as $item) {
if (!in_array($item, $this->alias)) {
array_push($this->alias, $item);
}
}
} else {
if (!in_array($param, $this->alias)) {
array_push($this->alias, $param);
}
}
}
return $this;
}
/**
* 设置推送registration_id仅允许传入字符串和一维索引数组
* @param string|array $param
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function addRegistrationId($param) {
if (is_null($this->registrationId)) {
if (is_array($this->registrationId)) {
$this->registrationId = $param;
} else {
$this->registrationId = array($param);
}
} else {
if (is_array($param)) {
foreach ($param as $item) {
if (!in_array($item, $this->registrationId)) {
array_push($this->registrationId, $item);
}
}
} else {
if (!in_array($param, $this->registrationId)) {
array_push($this->registrationId, $param);
}
}
}
return $this;
}
/**
* 设置公告消息
* @param string $param
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function setNotificationAlert($param) {
if (!is_string($param)) {
Response::error(ReturnCode::EXCEPTION, 'NotificationAlert 必须是字符串');
}
$this->notificationAlert = $param;
return $this;
}
/**
* 设置推送addExtras新增加额外字段
* @param array $param
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function addExtras($param) {
if (is_null($this->extras)) {
if (is_array($param)) {
$this->extras = $param;
}
} else {
if (is_array($param)) {
array_merge($this->extras, $param);
}
}
return $this;
}
/**
* 设置IOS的通知消息体
* @param $alert
* @param array $notification
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function iosNotification($alert, $notification = array()) {
$ios = array();
$ios['alert'] = (is_string($alert) || is_array($alert)) ? $alert : '';
if (!empty($notification)) {
if (isset($notification['sound']) && is_string($notification['sound'])) {
$ios['sound'] = $notification['sound'];
}
if (isset($notification['badge'])) {
$ios['badge'] = (int)$notification['badge'] ? $notification['badge'] : 0;
}
if (isset($notification['content-available']) && is_bool($notification['content-available']) && $notification['content-available']) {
$ios['content-available'] = $notification['content-available'];
}
if (isset($notification['mutable-content']) && is_bool($notification['mutable-content']) && $notification['mutable-content']) {
$ios['mutable-content'] = $notification['mutable-content'];
}
if (isset($notification['category']) && is_string($notification['category'])) {
$ios['category'] = $notification['category'];
}
if (isset($notification['extras']) && is_array($notification['extras']) && !empty($notification['extras'])) {
$ios['extras'] = $notification['extras'];
}
}
if (!isset($ios['sound'])) {
$ios['sound'] = '';
}
if (!isset($ios['badge'])) {
$ios['badge'] = '+1';
}
$this->iosNotification = $ios;
return $this;
}
/**
* 设置Android的通知消息体
* @param $alert
* @param array $notification
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function androidNotification($alert, array $notification = array()) {
$android = array();
$android['alert'] = is_string($alert) ? $alert : '';
if (!empty($notification)) {
if (isset($notification['title']) && is_string($notification['title'])) {
$android['title'] = $notification['title'];
}
if (isset($notification['builder_id']) && is_int($notification['builder_id'])) {
$android['builder_id'] = $notification['builder_id'];
}
if (isset($notification['extras']) && is_array($notification['extras']) && !empty($notification['extras'])) {
$android['extras'] = $notification['extras'];
}
if (isset($notification['priority']) && is_int($notification['priority'])) {
$android['priority'] = $notification['priority'];
}
if (isset($notification['category']) && is_string($notification['category'])) {
$android['category'] = $notification['category`'];
}
if (isset($notification['style']) && is_int($notification['style'])) {
$android['style'] = $notification['style'];
}
if (isset($notification['big_text']) && is_string($notification['big_text'])) {
$android['big_text'] = $notification['big_text'];
}
if (isset($notification['inbox']) && is_array($notification['inbox'])) {
$android['inbox'] = $notification['inbox'];
}
if (isset($notification['big_pic_path']) && is_string($notification['big_pic_path'])) {
$android['big_pic_path'] = $notification['big_pic_path'];
}
}
$this->androidNotification = $android;
return $this;
}
/**
* 自定义消息体设置
* @param $msgContent
* @param array $msg
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function message($msgContent, array $msg = array()) {
if (is_string($msgContent)) {
$message = array();
$message['msg_content'] = $msgContent;
if (!empty($msg)) {
if (isset($msg['title']) && is_string($msg['title'])) {
$message['title'] = $msg['title'];
}
if (isset($msg['content_type']) && is_string($msg['content_type'])) {
$message['content_type'] = $msg['content_type'];
}
if (isset($msg['extras']) && is_array($msg['extras']) && !empty($msg['extras'])) {
$message['extras'] = $msg['extras'];
}
}
$this->message = $message;
}
return $this;
}
/**
* 额外可选配置参数
* @param array $opts
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return $this
*/
public function options(array $opts = array()) {
$options = array();
if (isset($opts['sendno']) && is_int($opts['sendno'])) {
$options['sendno'] = $opts['sendno'];
}
if (isset($opts['time_to_live']) && is_int($opts['time_to_live']) && $opts['time_to_live'] <= 864000 && $opts['time_to_live'] >= 0) {
$options['time_to_live'] = $opts['time_to_live'];
}
if (isset($opts['override_msg_id']) && is_long($opts['override_msg_id'])) {
$options['override_msg_id'] = $opts['override_msg_id'];
}
if (isset($opts['apns_production']) && is_bool($opts['apns_production'])) {
$options['apns_production'] = $opts['apns_production'];
} else {
$options['apns_production'] = false;
}
if (isset($opts['big_push_duration']) && is_int($opts['big_push_duration']) && $opts['big_push_duration'] <= 1400 && $opts['big_push_duration'] >= 0) {
$options['big_push_duration'] = $opts['big_push_duration'];
}
$this->options = $options;
return $this;
}
/**
* 根据配置,整合数据
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array
*/
private function buildData() {
$payload = array();
$payload["platform"] = $this->platform;
$audience = array();
if (!is_null($this->tag)) {
$audience["tag"] = $this->tag;
}
if (!is_null($this->tagAnd)) {
$audience["tag_and"] = $this->tagAnd;
}
if (!is_null($this->alias)) {
$audience["alias"] = $this->alias;
}
if (!is_null($this->registrationId)) {
$audience["registration_id"] = $this->registrationId;
}
if (count($audience) <= 0) {
$payload["audience"] = 'all';
} else {
$payload["audience"] = $audience;
}
$notification = array();
if (!is_null($this->notificationAlert)) {
$notification['alert'] = $this->notificationAlert;
}
if (!is_null($this->androidNotification)) {
$notification['android'] = $this->androidNotification;
if (is_null($this->androidNotification['alert'])) {
if (is_null($this->notificationAlert)) {
Response::error(ReturnCode::EXCEPTION, 'Android alert can not be null');
} else {
$notification['android']['alert'] = $this->notificationAlert;
}
}
} else {
if (!is_null($this->extras)) {
$notification['android']['extras'] = $this->extras;
}
}
if (!is_null($this->iosNotification)) {
$notification['ios'] = $this->iosNotification;
if (is_null($this->iosNotification['alert'])) {
if (is_null($this->notificationAlert)) {
Response::error(ReturnCode::EXCEPTION, 'iOS alert can not be null');
} else {
$notification['ios']['alert'] = $this->notificationAlert;
}
}
} else {
if (!is_null($this->extras)) {
$notification['ios']['extras'] = $this->extras;
}
}
if (count($notification) > 0) {
$payload['notification'] = $notification;
}
if (count($this->message) > 0) {
$payload['message'] = $this->message;
}
if (!array_key_exists('notification', $payload) && !array_key_exists('message', $payload)) {
Response::error(ReturnCode::EXCEPTION, 'notification and message can not all be null');
}
if (!is_null($this->options)) {
$payload['options'] = $this->options;
}
return $payload;
}
public function send() {
return Http::post(Config::API_PUSH, $this->buildData());
}
}

View File

@ -0,0 +1,13 @@
<?php
/**
*
* @since 2017/03/24 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\JPush;
class Report {
}

View File

@ -0,0 +1,13 @@
<?php
/**
*
* @since 2017/03/24 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG\JPush;
class Schedule {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* 极光推送Manager
* @since 2017/03/24 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG;
use Home\ORG\JPush\Device;
use Home\ORG\JPush\Push;
use Home\ORG\JPush\Report;
use Home\ORG\JPush\Schedule;
class JPushSDK {
public static function push() {
return new Push();
}
public static function report() {
return new Report();
}
public static function device() {
return new Device();
}
public static function schedule() {
return new Schedule();
}
}

View File

@ -0,0 +1,92 @@
<?php
/**
* 输出类库
* @since 2017-03-14
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG;
class Response {
static private $debugInfo = array();
static private $dataType;
static private $successMsg = null;
/**
* 设置Debug信息
* @param $info
*/
static public function debug($info) {
if (APP_DEBUG) {
array_push(self::$debugInfo, $info);
}
}
/**
* 设置data字段数据类型规避空数组json_encode导致的数据类型混乱
* @param string $msg
*/
static public function setSuccessMsg($msg) {
self::$successMsg = $msg;
}
/**
* 设置data字段数据类型规避空数组json_encode导致的数据类型混乱
* @param int $type
*/
static public function setDataType($type = DataType::TYPE_OBJECT) {
self::$dataType = $type;
}
/**
* 错误输出
* @param integer $code 错误码,必填!
* @param string $msg 错误信息,选填,但是建议必须有!
* @param array $data
*/
static public function error($code, $msg = '', $data = array()) {
$returnData = array(
'code' => $code,
'msg' => $msg,
'data' => $data
);
if (!empty(self::$debugInfo)) {
$returnData['debug'] = self::$debugInfo;
}
header('Content-Type:application/json; charset=utf-8');
if (self::$dataType == DataType::TYPE_OBJECT && empty($data)) {
$returnStr = json_encode($returnData, JSON_FORCE_OBJECT);
} else {
$returnStr = json_encode($returnData);
}
ApiLog::setResponse($returnStr);
ApiLog::save();
exit($returnStr);
}
/**
* 成功返回
* @param $data
* @param null $code
*/
static public function success($data, $code = null) {
$code = is_null($code) ? ReturnCode::SUCCESS : $code;
$msg = is_null(self::$successMsg) ? '操作成功' : self::$successMsg;
$returnData = array(
'code' => $code,
'msg' => $msg,
'data' => $data
);
if (!empty(self::$debugInfo)) {
$returnData['debug'] = self::$debugInfo;
}
header('Content-Type:application/json; charset=utf-8');
$returnStr = json_encode($returnData);
ApiLog::setResponse($returnStr);
ApiLog::save();
exit($returnStr);
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* 错误码统一维护
* @since 2017/02/28 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Home\ORG;
class ReturnCode {
const SUCCESS = 1;
const INVALID = -1;
const DB_SAVE_ERROR = -2;
const DB_READ_ERROR = -3;
const CACHE_SAVE_ERROR = -4;
const CACHE_READ_ERROR = -5;
const FILE_SAVE_ERROR = -6;
const LOGIN_ERROR = -7;
const NOT_EXISTS = -8;
const JSON_PARSE_FAIL = -9;
const TYPE_ERROR = -10;
const NUMBER_MATCH_ERROR = -11;
const EMPTY_PARAMS = -12;
const DATA_EXISTS = -13;
const AUTH_ERROR = -14;
const OTHER_LOGIN = -16;
const VERSION_INVALID = -17;
const CURL_ERROR = -18;
const PARAM_INVALID = -995;
const ACCESS_TOKEN_TIMEOUT = -996;
const SESSION_TIMEOUT = -997;
const UNKNOWN = -998;
const EXCEPTION = -999;
static public function getConstants() {
$oClass = new \ReflectionClass(__CLASS__);
return $oClass->getConstants();
}
}

Some files were not shown because too many files have changed in this diff Show More