UsersController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Oauth;
  3. use App\Consts\SysConsts;
  4. use App\Modules\User\Models\QappPackage;
  5. use App\Modules\User\Services\QappPackageService;
  6. use Illuminate\Http\Request;
  7. use App\Http\Controllers\Controller;
  8. use App\Modules\User\Services\QappUserService;
  9. use JWTAuth;
  10. use Tymon\JWTAuth\Exceptions\JWTException;
  11. class UsersController extends Controller
  12. {
  13. /**
  14. * @apiDefine Login 登录
  15. */
  16. /**
  17. * @apiVersion 1.0.0
  18. * @apiDescription 登录
  19. * @api {post} login 登录
  20. * @apiParam {String} device_no 设备号
  21. * @apiParam {String} device_info 设备信息json字符串格式
  22. * @apiParam {Int} send_order_id send_order_id
  23. * @apiParam {Int} timestamp 时间戳10分钟过期
  24. * @apiParam {String} sign 签名(见微信支付签名https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=4_3)
  25. * @apiGroup Login
  26. * @apiName index
  27. * @apiSuccess {int} code 状态码
  28. * @apiSuccess {String} msg 信息
  29. * @apiSuccess {object} data 结果集
  30. * @apiSuccess {String} data.uid 用户uid
  31. * @apiSuccess {String} data.token token
  32. * @apiSuccess {Int} data.time 过期时间
  33. * @apiSuccessExample {json} Success-Response:
  34. * HTTP/1.1 200 OK
  35. * {
  36. * code: 0,
  37. * msg: "",
  38. * data: {
  39. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  40. * time:123455,
  41. * uid:1
  42. * }
  43. * }
  44. */
  45. public function index(Request $request)
  46. {
  47. $codeVersion = $request->header('x-codeversion', '');
  48. $package = $request->input('package', '');
  49. $send_order_id = $request->input('send_order_id', 0);
  50. $device_no = $request->input('device_no', '');
  51. $androidid = $request->input('androidid', '');
  52. $imei = $request->input('imei', '');
  53. $mac = $request->input('mac', '');
  54. $device_info = $request->input('device_info', '');
  55. $origin_package = $package;
  56. //FIXME 海天包传成浩瀚了,特殊处理下,这个名字就给海天用
  57. if($package =='com.beidao.kuaiying.haohan'){
  58. $package = 'com.beidao.kuaiying.haitian';
  59. }
  60. //获取渠道id
  61. $channel_id = QappPackageService::getChannelId($package);
  62. if ($device_no && $channel_id > 0) {
  63. \Log::info('$package:'.$package.' $origin_package:'.$origin_package.' $send_order_id:'.$send_order_id);
  64. $data = (new QappUserService)->login(compact('package', 'send_order_id', 'device_no', 'androidid', 'mac', 'device_info', 'imei', 'codeVersion'));
  65. if($data){
  66. return response()->success($data);
  67. }else{
  68. return response()->error('PARAM_ERROR');
  69. }
  70. } else {
  71. \Log::info('$package:'.$package.' $send_order_id:'.$send_order_id);
  72. return response()->error('PARAM_ERROR');
  73. }
  74. }
  75. /**
  76. * @apiVersion 1.0.0
  77. * @apiDescription 刷新token
  78. * @api {get} refreshToken 刷新token
  79. * @apiParam {String} [token] token
  80. * @apiHeader {String} [Authorization] token 两个token任选其一
  81. * @apiGroup Login
  82. * @apiName RefreshToken
  83. * @apiSuccess {int} code 状态码
  84. * @apiSuccess {String} msg 信息
  85. * @apiSuccess {object} data 结果集
  86. * @apiSuccess {String} data.token token
  87. * @apiSuccess {Int} data.time 过期时间
  88. * @apiSuccessExample {json} Success-Response:
  89. * HTTP/1.1 200 OK
  90. * {
  91. * code: 0,
  92. * msg: "",
  93. * data: {
  94. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  95. * time:123455
  96. * }
  97. * }
  98. */
  99. public function refreshToken()
  100. {
  101. try {
  102. $old_token = JWTAuth::getToken();
  103. $token = JWTAuth::refresh($old_token);
  104. $time = strtotime("+1 month");
  105. return response()->success(compact('token', 'time'));
  106. } catch (JWTException $e) {
  107. return response()->error('QAPP_NOT_LOGIN');
  108. }
  109. }
  110. }