Commit f32854e9 authored by hj's avatar hj

更新提交

parent 9c84835d
<?php <?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Http\Controllers\V1; namespace App\Http\Controllers\V1;
use App\Services\CustomerService; use App\Exceptions\ServerRunTimeException;
use App\Services\AuthService;
use App\Services\YyBao\CustomersService;
use App\Support\Traits\Helpers;
use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use Jiannei\Response\Laravel\Support\Facades\Response; use Jiannei\Response\Laravel\Support\Facades\Response;
use Jiannei\Response\Laravel\Support\Traits\ExceptionTrait; use Jiannei\Response\Laravel\Support\Traits\ExceptionTrait;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use OpenApi\Annotations\Info; use OpenApi\Annotations\Info;
use OpenApi\Annotations\Schema;
use OpenApi\Annotations\Server;
use OpenApi\Annotations\Property; use OpenApi\Annotations\Property;
use OpenApi\Annotations\SecurityScheme; use OpenApi\Annotations\Schema;
/** /**
* *
* @Info( * @Info(
* version="1.0", * version="1.0",
* title="罗恩开放平台 API接口文档" * title="研易宝"
* ) * )
* *
* @Schema( * @Schema(
...@@ -46,11 +38,24 @@ use OpenApi\Annotations\SecurityScheme; ...@@ -46,11 +38,24 @@ use OpenApi\Annotations\SecurityScheme;
* ) * )
* *
*/ */
abstract class Controller extends BaseController abstract class Controller extends BaseController
{ {
use ExceptionTrait; use Helpers, ExceptionTrait;
public function getRequestRulesInputs(Request $request): array
{
$inputs = $request->request->all();
$rules = $request->rules();
foreach($inputs as $key => $in){
if(!empty($rules) && !in_array($key,array_keys($rules))){
unset($inputs[$key]);
}
$inputs[$key] = $this->stripHtml($in);
}
$inputs['platform_source'] = current($this->getUriPath());
return $inputs;
}
/** /**
* request 参数验证 * request 参数验证
...@@ -76,26 +81,36 @@ abstract class Controller extends BaseController ...@@ -76,26 +81,36 @@ abstract class Controller extends BaseController
return true; return true;
} }
protected function returnErrorExecptionResponse(\Exception $exception, string $message = '') public function getGuardName()
{ {
if($exception->getCode() == 500 || $exception->getCode() == 502){ return app()->request->headers->get('guardName');
return Response::fail($exception->getMessage(),200);
}
return Response::fail($message == '' ? $exception->getMessage() : $message,200);
} }
protected function checkCustomerType($customerCode,$type) protected function returnErrorExecptionResponse(\Exception $exception, string $message = ''): \Illuminate\Http\JsonResponse
{ {
$customer = app(CustomerService::class)->getPlatformCustomer(['cus_number' => $customerCode, 'cus_type' => $type]); if($exception instanceof AuthenticationException){
if($customer){ return Response::fail($exception->getMessage(),401);
if($customer['cus_type'] != $type){ }
switch($type){ if($exception->getCode() == 500 || $exception->getCode() == 0){
case 'bh' : $this->returnErrorExecptionResponse(new AuthenticationException('不是百化用户,无法访问该类型接口'));break; return Response::fail($exception->getMessage(),500);
case 'rhawn' : $this->returnErrorExecptionResponse(new AuthenticationException('不是罗恩用户,无法访问该类型接口'));break; }else{
case 'chemsite' : $this->returnErrorExecptionResponse(new AuthenticationException('不是chemsite用户,无法访问该类型接口'));break; return Response::fail($message == '' ? $exception->getMessage() : $message,$exception->getCode());
default : $this->returnErrorExecptionResponse(new AuthenticationException('用户类型未知'));
}
}
} }
} }
public function setService($service)
{
$this->service = $service;
}
public function getService()
{
return $this->service;
}
public function getUriPath()
{
$urls = explode('/',app()->request->url);
return array_values(array_filter($urls));
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment