123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Api\Controllers;
- use App\Api\Services\ApiService;
- use App\Base\Controllers\ApiBaseController;
- use App\Base\Library\Shorty;
- use Illuminate\Http\Request;
- class ApiController extends ApiBaseController
- {
- private $apiService;
- private $shorty;
- public function __construct(ApiService $apiService)
- {
- $this->apiService = $apiService;
- $this->shorty = new Shorty(config("app.domain"));
- }
- /**
- * @param string url 生成短地址的url
- * @return array
- * @throws \App\Base\Exceptions\ApiException
- * @throws
- * @api get /api/short 获取短地址
- * @group 短地址
- * @successExample
- * {"ret":0,"msg":"success.","data":{"id":2,"name":"物性任光保","remark":"nisi nostrud velit culpa ad","sort":100}}
- */
- public function getShortUrl(Request $request)
- {
- $this->validate($request, [
- 'url' => 'required'
- ], [
- 'url.required' => "url不能为空"
- ]);
- return $this->apiService->getShortUrl($request->input("url"));
- }
- /**
- * @param string url 生成短地址的url
- * @return array
- * @throws \App\Base\Exceptions\ApiException
- * @throws
- * @api get /api/short-hits 获取短地址访问量
- * @group 短地址
- * @successExample
- * {"ret":0,"msg":"success.","data":[]}
- */
- public function getShortUrlHits(Request $request)
- {
- $this->validate($request, [
- 'url' => 'required'
- ], [
- 'url.required' => "url不能为空"
- ]);
- return $this->apiService->getShortUrlHits($request->input("url"));
- }
- }
|