UsersController.php 3.2 KB

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