UsersController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. //
  61. // //FIXME 浩瀚包传的是haohannew,但是打开要跟官方包名保持一致,所以这样特殊处理
  62. // if($package =='com.beidao.kuaiying.haohannew'){
  63. // $package = 'com.beidao.kuaiying.haohan';
  64. // }
  65. $package = get_real_package($package);
  66. //获取渠道id
  67. $channel_id = QappPackageService::getChannelId($package);
  68. if ($device_no && $channel_id > 0) {
  69. \Log::info('$package:'.$package.' $origin_package:'.$origin_package.' $send_order_id:'.$send_order_id);
  70. $data = (new QappUserService)->login(compact('package', 'send_order_id', 'device_no', 'androidid', 'mac', 'device_info', 'imei', 'codeVersion'));
  71. if($data){
  72. return response()->success($data);
  73. }else{
  74. return response()->error('PARAM_ERROR');
  75. }
  76. } else {
  77. \Log::info('$package:'.$package.' $send_order_id:'.$send_order_id);
  78. return response()->error('PARAM_ERROR');
  79. }
  80. }
  81. /**
  82. * @apiVersion 1.0.0
  83. * @apiDescription 刷新token
  84. * @api {get} refreshToken 刷新token
  85. * @apiParam {String} [token] token
  86. * @apiHeader {String} [Authorization] token 两个token任选其一
  87. * @apiGroup Login
  88. * @apiName RefreshToken
  89. * @apiSuccess {int} code 状态码
  90. * @apiSuccess {String} msg 信息
  91. * @apiSuccess {object} data 结果集
  92. * @apiSuccess {String} data.token token
  93. * @apiSuccess {Int} data.time 过期时间
  94. * @apiSuccessExample {json} Success-Response:
  95. * HTTP/1.1 200 OK
  96. * {
  97. * code: 0,
  98. * msg: "",
  99. * data: {
  100. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  101. * time:123455
  102. * }
  103. * }
  104. */
  105. public function refreshToken()
  106. {
  107. try {
  108. $old_token = JWTAuth::getToken();
  109. $token = JWTAuth::refresh($old_token);
  110. $time = strtotime("+1 month");
  111. return response()->success(compact('token', 'time'));
  112. } catch (JWTException $e) {
  113. return response()->error('QAPP_NOT_LOGIN');
  114. }
  115. }
  116. }