mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 细节调整,新增加文档支持
This commit is contained in:
parent
f5673158b1
commit
b46a9f13ad
@ -70,7 +70,6 @@ class App extends Base {
|
||||
$groupArr = ApiGroup::all();
|
||||
$groupArr = Tools::buildArrFromObj($groupArr);
|
||||
$res['groupInfo'] = array_column($groupArr, 'name', 'hash');
|
||||
$res['groupInfo']['default'] = '默认分组';
|
||||
$id = $this->request->get('id', 0);
|
||||
if ($id) {
|
||||
$appInfo = ApiApp::get($id)->toArray();
|
||||
|
@ -43,21 +43,6 @@ class Base extends Controller {
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将二维数组变成指定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;
|
||||
}
|
||||
|
||||
protected function debug($data) {
|
||||
if ($data) {
|
||||
$this->debug[] = $data;
|
||||
|
@ -56,13 +56,13 @@ class User extends Base {
|
||||
$query->whereIn('uid', $idArr);
|
||||
});
|
||||
$userData = Tools::buildArrFromObj($userData);
|
||||
$userData = $this->buildArrByNewKey($userData, 'uid');
|
||||
$userData = Tools::buildArrByNewKey($userData, 'uid');
|
||||
|
||||
$userGroup = ApiAuthGroupAccess::all(function($query) use ($idArr) {
|
||||
$query->whereIn('uid', $idArr);
|
||||
});
|
||||
$userGroup = Tools::buildArrFromObj($userGroup);
|
||||
$userGroup = $this->buildArrByNewKey($userGroup, 'uid');
|
||||
$userGroup = Tools::buildArrByNewKey($userGroup, 'uid');
|
||||
|
||||
foreach ($listInfo as $key => $value) {
|
||||
if (isset($userData[$value['id']])) {
|
||||
@ -140,7 +140,7 @@ class User extends Base {
|
||||
$query->whereIn('uid', $uidArr);
|
||||
});
|
||||
$userData = Tools::buildArrFromObj($userData);
|
||||
$userData = $this->buildArrByNewKey($userData, 'uid');
|
||||
$userData = Tools::buildArrByNewKey($userData, 'uid');
|
||||
|
||||
foreach ($userInfo as $key => $value) {
|
||||
if (isset($userData[$value['id']])) {
|
||||
|
@ -49,6 +49,14 @@ class BuildToken extends Base {
|
||||
return $this->buildSuccess($return);
|
||||
}
|
||||
|
||||
public function e1() {
|
||||
return $this->buildSuccess('e1');
|
||||
}
|
||||
|
||||
public function e2() {
|
||||
return $this->buildSuccess('e2');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据AppSecret和数据生成相对应的身份认证秘钥
|
||||
* @param $appSecret
|
||||
|
@ -9,10 +9,18 @@ $afterBehavior = ['\app\api\behavior\ApiAuth', '\app\api\behavior\RequestFilter'
|
||||
|
||||
return [
|
||||
'[api]' => [
|
||||
'58bf98c1dcb63' => [
|
||||
'5a9363c133719' => [
|
||||
'api/BuildToken/getAccessToken',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'5a93646b40ab5' => [
|
||||
'api/BuildToken/e1',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'5a93648c769f8' => [
|
||||
'api/BuildToken/e2',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'__miss__' => ['api/Miss/index'],
|
||||
],
|
||||
'[wiki]' => [
|
||||
@ -20,6 +28,30 @@ return [
|
||||
'wiki/index/login',
|
||||
['method' => 'get']
|
||||
],
|
||||
'doLogin' => [
|
||||
'wiki/index/doLogin',
|
||||
['method' => 'post']
|
||||
],
|
||||
'index' => [
|
||||
'wiki/index/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'calculation' => [
|
||||
'wiki/index/calculation',
|
||||
['method' => 'get']
|
||||
],
|
||||
'errorCode' => [
|
||||
'wiki/index/errorCode',
|
||||
['method' => 'get']
|
||||
],
|
||||
'detail/:hash' => [
|
||||
'wiki/index/detail',
|
||||
['method' => 'get']
|
||||
],
|
||||
'logout' => [
|
||||
'wiki/index/logout',
|
||||
['method' => 'get']
|
||||
],
|
||||
'__miss__' => ['api/Miss/index'],
|
||||
],
|
||||
];
|
||||
|
@ -97,4 +97,19 @@ class Tools {
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将二维数组变成指定key
|
||||
* @param $array
|
||||
* @param $keyName
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
* @return array
|
||||
*/
|
||||
public static function buildArrByNewKey($array, $keyName = 'id') {
|
||||
$list = array();
|
||||
foreach ($array as $item) {
|
||||
$list[$item[$keyName]] = $item;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,83 @@
|
||||
namespace app\wiki\controller;
|
||||
|
||||
|
||||
use think\Config;
|
||||
use think\Controller;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
use think\View as ViewTemplate;
|
||||
use think\Url;
|
||||
|
||||
class Base extends Controller {
|
||||
|
||||
public function _initialize() {
|
||||
protected $appInfo;
|
||||
|
||||
public function checkLogin() {
|
||||
$appInfo = session('app_info');
|
||||
if ($appInfo) {
|
||||
$this->appInfo = json_decode($appInfo, true);
|
||||
} else {
|
||||
$this->redirect(url('/wiki/login'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []) {
|
||||
if (is_null($url)) {
|
||||
$url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);';
|
||||
} elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
|
||||
$url = Url::build($url);
|
||||
}
|
||||
|
||||
$type = 'html';
|
||||
$result = [
|
||||
'code' => 0,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url,
|
||||
'wait' => $wait,
|
||||
];
|
||||
|
||||
if ('html' == strtolower($type)) {
|
||||
$template = Config::get('template');
|
||||
$view = Config::get('view_replace_str');
|
||||
|
||||
$result = ViewTemplate::instance($template, $view)
|
||||
->fetch(Config::get('dispatch_error_tmpl'), $result);
|
||||
}
|
||||
|
||||
$response = Response::create($result, $type)->header($header);
|
||||
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
|
||||
public function success($msg = '', $url = null, $data = '', $wait = 3, array $header = []) {
|
||||
if (is_null($url) && !is_null(Request::instance()->server('HTTP_REFERER'))) {
|
||||
$url = Request::instance()->server('HTTP_REFERER');
|
||||
} elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
|
||||
$url = Url::build($url);
|
||||
}
|
||||
|
||||
$type = 'html';
|
||||
$result = [
|
||||
'code' => 1,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url,
|
||||
'wait' => $wait,
|
||||
];
|
||||
|
||||
if ('html' == strtolower($type)) {
|
||||
$template = Config::get('template');
|
||||
$view = Config::get('view_replace_str');
|
||||
|
||||
$result = ViewTemplate::instance($template, $view)
|
||||
->fetch(Config::get('dispatch_success_tmpl'), $result);
|
||||
}
|
||||
|
||||
$response = Response::create($result, $type)->header($header);
|
||||
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,15 +8,36 @@
|
||||
namespace app\wiki\controller;
|
||||
|
||||
|
||||
use app\model\ApiApp;
|
||||
use app\model\ApiFields;
|
||||
use app\model\ApiGroup;
|
||||
use app\model\ApiList;
|
||||
use app\util\DataType;
|
||||
use app\util\ReturnCode;
|
||||
use app\util\Tools;
|
||||
|
||||
class Index extends Base {
|
||||
|
||||
/**
|
||||
* 获取应用列表
|
||||
* @return \think\response\View
|
||||
* @throws \think\exception\DbException
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function index() {
|
||||
return $this->fetch();
|
||||
$this->checkLogin();
|
||||
|
||||
$groupInfo = ApiGroup::all();
|
||||
$groupInfo = Tools::buildArrFromObj($groupInfo);
|
||||
$groupInfo = Tools::buildArrByNewKey($groupInfo, 'hash');
|
||||
|
||||
$this->appInfo = ApiApp::get(['app_id' => $this->appInfo['app_id']]);
|
||||
$this->appInfo['app_api_show'] = json_decode($this->appInfo['app_api_show'], true);
|
||||
|
||||
return view('', [
|
||||
'groupInfo' => $groupInfo,
|
||||
'appInfo' => $this->appInfo
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail() {
|
||||
@ -58,10 +79,13 @@ class Index extends Base {
|
||||
}
|
||||
|
||||
public function calculation() {
|
||||
return $this->fetch();
|
||||
$this->checkLogin();
|
||||
|
||||
return view();
|
||||
}
|
||||
|
||||
public function errorCode() {
|
||||
$this->checkLogin();
|
||||
$codeArr = ReturnCode::getConstants();
|
||||
$errorInfo = array(
|
||||
ReturnCode::SUCCESS => '请求成功',
|
||||
@ -81,21 +105,55 @@ class Index extends Base {
|
||||
ReturnCode::AUTH_ERROR => '权限认证失败',
|
||||
ReturnCode::OTHER_LOGIN => '别的终端登录',
|
||||
ReturnCode::VERSION_INVALID => 'API版本非法',
|
||||
ReturnCode::CURL_ERROR => 'CURL操作异常',
|
||||
ReturnCode::RECORD_NOT_FOUND => '记录未找到',
|
||||
ReturnCode::DELETE_FAILED => '删除失败',
|
||||
ReturnCode::ADD_FAILED => '添加记录失败',
|
||||
ReturnCode::UPDATE_FAILED => '添加记录失败',
|
||||
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);
|
||||
|
||||
return $this->fetch();
|
||||
return view('', [
|
||||
'errorInfo' => $errorInfo,
|
||||
'codeArr' => $codeArr
|
||||
]);
|
||||
}
|
||||
|
||||
public function login() {
|
||||
return view();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理wiki登录
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\DbException
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function doLogin() {
|
||||
$appId = $this->request->post('appId');
|
||||
$appSecret = $this->request->post('appSecret');
|
||||
|
||||
$appInfo = ApiApp::get(['app_id' => $appId, 'app_secret' => $appSecret]);
|
||||
if (!empty($appInfo)) {
|
||||
if ($appInfo->app_status) {
|
||||
//保存用户信息和登录凭证
|
||||
session('app_info', json_encode($appInfo));
|
||||
$this->success('登录成功', url('/wiki/index'));
|
||||
} else {
|
||||
$this->error('当前应用已被封禁,请联系管理员');
|
||||
}
|
||||
} else {
|
||||
$this->error('AppId或AppSecret错误');
|
||||
}
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
session('app_info', null);
|
||||
$this->success('退出成功', url('/wiki/login'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
<div class="ui text container" style="max-width: none !important;">
|
||||
<div class="ui floating message">
|
||||
<h1 class="ui header">{:config('apiAdmin.APP_NAME')} - 算法说明 </h1>
|
||||
<a href="{:url('/wiki/group')}">
|
||||
<a href="{:url('/wiki/index')}">
|
||||
<button class="ui green button" style="margin-top: 15px">返回接口文档</button>
|
||||
</a>
|
||||
<div class="ui red message">
|
||||
@ -18,10 +18,10 @@
|
||||
</div>
|
||||
<div class="ui piled segment">
|
||||
<div class="ui horizontal divider">简介</div>
|
||||
<p>当前算法主要服务于获取身份令牌(AccessToken)所进行的身份认证秘钥的计算。在请求高级接口的时候,系统会验证应用的合法性,也就是验证AccessToken。所以AccessToken是请求API的必要参数。</p>
|
||||
<p>在请求获取AccessToken的接口时候,服务器会对用户合法性进行核验,具体的接口请求字段,请参看具体的接口文档。</p>
|
||||
<p>当前算法主要服务于获取身份令牌(AccessToken)所进行的身份认证秘钥(signature)的计算。在请求高级接口的时候,系统会验证应用的合法性,也就是验证AccessToken。所以AccessToken是请求API的必要参数。</p>
|
||||
<p>在请求获取AccessToken的接口时候,服务器会对用户合法性(signature)进行核验,具体的接口请求字段,请参看具体的接口文档。</p>
|
||||
<div class="ui horizontal divider">一、获取app_id和app_secret</div>
|
||||
<p>目前获取应用ID和应用秘钥是人工手动发放,请联系后台开发。<b>请注意:app_secret非常重要请妥善保管</b></p>
|
||||
<p>目前获取应用ID和应用秘钥是由系统管理员发放,如果你还没有请联系管理员。<b>请注意:app_secret非常重要请妥善保管</b></p>
|
||||
<div class="ui horizontal divider">二、准备加密对象,并且根据字段名降序排序</div>
|
||||
<pre>//排序好后应当是如下所示的数据
|
||||
{
|
||||
@ -41,4 +41,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -10,7 +10,7 @@
|
||||
<div class="ui text container" style="max-width: none !important;">
|
||||
<div class="ui floating message">
|
||||
<h1 class="ui header">{:config('apiAdmin.APP_NAME')} - 错误码说明</h1>
|
||||
<a href="{:url('/wiki/group')}">
|
||||
<a href="{:url('/wiki/index')}">
|
||||
<button class="ui green button" style="margin-top: 15px">返回接口文档</button>
|
||||
</a>
|
||||
<table class="ui red celled striped table">
|
||||
@ -42,4 +42,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -25,43 +25,54 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui cards four column">
|
||||
<div class="card column">
|
||||
<a class="image" href="#">
|
||||
<img src="http://static10.photo.sina.com.cn/middle/5a3ab1b1x9961016a8699&690">
|
||||
</a>
|
||||
<div class="content">
|
||||
<a class="header">
|
||||
XXX分组
|
||||
</a>
|
||||
<a class="meta">
|
||||
<span class="group" style="font-size: 0.8em;">2017-07-17</span>
|
||||
</a>
|
||||
<a class="description" style="display: block;font-size: 0.8em;">
|
||||
{php}
|
||||
$vo['success_place_description'] = '需要啥需要啥需要啥需要啥需要啥需要啥需要啥需要啥需要啥需要啥需要啥需要啥';
|
||||
$len = mb_strlen($vo['success_place_description'], 'utf8');
|
||||
if($len > 31) {
|
||||
echo mb_substr($vo['success_place_description'], 0, 31, 'utf8') . ' ...';
|
||||
} else {
|
||||
echo $vo['success_place_description'];
|
||||
}
|
||||
{/php}
|
||||
{volist name="appInfo['app_api_show']" id="vo"}
|
||||
{php}
|
||||
$apiLength = count($vo);
|
||||
{/php}
|
||||
{if condition="$apiLength"}
|
||||
<div class="card column">
|
||||
<a class="image" href="{:url('/wiki/detail/' . $key)}">
|
||||
<img src="http://static10.photo.sina.com.cn/middle/5a3ab1b1x9961016a8699&690">
|
||||
</a>
|
||||
<div class="content">
|
||||
<a class="header" href="{:url('/wiki/detail/' . $key)}">
|
||||
{$groupInfo[$key]['name']}
|
||||
</a>
|
||||
<a class="meta" href="{:url('/wiki/detail/' . $key)}">
|
||||
<span class="group" style="font-size: 0.8em;">{:date('Y-m-d', $groupInfo[$key]['updateTime'])}</span>
|
||||
</a>
|
||||
<a class="description" style="display: block;font-size: 0.8em;" href="{:url('/wiki/detail/' . $key)}">
|
||||
{php}
|
||||
$len = mb_strlen($groupInfo[$key]['description'], 'utf8');
|
||||
if($len > 31) {
|
||||
echo mb_substr($groupInfo[$key]['description'], 0, 31, 'utf8') . ' ...';
|
||||
} else {
|
||||
echo $groupInfo[$key]['description'];
|
||||
}
|
||||
if ($groupInfo[$key]['hot'] >= 10000) {
|
||||
$hot = sprintf("%.1f", $groupInfo[$key]['hot']/10000) . '万';
|
||||
} else {
|
||||
$hot = $groupInfo[$key]['hot'];
|
||||
}
|
||||
{/php}
|
||||
</a>
|
||||
</div>
|
||||
<div class="extra content" style="font-size: 0.9em">
|
||||
<a class="right floated created" href="{:url('/wiki/detail/' . $key)}">
|
||||
<i class="fire icon"></i>
|
||||
热度{$hot}
|
||||
</a>
|
||||
<a class="friends" href="{:url('/wiki/detail/' . $key)}">
|
||||
<i class="cubes icon"></i>
|
||||
共{$apiLength}个接口
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="extra content" style="font-size: 0.9em">
|
||||
<a class="right floated created">
|
||||
<i class="fire icon"></i>
|
||||
热度29.1万
|
||||
</a>
|
||||
<a class="friends">
|
||||
<i class="cubes icon"></i>
|
||||
共190个接口
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/volist}
|
||||
</div>
|
||||
<p>© Powered By <a href="http://www.apiadmin.org/" target="_blank">{:config('apiAdmin.APP_NAME')} {:config('apiAdmin.APP_VERSION')}</a> <p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -69,7 +69,7 @@
|
||||
欢迎使用{:config('apiAdmin.APP_NAME')}在线文档
|
||||
</div>
|
||||
</h2>
|
||||
<form class="ui large form">
|
||||
<form class="ui large form" method="post" action="{:url('/wiki/doLogin')}">
|
||||
<div class="ui stacked segment">
|
||||
<div class="field">
|
||||
<div class="ui left icon input">
|
||||
@ -93,4 +93,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user