UsersController.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Oauth;
  3. use App\Consts\SysConsts;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use App\Modules\User\Services\QappUserService;
  7. use JWTAuth;
  8. class UsersController extends Controller
  9. {
  10. /**
  11. * @apiDefine Login 登录
  12. */
  13. /**
  14. * @apiVersion 1.0.0
  15. * @apiDescription 登录
  16. * @api {post} login 登录
  17. * @apiParam {String} device_no 设备号
  18. * @apiParam {String} device_info 设备信息json格式
  19. * @apiParam {Int} send_order_id send_order_id
  20. * @apiGroup Login
  21. * @apiName index
  22. * @apiSuccess {int} code 状态码
  23. * @apiSuccess {String} msg 信息
  24. * @apiSuccess {object} data 结果集
  25. * @apiSuccess {String} data.uid 用户uid
  26. * @apiSuccess {String} data.token token
  27. * @apiSuccess {Int} data.time 过期时间
  28. * @apiSuccessExample {json} Success-Response:
  29. * HTTP/1.1 200 OK
  30. * {
  31. * code: 0,
  32. * msg: "",
  33. * data: {
  34. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  35. * time:123455,
  36. * uid:1
  37. * }
  38. * }
  39. */
  40. public function index(Request $request)
  41. {
  42. $send_order_id = $request->input('send_order_id', 0);
  43. $device_no = $request->input('device_no', '');
  44. $device_info = $request->input('device_info', '');
  45. if ($device_no) {
  46. $data = QappUserService::loginStatic(compact('send_order_id', 'device_no', 'device_info'));
  47. return response()->success($data);
  48. } else {
  49. return response()->error('PARAM_ERROR');
  50. }
  51. }
  52. /**
  53. * @apiVersion 1.0.0
  54. * @apiDescription 刷新token
  55. * @api {get} RefreshToken 刷新token
  56. * @apiParam {String} [token] token
  57. * @apiHeader {String} [Authorization] token 两个token任选其一
  58. * @apiGroup Login
  59. * @apiName RefreshToken
  60. * @apiSuccess {int} code 状态码
  61. * @apiSuccess {String} msg 信息
  62. * @apiSuccess {object} data 结果集
  63. * @apiSuccess {String} data.token token
  64. * @apiSuccess {Int} data.time 过期时间
  65. * @apiSuccessExample {json} Success-Response:
  66. * HTTP/1.1 200 OK
  67. * {
  68. * code: 0,
  69. * msg: "",
  70. * data: {
  71. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  72. * time:123455
  73. * }
  74. * }
  75. */
  76. public function refreshToken()
  77. {
  78. try {
  79. $old_token = JWTAuth::getToken();
  80. $token = JWTAuth::refresh($old_token);
  81. $time = time() + SysConsts::ONE_HOUR_SECONDS * 2;
  82. return response()->success(compact('token', 'time'));
  83. } catch (Exception $e) {
  84. return response()->error('QAPP_NOT_LOGIN');
  85. }
  86. }
  87. }