diff --git a/plugins/Common.php b/plugins/Common.php index 44643de..0f7c30f 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -33,7 +33,8 @@ Class Common { try { $rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; - $userDir = "{$rootDir}{$cellphone}"; + $username = self::getMappedUsername($cellphone); + $userDir = "{$rootDir}{$username}"; mkdir("{$userDir}/data/", 0755, true); //分享视频目录 if (!is_dir("{$userDir}/data/")) { throw new Exception("创建用户数据目录失败,请检查目录 www/" . FSC::$app['config']['content_directory'] . " 权限配置,允许PHP写入"); @@ -46,6 +47,8 @@ Class Common { if (!empty($friends_code)) { file_put_contents("{$userDir}/README_friendscode.txt", $friends_code); } + + file_put_contents("{$userDir}/README_cellphone.txt", $cellphone); }catch(Exception $e) { throw new Exception("创建用户数据目录失败:" . $e->getMessage()); } @@ -53,12 +56,26 @@ Class Common { return true; } + //根据手机号码获取用户名ID + //规则:前6位对 97 求余数,再拼接后5位 + public static function getUserId($cellphone){ + $user_id = $cellphone; + + $prefix = substr($cellphone, 0, 6); + $prefix = str_pad( (int)$prefix % 97, 2, '0', STR_PAD_LEFT); + $suffix = substr($cellphone, -5); + + return "{$prefix}{$suffix}"; + } + //根据手机号码获取映射的用户名 public static function getMappedUsername($cellphone){ $username = $cellphone; if (!empty(FSC::$app['config']['tajia_user_map']) && !empty(FSC::$app['config']['tajia_user_map'][$username])) { $username = FSC::$app['config']['tajia_user_map'][$username]; + }else { + $username = self::getUserId($cellphone); } return $username;