setPassword($password); $this->setEncrypt($encrypt); } /** * 创建对象 * @param string $password * @param string $encrypt * @return PassServer */ static function creatServer($password = '', $encrypt = '') { return new PassServer($password, $encrypt); } /** * @return string */ public function getPassword(): string { return $this->password; } /** * @param string $password */ public function setPassword($password = ''): void { if (!empty($password)) $this->password = $password; } /** * @return string */ public function getEncrypt(): string { return $this->encrypt; } /** * @param string $encrypt */ public function setEncrypt($encrypt = ''): void { if (!empty($encrypt)) $this->encrypt = $encrypt; } private $encrypt = ''; /** * @return string */ public function getErrorMsg(): string { return $this->errorMsg; } /** * 加密字符串 * @param $length * @return null|string */ public function getRandChar($length = 6) { $str = null; $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; $max = strlen($strPol) - 1; for ($i = 0; $i < $length; $i++) { $str .= $strPol[rand(0, $max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数 } return $str; } /** * 创建会员密码 * @return array|false */ function creatPassword() { if (empty($this->password)) { $this->errorMsg = "密码不能为空"; return false; } if (empty($this->encrypt)) $this->encrypt = $this->getRandChar(); $password = $this->memberPassword(); return ['password' => $password, 'encrypt' => $this->encrypt]; } /** * 验证密码 * @param $member_pass * @return bool */ public function verifyPass($member_pass) { $str = $this->memberPassword(); return $member_pass == $str; } /** * 密码加密 * @return string */ private function memberPassword() { $str = md5($this->password) . md5($this->encrypt); return md5($str); } /** * 获取推荐码 * @return int|string */ public function getInviteCode() { return InviteCodeServer::creatServer()->getInviteCode(); } /** * 生成会员登录token * @param $m_id * @return string */ public function getMemberToken($m_id) { $token = md5($m_id . 'token' . time()); return $token; } public function setSecretKey($private_key, $key_num = 0) { $key_num = $key_num % 20; if ($key_num == 0) $key_num = 15; $private_one = substr($private_key, 0, $key_num); $private_two = substr($private_key, $key_num, 5); $private_three = substr($private_key, $key_num + 5); $new_private = $private_three . $private_one . $private_two; return $new_private; } /** * @param $private_key * @param int $key_num * @return string */ public function getSecretKey($private_key, $key_num = 0) { $key_num = $key_num % 20; if ($key_num == 0) $key_num = 15; $private_length = strlen($private_key); $three_length = $private_length - $key_num - 5; $private_three = substr($private_key, 0, $three_length); $private_two = substr($private_key, -5); $private_one = substr($private_key, $three_length, $key_num); $new_private = $private_one . $private_two . $private_three; return $new_private; } }