services->apiAccessToken->disableByAccessToken(Yii::$app->user->identity->access_token)) { return ResultHelper::json(200, '退出成功'); } return ResultHelper::json(422, '退出失败'); } /** * 重置令牌 * * @param $refresh_token * @return array * @throws NotFoundHttpException * @throws \yii\base\Exception */ public function actionRefresh() { $model = new RefreshForm(); $model->attributes = Yii::$app->request->post(); if (!$model->validate()) { return ResultHelper::json(422, $this->getError($model)); } return Yii::$app->services->apiAccessToken->getAccessToken($model->getUser(), $model->group); } /** * 手机验证码登录Demo * * @return array|mixed * @throws \yii\base\Exception */ private function actionMobileLogin() { $model = new MobileLogin(); $model->attributes = Yii::$app->request->post(); if ($model->validate()) { return Yii::$app->services->apiAccessToken->getAccessToken($model->getUser(), $model->group); } // 返回数据验证失败 return ResultHelper::json(422, $this->getError($model)); } /** * 获取验证码 * * @return int|mixed * @throws \yii\web\UnprocessableEntityHttpException */ public function actionSmsCode() { $model = new SmsCodeForm(); $model->attributes = Yii::$app->request->post(); if (!$model->validate()) { return ResultHelper::json(422, $this->getError($model)); } return $model->send(); } /** * 注册 * * @return array|mixed * @throws \yii\base\Exception */ private function actionRegister() { $model = new RegisterForm(); $model->attributes = Yii::$app->request->post(); if (!$model->validate()) { return ResultHelper::json(422, $this->getError($model)); } $member = new Member(); $member->attributes = ArrayHelper::toArray($model); $member->merchant_id = !empty($this->getMerchantId()) ? $this->getMerchantId() : 0; $member->password_hash = Yii::$app->security->generatePasswordHash($model->password); if (!$member->save()) { return ResultHelper::json(422, $this->getError($member)); } return Yii::$app->services->apiAccessToken->getAccessToken($member, $model->group); } /** * 密码重置 * * @return array|mixed * @throws \yii\base\Exception */ private function actionUpPwd() { $model = new UpPwdForm(); $model->attributes = Yii::$app->request->post(); if (!$model->validate()) { return ResultHelper::json(422, $this->getError($model)); } $member = $model->getUser(); $member->password_hash = Yii::$app->security->generatePasswordHash($model->password); if (!$member->save()) { return ResultHelper::json(422, $this->getError($member)); } return Yii::$app->services->apiAccessToken->getAccessToken($member, $model->group); } /** * 权限验证 * * @param string $action 当前的方法 * @param null $model 当前的模型类 * @param array $params $_GET变量 * @throws \yii\web\BadRequestHttpException */ public function checkAccess($action, $model = null, $params = []) { // 方法名称 if (in_array($action, ['index', 'view', 'update', 'create', 'delete'])) { throw new \yii\web\BadRequestHttpException('权限不足'); } } }