mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
ComposerUpdate
This commit is contained in:
parent
fe98588f9b
commit
6410c7bece
8
composer.lock
generated
8
composer.lock
generated
@ -937,12 +937,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||||
"reference": "29bdf3342f44b803db8206ca9cfba4415f1b7e44"
|
"reference": "47525f4cb63fb97937d44b45405a3c348a309cd2"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/29bdf3342f44b803db8206ca9cfba4415f1b7e44",
|
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/47525f4cb63fb97937d44b45405a3c348a309cd2",
|
||||||
"reference": "29bdf3342f44b803db8206ca9cfba4415f1b7e44",
|
"reference": "47525f4cb63fb97937d44b45405a3c348a309cd2",
|
||||||
"shasum": "",
|
"shasum": "",
|
||||||
"mirrors": [
|
"mirrors": [
|
||||||
{
|
{
|
||||||
@ -987,7 +987,7 @@
|
|||||||
],
|
],
|
||||||
"description": "ThinkPHP v6.0 Development Library",
|
"description": "ThinkPHP v6.0 Development Library",
|
||||||
"homepage": "http://thinkadmin.top",
|
"homepage": "http://thinkadmin.top",
|
||||||
"time": "2020-08-24T06:41:53+00:00"
|
"time": "2020-08-25T05:34:07+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "zoujingli/wechat-developer",
|
"name": "zoujingli/wechat-developer",
|
||||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -963,12 +963,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||||
"reference": "29bdf3342f44b803db8206ca9cfba4415f1b7e44"
|
"reference": "47525f4cb63fb97937d44b45405a3c348a309cd2"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/29bdf3342f44b803db8206ca9cfba4415f1b7e44",
|
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/47525f4cb63fb97937d44b45405a3c348a309cd2",
|
||||||
"reference": "29bdf3342f44b803db8206ca9cfba4415f1b7e44",
|
"reference": "47525f4cb63fb97937d44b45405a3c348a309cd2",
|
||||||
"shasum": "",
|
"shasum": "",
|
||||||
"mirrors": [
|
"mirrors": [
|
||||||
{
|
{
|
||||||
@ -985,7 +985,7 @@
|
|||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"topthink/framework": "^6.0"
|
"topthink/framework": "^6.0"
|
||||||
},
|
},
|
||||||
"time": "2020-08-24T06:41:53+00:00",
|
"time": "2020-08-25T05:34:07+00:00",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"think": {
|
"think": {
|
||||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// This file is automatically generated at:2020-08-24 14:45:27
|
// This file is automatically generated at:2020-08-25 13:48:22
|
||||||
declare (strict_types = 1);
|
declare (strict_types = 1);
|
||||||
return array (
|
return array (
|
||||||
0 => 'think\\admin\\Library',
|
0 => 'think\\admin\\Library',
|
||||||
|
@ -22,29 +22,41 @@ use think\App;
|
|||||||
use think\exception\HttpResponseException;
|
use think\exception\HttpResponseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统接口基础服务
|
* 通用接口基础服务
|
||||||
* Class InterfaceService
|
* Class InterfaceService
|
||||||
* @package think\admin\service
|
* @package think\admin\service
|
||||||
*/
|
*/
|
||||||
class InterfaceService extends Service
|
class InterfaceService extends Service
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 调试模式
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $debug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口认证账号
|
* 接口认证账号
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $appid;
|
private $appid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求数据
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口认证密钥
|
* 接口认证密钥
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $appkey;
|
private $appkey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口请求地址
|
* 接口请求地址
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $baseapi;
|
private $baseapi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口服务初始化
|
* 接口服务初始化
|
||||||
@ -65,6 +77,17 @@ class InterfaceService extends Service
|
|||||||
$this->baseapi = $baseapi ?: sysconf('data.interface_baseapi');
|
$this->baseapi = $baseapi ?: sysconf('data.interface_baseapi');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置调试模式
|
||||||
|
* @param boolean $debug
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function debug($debug)
|
||||||
|
{
|
||||||
|
$this->debug = boolval($debug);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取接口账号
|
* 获取接口账号
|
||||||
* @return string
|
* @return string
|
||||||
@ -75,33 +98,86 @@ class InterfaceService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求数据
|
* 获取接口地址
|
||||||
* @return array
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get(): array
|
public function getBaseUrl()
|
||||||
|
{
|
||||||
|
return $this->baseapi;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置授权账号
|
||||||
|
* @param string $appid
|
||||||
|
* @param string $appkey
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setAuth($appid, $appkey)
|
||||||
|
{
|
||||||
|
$this->appid = $appid;
|
||||||
|
$this->appkey = $appkey;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取请求数据
|
||||||
|
* @param boolean $check 验证数据
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getInput($check = true)
|
||||||
{
|
{
|
||||||
// 基础参数获取
|
// 基础参数获取
|
||||||
$input = ValidateHelper::instance()->init([
|
$this->input = ValidateHelper::instance()->init([
|
||||||
'appid.require' => lang('think_library_params_failed_empty', ['appid']),
|
'appid.require' => lang('think_library_params_failed_empty', ['appid']),
|
||||||
'nostr.require' => lang('think_library_params_failed_empty', ['nostr']),
|
'nostr.require' => lang('think_library_params_failed_empty', ['nostr']),
|
||||||
'time.require' => lang('think_library_params_failed_empty', ['time']),
|
'time.require' => lang('think_library_params_failed_empty', ['time']),
|
||||||
'sign.require' => lang('think_library_params_failed_empty', ['sign']),
|
'sign.require' => lang('think_library_params_failed_empty', ['sign']),
|
||||||
'data.require' => lang('think_library_params_failed_empty', ['data']),
|
'data.require' => lang('think_library_params_failed_empty', ['data']),
|
||||||
], 'post', [$this, 'baseError']);
|
], 'post', [$this, 'baseError']);
|
||||||
// 接口参数处理
|
|
||||||
if ($input['appid'] !== $this->appid) {
|
|
||||||
$this->baseError(lang('think_library_params_failed_auth'));
|
|
||||||
}
|
|
||||||
// 请求时间检查
|
// 请求时间检查
|
||||||
if (abs($input['time'] - time()) > 30) {
|
if (abs($this->input['time'] - time()) > 30) {
|
||||||
$this->baseError(lang('think_library_params_failed_time'));
|
$this->baseError(lang('think_library_params_failed_time'));
|
||||||
}
|
}
|
||||||
// 请求签名验证
|
return $check ? $this->showCheck() : $this->input;
|
||||||
if (!$this->_checkSign($input)) {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求数据签名验证
|
||||||
|
* @return bool|null
|
||||||
|
*/
|
||||||
|
public function checkInput()
|
||||||
|
{
|
||||||
|
if (empty($this->input)) $this->getInput(false);
|
||||||
|
if ($this->input['appid'] !== $this->appid) return null;
|
||||||
|
return md5("{$this->appid}#{$this->input['data']}#{$this->input['time']}#{$this->appkey}#{$this->input['nostr']}") === $this->input['sign'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示检查结果
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function showCheck()
|
||||||
|
{
|
||||||
|
if (is_null($check = $this->checkInput())) {
|
||||||
|
$this->baseError(lang('think_library_params_failed_auth'));
|
||||||
|
} elseif ($check === false) {
|
||||||
$this->baseError(lang('think_library_params_failed_sign'));
|
$this->baseError(lang('think_library_params_failed_sign'));
|
||||||
}
|
}
|
||||||
// 解析请求数据
|
return $this;
|
||||||
return json_decode($input['data'], true) ?: [];
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取请求参数
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getData()
|
||||||
|
{
|
||||||
|
if ($this->debug) {
|
||||||
|
return $this->app->request->request();
|
||||||
|
} else {
|
||||||
|
if (empty($this->input)) $this->getInput(true);
|
||||||
|
return json_decode($this->input['data'], true) ?: [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,8 +189,12 @@ class InterfaceService extends Service
|
|||||||
public function error($info, $data = '{-null-}', $code = 0)
|
public function error($info, $data = '{-null-}', $code = 0)
|
||||||
{
|
{
|
||||||
if ($data === '{-null-}') $data = new \stdClass();
|
if ($data === '{-null-}') $data = new \stdClass();
|
||||||
|
if ($this->debug) {
|
||||||
|
$this->baseError($info, $data, $code);
|
||||||
|
} else {
|
||||||
$this->baseResponse(lang('think_library_response_success'), ['code' => $code, 'info' => $info, 'data' => $data], 1);
|
$this->baseResponse(lang('think_library_response_success'), ['code' => $code, 'info' => $info, 'data' => $data], 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回复业务处理成功的消息
|
* 回复业务处理成功的消息
|
||||||
@ -125,8 +205,12 @@ class InterfaceService extends Service
|
|||||||
public function success($info, $data = '{-null-}', $code = 1)
|
public function success($info, $data = '{-null-}', $code = 1)
|
||||||
{
|
{
|
||||||
if ($data === '{-null-}') $data = new \stdClass();
|
if ($data === '{-null-}') $data = new \stdClass();
|
||||||
|
if ($this->debug) {
|
||||||
|
$this->baseSuccess($info, $data, $code);
|
||||||
|
} else {
|
||||||
$this->baseResponse(lang('think_library_response_success'), ['code' => $code, 'info' => $info, 'data' => $data], 1);
|
$this->baseResponse(lang('think_library_response_success'), ['code' => $code, 'info' => $info, 'data' => $data], 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回复根失败消息
|
* 回复根失败消息
|
||||||
@ -158,12 +242,15 @@ class InterfaceService extends Service
|
|||||||
*/
|
*/
|
||||||
public function baseResponse($info, $data = [], $code = 1)
|
public function baseResponse($info, $data = [], $code = 1)
|
||||||
{
|
{
|
||||||
$extend = ['code' => $code, 'info' => $info, 'data' => $data, 'appid' => $data['appid']];
|
$array = $this->_buildSign($data);
|
||||||
throw new HttpResponseException(json(array_merge($this->_buildSign($data), $extend)));
|
throw new HttpResponseException(json([
|
||||||
|
'code' => $code, 'info' => $info, 'time' => $array['time'], 'sign' => $array['sign'],
|
||||||
|
'appid' => input('appid', null), 'nostr' => $array['nostr'], 'data' => $data,
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口数据请求
|
* 接口数据模拟请求
|
||||||
* @param string $uri 接口地址
|
* @param string $uri 接口地址
|
||||||
* @param array $data 请求数据
|
* @param array $data 请求数据
|
||||||
* @return array
|
* @return array
|
||||||
@ -178,21 +265,7 @@ class InterfaceService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求数据签名验证
|
* 接口响应数据签名
|
||||||
* @param array $data 待检查数据
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
private function _checkSign(array $data): bool
|
|
||||||
{
|
|
||||||
if (isset($data['sign']) && isset($data['appid']) && isset($data['data']) && isset($data['time']) && isset($data['nostr'])) {
|
|
||||||
return md5("{$data['appid']}#{$data['data']}#{$data['time']}#{$this->appkey}#{$data['nostr']}") === $data['sign'];
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 接口数据签名
|
|
||||||
* @param array $data ['appid','nostr','time','sign','data']
|
* @param array $data ['appid','nostr','time','sign','data']
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user