123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Http\Controllers\QuickApp\Oauth;
- use App\Consts\SysConsts;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use App\Modules\User\Services\QappUserService;
- use JWTAuth;
- class UsersController extends Controller
- {
- /**
- * @apiDefine Login 登录
- */
- /**
- * @apiVersion 1.0.0
- * @apiDescription 登录
- * @api {post} login 登录
- * @apiParam {String} js_code js_code
- * @apiParam {Int} distribution_channel_id distribution_channel_id
- * @apiParam {String} sign 签名
- * @apiGroup Login
- * @apiName index
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccess {String} data.uid 用户uid
- * @apiSuccess {String} data.token token
- * @apiSuccess {Int} data.time 过期时间
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data: {
- * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
- * time:123455,
- * uid:1
- * }
- * }
- */
- public function index(Request $request)
- {
- $params = $request->except('_url');
- $send_order_id = $request->input('send_order_id', 0);
- $device_no = $request->input('device_no', '');
- $device_info = $request->input('device_info', '');
- $sign = $request->input('sign', '');
- $key = 'a!A&AFRWT65Nb3NlklezUiqHyQAA@Z8M';
- if ($sign == _sign($params, $key)) {
- if ($device_no) {
- $data = QappUserService::loginStatic(compact('send_order_id', 'device_no', 'device_info'));
- return response()->success($data);
- } else {
- return response()->error('PARAM_ERROR');
- }
- } else {
- return response()->error('QAPP_SIGN_ERROR');
- }
- }
- /**
- * @apiVersion 1.0.0
- * @apiDescription 刷新token
- * @api {get} RefreshToken 刷新token
- * @apiParam {String} [token] token
- * @apiHeader {String} [Authorization] token 两个token任选其一
- * @apiGroup Login
- * @apiName RefreshToken
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccess {String} data.token token
- * @apiSuccess {Int} data.time 过期时间
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data: {
- * token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
- * time:123455
- * }
- * }
- */
- public function refreshToken()
- {
- try {
- $old_token = JWTAuth::getToken();
- $token = JWTAuth::refresh($old_token);
- $time = time() + SysConsts::ONE_HOUR_SECONDS * 2;
- return response()->success(compact('token', 'time'));
- } catch (Exception $e) {
- return response()->error('QAPP_NOT_LOGIN');
- }
- }
- }
|