yansongda /
laravel-api
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Yansongda\LaravelApi\Http\Controllers; |
||||
| 4 | |||||
| 5 | use Illuminate\Http\Request; |
||||
| 6 | use Illuminate\Support\Carbon; |
||||
| 7 | use Yansongda\LaravelApi\Api; |
||||
| 8 | use Yansongda\LaravelApi\Exceptions\InvalidAppException; |
||||
| 9 | use Yansongda\LaravelApi\Models\AccessToken; |
||||
| 10 | use Yansongda\LaravelApi\Models\App; |
||||
| 11 | |||||
| 12 | class TokenController |
||||
| 13 | { |
||||
| 14 | /** |
||||
| 15 | * Issue access_token. |
||||
| 16 | * |
||||
| 17 | * @author yansongda <[email protected]> |
||||
| 18 | * |
||||
| 19 | * @param Request $request |
||||
| 20 | * |
||||
| 21 | * @return Illuminate\Http\Response |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 22 | * @throws InvalidAppException |
||||
| 23 | * @throws \Yansongda\LaravelApi\Exceptions\GenerateAccessTokenException |
||||
| 24 | */ |
||||
| 25 | public function issueToken(Request $request) |
||||
| 26 | { |
||||
| 27 | $app = App::where('app_id', $request->app_id) |
||||
| 28 | ->where('app_secret', $request->app_secret) |
||||
| 29 | ->first(); |
||||
| 30 | |||||
| 31 | if (is_null($app)) { |
||||
| 32 | throw new InvalidAppException('Invalid App Info'); |
||||
| 33 | } |
||||
| 34 | |||||
| 35 | $accessToken = Api::generateAccessToken($app); |
||||
| 36 | |||||
| 37 | return response()->json([ |
||||
|
0 ignored issues
–
show
The function
response was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 38 | 'code' => 0, |
||||
| 39 | 'message' => 'success', |
||||
| 40 | 'data' => [ |
||||
| 41 | 'user_id' => $accessToken->user_id, |
||||
|
0 ignored issues
–
show
|
|||||
| 42 | 'app_id' => $accessToken->app_id, |
||||
|
0 ignored issues
–
show
|
|||||
| 43 | 'access_token' => $accessToken->access_token, |
||||
|
0 ignored issues
–
show
|
|||||
| 44 | 'expired_in' => config('api.ttl', 7200), |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 45 | ], |
||||
| 46 | ]); |
||||
| 47 | } |
||||
| 48 | } |
||||
| 49 |