UsersController.php 4.4 KB

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