objTable->getRow(['app_id' => $appId]); if (!$info || $info['state'] == self::STATE_CLOSE) { throw new Exception('app id not available', CODE_PARAM_ERROR); } if ($sign != self::doSign($appId, $info['app_secret'], $ts)) { throw new Exception('sign error!', CODE_SIGN_ERROR); } if (time() - self::VERIFY_TIMEOUT > $ts) { throw new Exception('request params timeout', CODE_PARAM_ERROR); } return true; } public static function doSign($appId, $appSecret, $ts) { return md5(sprintf('%s_%s_%s', $appId, $appSecret, $ts)); } private static function _accessTokenKey($appId, $accessToken) { return sprintf(self::REDIS_KEY_ACCESS_TOKEN, $appId, $accessToken); } public static function genAccessToken($appId, $userId) { $accessToken = uuid16(); if (!$accessToken) { return false; } $key = self::_accessTokenKey($appId, $accessToken); $objRedis = dwRedis::init(Eos::REDIS_SERV); $objRedis->setex($key, self::ACCESS_TOKEN_TTL, $userId); return $accessToken; } public static function checkAccessToken($appId, $userId, $accessToken) { $key = self::_accessTokenKey($appId, $accessToken); $objRedis = dwRedis::init(Eos::REDIS_SERV); $in = $objRedis->get($key); if (intval($in) === intval($userId)) { return true; } return false; } }