12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- if (!function_exists('get_client_code_version')) {
- /**
- * 读取客户端代码版本号,用于客户端自动加载新提交的代码
- * @return string
- */
- function get_client_code_version()
- {
- // 前端版本号文件路径
- $versionFile = public_path('version.md');
- // 文件存在,且有读权限
- if (file_exists($versionFile) && is_readable($versionFile)) {
- $version = @file_get_contents($versionFile);
- if ($version) {
- return trim($version);
- }
- }
- return false;
- }
- }
- if (!function_exists('check_signature')) {
- /**
- * 校验用户签名
- * @return string
- */
- function check_signature($params, $token)
- {
- // 按数组键名 正序排序
- ksort($params);
- $tem = array();
- foreach ($params as $k => $v) {
- if ($k !== 'sign') {
- $tem[] = "$k=$v";
- }
- }
- $sk = implode('&', $tem);
- return (md5($sk) == $token);
- }
- }
- if (!function_exists('get_random')) {
- /**
- * 生成随机字符串
- * @return string
- */
- function get_random($length = 6, $type = 'string', $convert = 0)
- {
- $config = array(
- 'number' => '1234567890',
- 'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
- 'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
- 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
- );
- if (!isset($config[$type]))
- $type = 'string';
- $string = $config[$type];
- $code = '';
- $strlen = strlen($string) - 1;
- for ($i = 0; $i < $length; $i++) {
- $code .= $string[mt_rand(0, $strlen)];
- }
- if (!empty($convert)) {
- $code = ($convert > 0) ? strtoupper($code) : strtolower($code);
- }
- return $code;
- }
- }
|