public function generate() { if (!isset($_POST['dosubmit'])) { $condition['status'] = 1; $functionGroups = M('function_group')->where($condition)->order('sort asc, id asc')->select(); $this->assign('funcGroups', $functionGroups); $this->display(); } else { $func_groups = join(',', $_POST['func_group']); if (strlen($func_groups) <= 0) { $this->error('功能组不能为空'); } if (!isset($_POST['codeCount']) || empty($_POST['codeCount'])) { $this->error("邀请码总数不能为空"); } if (!isset($_POST['codeDuration']) || empty($_POST['codeDuration'])) { $this->error("有效期不能为空"); } $codeCount = $_POST['codeCount']; $codeDuration = $_POST['codeDuration']; $generator = new InviteCodeGenerator(); $ok = $generator->generate($codeCount, $codeDuration, 1, $func_groups, C('ADMIN_USER_ID')); if ($ok) { $this->success("成功生成 " . $codeCount . " 个邀请码", U('Admin/InviteCode/index')); } else { Log::record("Generate invitecode getDBError:" . $dbErr . " getError:" . $lastError, Log::ERR); $this->error('生成邀请码失败。请查看log!'); } } }
static function init() { $fp = fopen(CONF_PATH . 'public_key.pem', "r"); self::$inviteCodePubKey = fread($fp, 8192); fclose($fp); }