You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace api\logic;
use common\models\User; use yii\base\Exception; use Yii; use yii\web\BadRequestHttpException; use yii\web\NotFoundHttpException; use yii\web\ServerErrorHttpException;
class Login { const EXPIRE_TIME = 7 * 60 * 60 * 24;
/** * @return string * @throws Exception * @throws NotFoundHttpException * @throws ServerErrorHttpException */ public static function wxLogin() { $user = self::getWxUser(); Yii::$app->user->login($user, static::EXPIRE_TIME); $user->expire_at = time() + static::EXPIRE_TIME; $user->access_token = Yii::$app->security->generateRandomString(); if (!$user->save()) { throw new ServerErrorHttpException('更新登录信息失败'); } return $user->access_token; }
/** * @return array|User|null * @throws BadRequestHttpException * @throws NotFoundHttpException */ protected static function getWxUser() { $openid = Yii::$app->request->getBodyParam('openid'); if (!$openid) { throw new BadRequestHttpException('缺少参数openid'); } $user = User::find() ->where(['status' => User::STATUS_ACTIVE]) ->andWhere(['wx_openid' => $openid]) ->one(); if (!$user) { throw new NotFoundHttpException('用户未找到'); } return $user; }
public function miniProgramLogin() {
}
protected function getMiniUser() {
}
}
|