UsersController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.' device_no:'.$device_no);
  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. \Log::info('login_fail_PARAM_ERROR_package:'.$package.' $origin_package:'.$origin_package.' $send_order_id:'.$send_order_id.' device_no:'.$device_no);
  75. return response()->error('PARAM_ERROR');
  76. }
  77. } else {
  78. \Log::info('login_fail2_PARAM_ERROR_package:'.$package.' $origin_package:'.$origin_package.' $send_order_id:'.$send_order_id.' device_no:'.$device_no);
  79. return response()->error('PARAM_ERROR');
  80. }
  81. }
  82. /**
  83. * @apiVersion 1.0.0
  84. * @apiDescription 刷新token
  85. * @api {get} refreshToken 刷新token
  86. * @apiParam {String} [token] token
  87. * @apiHeader {String} [Authorization] token 两个token任选其一
  88. * @apiGroup Login
  89. * @apiName RefreshToken
  90. * @apiSuccess {int} code 状态码
  91. * @apiSuccess {String} msg 信息
  92. * @apiSuccess {object} data 结果集
  93. * @apiSuccess {String} data.token token
  94. * @apiSuccess {Int} data.time 过期时间
  95. * @apiSuccessExample {json} Success-Response:
  96. * HTTP/1.1 200 OK
  97. * {
  98. * code: 0,
  99. * msg: "",
  100. * data: {
  101. * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
  102. * time:123455
  103. * }
  104. * }
  105. */
  106. public function refreshToken()
  107. {
  108. try {
  109. $old_token = JWTAuth::getToken();
  110. $token = JWTAuth::refresh($old_token);
  111. $time = strtotime("+1 month");
  112. return response()->success(compact('token', 'time'));
  113. } catch (JWTException $e) {
  114. return response()->error('QAPP_NOT_LOGIN');
  115. }
  116. }
  117. }