UsersController.php 5.0 KB

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