12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Traits;
- use Illuminate\Support\Facades\Request;
- use App\Services\Interface\InterfaceService;
- use Illuminate\Http\JsonResponse;
- trait EavTrait
- {
- /**
- * @var InterfaceService
- */
- protected InterfaceService $interfaceService;
- /**
- * @var string 接口别名
- */
- protected string $interfaceAlias = '';
- /**
- * @param $interfaceAlias
- * @return JsonResponse|null
- * @throws \Exception
- */
- public function index($interfaceAlias): JsonResponse|null
- {
- return $this->manageRequest($interfaceAlias);
- }
- /**
- * @param $interfaceAlias
- * @return JsonResponse|null
- * @throws \Exception
- */
- private function manageRequest($interfaceAlias): JsonResponse|null
- {
- $this->interfaceAlias = $interfaceAlias;
- // 获取接口信息
- $this->interfaceService = new InterfaceService($interfaceAlias, $this->siteInfo);
- $errorMsg = $this->interfaceService->validator();
- if ($errorMsg) {
- return responseMessage(3001, $errorMsg);
- }
- $interfaceInfo = $this->interfaceService->getInterfaceInfo();
- if(Request::method() == strtoupper($interfaceInfo['request_method'])){
- return $this->interfaceService->exec();
- }else{
- return responseMessage(3001, "请求方式【".Request::method()."】,不被允许!");
- }
- }
- }
|