message($msg)->response($data); } } // 密码加盐 if (!function_exists('password_with_salt')) { function password_with_salt($password, $salt) { return md5(hash('sha256', $password . $salt)); } } // 生成随机字符串 if (!function_exists('random_str')) { /** * 生成随机字符串 * @param $length integer 生成的长度 * @param $type string 要生成的字符串类型(number, string, all) * @param $convert integer 大小写转换0为小写1为大写 * @return string */ function random_str($length, $type = "string", $convert = "0") { $conf = [ 'number' => '0123456789', 'string' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=' ]; $string = $conf[$type]; if (!$string) { $string = $conf['string']; } $strlen = strlen($string) - 1; $char = ''; for ($i = 0; $i < $length; $i++) { $char .= $string[mt_rand(0, $strlen)]; } if ($convert > 0) { $res = strtoupper($char); } elseif ($convert == 0) { $res = $char; } elseif ($convert < 0) { $res = strtolower($char); } return $res; } }