UsersController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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} js_code js_code
  18. * @apiParam {Int} distribution_channel_id distribution_channel_id
  19. * @apiParam {String} sign 签名
  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. $params = $request->except('_url');
  43. $send_order_id = $request->input('send_order_id', 0);
  44. $device_no = $request->input('device_no', '');
  45. $device_info = $request->input('device_info', '');
  46. $sign = $request->input('sign', '');
  47. $key = 'a!A&AFRWT65Nb3NlklezUiqHyQAA@Z8M';
  48. if ($sign == _sign($params, $key)) {
  49. if ($device_no) {
  50. $data = QappUserService::loginStatic(compact('send_order_id', 'device_no', 'device_info'));
  51. return response()->success($data);
  52. } else {
  53. return response()->error('PARAM_ERROR');
  54. }
  55. } else {
  56. return response()->error('QAPP_SIGN_ERROR');
  57. }
  58. }
  59. /**
  60. * @apiVersion 1.0.0
  61. * @apiDescription 刷新token
  62. * @api {get} RefreshToken 刷新token
  63. * @apiParam {String} [token] token
  64. * @apiHeader {String} [Authorization] token 两个token任选其一
  65. * @apiGroup Login
  66. * @apiName RefreshToken
  67. * @apiSuccess {int} code 状态码
  68. * @apiSuccess {String} msg 信息
  69. * @apiSuccess {object} data 结果集
  70. * @apiSuccess {String} data.token token
  71. * @apiSuccess {Int} data.time 过期时间
  72. * @apiSuccessExample {json} Success-Response:
  73. * HTTP/1.1 200 OK
  74. * {
  75. * code: 0,
  76. * msg: "",
  77. * data: {
  78. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  79. * time:123455
  80. * }
  81. * }
  82. */
  83. public function refreshToken()
  84. {
  85. try {
  86. $old_token = JWTAuth::getToken();
  87. $token = JWTAuth::refresh($old_token);
  88. $time = time() + SysConsts::ONE_HOUR_SECONDS * 2;
  89. return response()->success(compact('token', 'time'));
  90. } catch (Exception $e) {
  91. return response()->error('QAPP_NOT_LOGIN');
  92. }
  93. }
  94. }