api.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | API Routes
  5. |--------------------------------------------------------------------------
  6. |
  7. | Here is where you can register API routes for your application. These
  8. | routes are loaded by the RouteServiceProvider within a group which
  9. | is assigned the "api" middleware group. Enjoy building your API!
  10. |
  11. */
  12. $api = app('Dingo\Api\Routing\Router');
  13. $api->version('v1', [
  14. 'namespace' => 'App\Http\Controllers\Api',
  15. 'middleware' => ['serializer:array','cors','activity_log','bindings']
  16. ], function ($api) {
  17. $api->group([
  18. 'middleware' => 'api.throttle',
  19. 'limit' => config('api.rate_limits.access.limit'),
  20. 'expires' => config('api.rate_limits.access.expires')
  21. ], function ($api) { //游客可以访问的接口
  22. /*
  23. |--------------------------------------------------------------
  24. | 登录
  25. |--------------------------------------------------------------
  26. */
  27. $api->group(['prefix' => 'login'], function ($api) {
  28. $api->post('/loginByMobile', 'AuthorizationsController@loginByMobile')->name('login.mobile');
  29. $api->post('/loginByPassword', 'AuthorizationsController@loginByAccountPassword')->name('login.password');
  30. $api->post('/forgetPassword', 'AuthorizationsController@forgetPassword')->name('login.forget');
  31. $api->post('/register', 'AuthorizationsController@register')->name('login.register');
  32. });
  33. /*
  34. |--------------------------------------------------------------
  35. | 发送短信验证码
  36. |--------------------------------------------------------------
  37. */
  38. $api->group(['prefix' => 'sms'], function ($api) {
  39. $api->get('/send', 'SmsController@send')->name('sms.send');
  40. });
  41. });
  42. //需要 token 验证的接口
  43. $api->group(['middleware' => 'api.auth'], function ($api) {
  44. /*
  45. |--------------------------------------------------------------
  46. | 用户信息相关
  47. |--------------------------------------------------------------
  48. */
  49. $api->group(['prefix' => 'user'], function ($api) {
  50. //设置性别
  51. $api->post('/checksex', 'UserController@checksex')->name('user.checksex');
  52. //设置资料(初次注册进入时)
  53. $api->post('/setinfo', 'UserController@setinfo')->name('user.setinfo');
  54. });
  55. /*
  56. |--------------------------------------------------------------
  57. | 退出登录
  58. |--------------------------------------------------------------
  59. */
  60. $api->put('/logout', 'AuthorizationsController@logout')->name('logout');
  61. });
  62. });