商用授权接口
Showing
3 changed files
with
13 additions
and
6 deletions
... | @@ -124,6 +124,13 @@ class ClientCredentialsController | ... | @@ -124,6 +124,13 @@ class ClientCredentialsController |
124 | 124 | ||
125 | public function test() | 125 | public function test() |
126 | { | 126 | { |
127 | return ''; | 127 | $params = [ |
128 | time(), | ||
129 | rand(10000, 999999), | ||
130 | 'i85ShUQ6' | ||
131 | ]; | ||
132 | sort($params, SORT_STRING); | ||
133 | |||
134 | return [$params, sha1(join('&', $params))]; | ||
128 | } | 135 | } |
129 | } | 136 | } | ... | ... |
... | @@ -62,12 +62,12 @@ class CheckSignature | ... | @@ -62,12 +62,12 @@ class CheckSignature |
62 | $only = Arr::only($params, ['client_id', 'timestamp', 'nonce']); | 62 | $only = Arr::only($params, ['client_id', 'timestamp', 'nonce']); |
63 | sort($only, SORT_STRING); | 63 | sort($only, SORT_STRING); |
64 | $tmpStr = sha1(join('&', $only)); | 64 | $tmpStr = sha1(join('&', $only)); |
65 | if ($params['sign'] != $tmpStr) { | 65 | if ($params['signature'] != $tmpStr) { |
66 | return Response::successWithCode(ErrorCode::INVALID_SIGNATURE, ErrorCode::$messages[ErrorCode::INVALID_SIGNATURE]); | 66 | return Response::successWithCode(ErrorCode::INVALID_SIGNATURE, ErrorCode::$messages[ErrorCode::INVALID_SIGNATURE]); |
67 | } | 67 | } |
68 | //防重放机制 | 68 | //防重放机制 |
69 | //检查时间戳是否有效 | 69 | //检查时间戳是否有效 |
70 | if (time() < $params['timestamp'] + self::TIMESTAMP_LIMIT) { | 70 | if (time() > $params['timestamp'] + self::TIMESTAMP_LIMIT) { |
71 | return Response::successWithCode(ErrorCode::INVALID_TIMESTAMP, ErrorCode::$messages[ErrorCode::INVALID_TIMESTAMP]); | 71 | return Response::successWithCode(ErrorCode::INVALID_TIMESTAMP, ErrorCode::$messages[ErrorCode::INVALID_TIMESTAMP]); |
72 | } | 72 | } |
73 | //随机数是否已被使用 | 73 | //随机数是否已被使用 | ... | ... |
... | @@ -6,8 +6,8 @@ Route::group(['prefix' => 'client-credentials'], function () { | ... | @@ -6,8 +6,8 @@ Route::group(['prefix' => 'client-credentials'], function () { |
6 | Route::get('getApp', "ClientCredentialsController@getApp"); | 6 | Route::get('getApp', "ClientCredentialsController@getApp"); |
7 | Route::get('token', "ClientCredentialsController@getAccessToken"); | 7 | Route::get('token', "ClientCredentialsController@getAccessToken"); |
8 | }); | 8 | }); |
9 | Route::get('test', "ClientCredentialsController@test"); | 9 | //Route::get('test', "ClientCredentialsController@test"); |
10 | Route::get('song/list', "SongController@list"); | ||
11 | Route::group(['middleware' => 'check.signature'], function () { | ||
12 | 10 | ||
11 | Route::group(['middleware' => 'check.signature'], function () { | ||
12 | Route::get('song/list', "SongController@list"); | ||
13 | }); | 13 | }); | ... | ... |
-
Please register or sign in to post a comment