ApiController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Api\Controllers;
  3. use App\Api\Services\ApiService;
  4. use App\Base\Controllers\ApiBaseController;
  5. use App\Base\Library\Shorty;
  6. use Illuminate\Http\Request;
  7. class ApiController extends ApiBaseController
  8. {
  9. private $apiService;
  10. private $shorty;
  11. public function __construct(ApiService $apiService)
  12. {
  13. $this->apiService = $apiService;
  14. $this->shorty = new Shorty(config("app.domain"));
  15. }
  16. /**
  17. * @param string url 生成短地址的url
  18. * @return array
  19. * @throws \App\Base\Exceptions\ApiException
  20. * @throws
  21. * @api get /api/short 获取短地址
  22. * @group 短地址
  23. * @successExample
  24. * {"ret":0,"msg":"success.","data":{"id":2,"name":"物性任光保","remark":"nisi nostrud velit culpa ad","sort":100}}
  25. */
  26. public function getShortUrl(Request $request)
  27. {
  28. $this->validate($request, [
  29. 'url' => 'required'
  30. ], [
  31. 'url.required' => "url不能为空"
  32. ]);
  33. return $this->apiService->getShortUrl($request->input("url"));
  34. }
  35. /**
  36. * @param string url 生成短地址的url
  37. * @return array
  38. * @throws \App\Base\Exceptions\ApiException
  39. * @throws
  40. * @api get /api/short-hits 获取短地址访问量
  41. * @group 短地址
  42. * @successExample
  43. * {"ret":0,"msg":"success.","data":[]}
  44. */
  45. public function getShortUrlHits(Request $request)
  46. {
  47. $this->validate($request, [
  48. 'url' => 'required'
  49. ], [
  50. 'url.required' => "url不能为空"
  51. ]);
  52. return $this->apiService->getShortUrlHits($request->input("url"));
  53. }
  54. }