UsersController.php 3.0 KB

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