You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.0 KiB
118 lines
3.0 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\BaseController;
|
|
use app\service\BaseService;
|
|
use app\service\SignService;
|
|
use app\service\user\UserService;
|
|
use log\LogOpe;
|
|
use think\exception\HttpResponseException;
|
|
use think\facade\Log;
|
|
use think\facade\Request;
|
|
|
|
class Base extends BaseController
|
|
{
|
|
|
|
/**
|
|
* 无需检测的方法.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $noNeedCheck = ['apiDoc'];
|
|
|
|
protected $log = null;
|
|
protected $apilog = null;
|
|
protected $token = null;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->log = new LogOpe('api/'.get_class($this) . 'Controller');
|
|
$this->apilog = new LogOpe("request/".date("YmdH") . "Request");
|
|
|
|
if(!$this->match($this->noNeedCheck)){
|
|
// $this->checkSign();
|
|
}
|
|
$this->checkUser();
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 检测当前控制器和方法是否匹配传递的数组.
|
|
*
|
|
* @param array $arr 需要验证权限的数组
|
|
* @return bool
|
|
*/
|
|
public function match($arr = [])
|
|
{
|
|
$request = Request::instance();
|
|
$arr = is_array($arr) ? $arr : explode(',', $arr);
|
|
if (! $arr) {
|
|
return false;
|
|
}
|
|
$arr = array_map('strtolower', $arr);
|
|
// 是否存在
|
|
if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) {
|
|
return true;
|
|
}
|
|
// 没找到匹配
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 请求校验(抛异常)
|
|
* @param $class
|
|
* @param string $scene
|
|
* @param string|null $method 指定参数类型
|
|
* @param bool $limit 限制请求类型
|
|
* @throws \Exception
|
|
*/
|
|
protected function checkVaild($class, $scene = '', $method = null, $limit = false) {
|
|
(new BaseService())->checkVaild($class, $scene, $method, $limit);
|
|
}
|
|
|
|
/**
|
|
* 校验签名.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function checkSign()
|
|
{
|
|
$signService = new SignService();
|
|
// 获取请求数据
|
|
$post = $this->request->post(['appkey', 'timestamp']);
|
|
// 获取签名以及key
|
|
$sign = isset($_SERVER['HTTP_SIGN']) ? $_SERVER['HTTP_SIGN'] : '';
|
|
if (!$sign){
|
|
throw new HttpResponseException(_error('缺少sign', 400));
|
|
}
|
|
$signService->checkSign($post, $sign);
|
|
}
|
|
|
|
public function checkUser(){
|
|
$user_isli = $this->request->post('user_isli', '');
|
|
$userService = new UserService();
|
|
if(!empty($user_isli)){
|
|
// $userService->checkUser($user_isli);
|
|
}
|
|
}
|
|
|
|
protected function curl_request_post($url="", $data=[]){
|
|
if (empty($url) || empty($data)){
|
|
return null;
|
|
}
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
// 数据
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
|
|
$res = curl_exec($curl);
|
|
curl_close($curl);
|
|
return $res;
|
|
}
|
|
|
|
}
|