UsersController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * @apiParam {String} sign 签名(见微信支付签名https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=4_3)
  21. * @apiGroup Login
  22. * @apiName index
  23. * @apiSuccess {int} code 状态码
  24. * @apiSuccess {String} msg 信息
  25. * @apiSuccess {object} data 结果集
  26. * @apiSuccess {String} data.uid 用户uid
  27. * @apiSuccess {String} data.token token
  28. * @apiSuccess {Int} data.time 过期时间
  29. * @apiSuccessExample {json} Success-Response:
  30. * HTTP/1.1 200 OK
  31. * {
  32. * code: 0,
  33. * msg: "",
  34. * data: {
  35. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  36. * time:123455,
  37. * uid:1
  38. * }
  39. * }
  40. */
  41. public function index(Request $request)
  42. {
  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. if ($device_no) {
  47. $data = QappUserService::loginStatic(compact('send_order_id', 'device_no', 'device_info'));
  48. return response()->success($data);
  49. } else {
  50. return response()->error('PARAM_ERROR');
  51. }
  52. }
  53. /**
  54. * @apiVersion 1.0.0
  55. * @apiDescription 刷新token
  56. * @api {get} refreshToken 刷新token
  57. * @apiParam {String} [token] token
  58. * @apiHeader {String} [Authorization] token 两个token任选其一
  59. * @apiGroup Login
  60. * @apiName RefreshToken
  61. * @apiSuccess {int} code 状态码
  62. * @apiSuccess {String} msg 信息
  63. * @apiSuccess {object} data 结果集
  64. * @apiSuccess {String} data.token token
  65. * @apiSuccess {Int} data.time 过期时间
  66. * @apiSuccessExample {json} Success-Response:
  67. * HTTP/1.1 200 OK
  68. * {
  69. * code: 0,
  70. * msg: "",
  71. * data: {
  72. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  73. * time:123455
  74. * }
  75. * }
  76. */
  77. public function refreshToken()
  78. {
  79. try {
  80. $old_token = JWTAuth::getToken();
  81. $token = JWTAuth::refresh($old_token);
  82. $time = time() + SysConsts::ONE_HOUR_SECONDS * 2;
  83. return response()->success(compact('token', 'time'));
  84. } catch (Exception $e) {
  85. return response()->error('QAPP_NOT_LOGIN');
  86. }
  87. }
  88. }