ApiController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Helpers\Utils;
  4. use Illuminate\Http\Request;
  5. use App\Services\CallApiService;
  6. class ApiController
  7. {
  8. /**
  9. * @var CallApiService
  10. */
  11. private $callApiService;
  12. public function __construct(CallApiService $callApiService)
  13. {
  14. $this->callApiService = $callApiService;
  15. }
  16. public function send(Request $request)
  17. {
  18. return $this->getData($request);
  19. }
  20. public function callApi($url, $data, $headers = null, $type = 'erp')
  21. {
  22. $response = $this->callApiService->callApi([
  23. 'url' => $url,
  24. 'data' => $data,
  25. 'headers' => $headers,
  26. 'type' => $type,
  27. ]);
  28. return $response;
  29. }
  30. public function getData(Request $request)
  31. {
  32. return $this->callApiService->getData($request);
  33. // if ($request['is_user_page'] && empty(session('user'))) {
  34. // return ['apiStatus' => 555, 'body' => 'User session not found'];
  35. // }
  36. //
  37. // if ($request['encode_status']) {
  38. // $request['data'] = json_decode($request['data']);
  39. // }
  40. //
  41. // $response = $this->callApiService->callApi([
  42. // 'url' => $request['url'],
  43. // 'data' => $request['data'],
  44. // 'headers' => $request['headers'],
  45. // 'type' => $request['type'],
  46. // ], true);
  47. //
  48. // if ($request['para_cache'] && ! isset($response['apiStatus'])) {
  49. // Utils::putParamCache($request['para_cache'], $request['url'], json_encode($request['data']));
  50. // }
  51. //
  52. // return $response;
  53. }
  54. }