hSet('oralcavity_token', $array['id'], $encode_token); $redis->close(); return $encode_token; } catch (\Exception $e) { tojson('10000', $e->getMessage()); } } } if (!function_exists('has_special_str')) { function has_special_str($str) { //$前要加反斜杠 $specialChars = "~·`!!`@@&$##\$¥%^…&*()()—-_==×++[]{}*{}【】、|\\;:;:'\"“”‘’,./<>《》??~,。…"; //特殊符号数组 $specialArr = array(); $len = mb_strlen($specialChars, 'UTF-8'); for ($i = 0; $i < $len; $i++) { $specialArr[] = mb_substr($specialChars, $i, 1, 'UTF-8'); } //待比较字符串数组 $arr = array(); $len = mb_strlen($str, 'UTF-8'); for ($i = 0; $i < $len; $i++) { $arr[] = mb_substr($str, $i, 1, 'UTF-8'); } foreach ($arr as $v) { if (in_array($v, $specialArr)) { return true; } } return false; } } if (!function_exists('uuid')) { function uuid() { $uuid = sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); return $uuid; } } // 应用公共文件 if (!function_exists('tojson')) { function tojson($code = 200, $msg = '请求成功', $arr = null) { $array = [ 'code' => (int)$code, 'msg' => $msg, // 'data' => $arr, ]; if ($arr) { $array = array_merge($array, $arr); } return json($array, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } } //token,获取用户信息 if (!function_exists('getToken')) { function getToken($token) { try { $data = \app\common\model\Jwt::decode($token); $redis = new support\Redis(); $res = $redis->hGet('oralcavity_token', $data['id']); if ($res != $token) { return tojson(201, 'token不存在,请重试登录'); } if (!empty($data)) { return $data; } else { return tojson(201, 'token不存在'); } } catch (\Exception $e) { return tojson(201, 'token不存在'); } } } if (!function_exists('nosecure')) { function nosecure($method, $nosecure, $function, $param) { return \app\common\model\Secure::secure($method, $nosecure, $function, $param); } } if (!function_exists('host')) { function host()//??? { // $host = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT']; $host = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT']; return $host; } } //验证器以及验签 if (!function_exists('verifysign')) { function verifysign($param, $noSize, $request) { if (!isset($param['sign'])) { if (!nosign($noSize, $request)) { return tojson(10005, 'sign验签不存在'); } } //验证签名 $no = nosign($noSize, $request); if ($no) { if ($no == false) { unset($param['sign']); } } else { return checksign($param); } } } //验签 if (!function_exists('checksign')) { function checksign($array) { ksort($array); $string = ''; foreach ($array as $k => $v) { if ($k != 'sign' && $v !== '' && !is_array($v)) { $string .= $k . '=' . $v . '&'; } } $string = trim($string, '&'); if ($string == '') { $string = $string . 'key=' . config('apiconfig.key'); } else { $string = $string . '&key=' . config('apiconfig.key'); } $sign = md5($string); if ($sign != $array['sign']) { return tojson('10004', '验签不对'); } return $sign; } } //检查是否签名 if (!function_exists('nosign')) { function nosign($arr, $request) { $action = $request->action; $arr = is_array($arr) ? $arr : explode(',', $arr); if (!$arr) { return false; } $arr = array_map('strtolower', $arr); // 是否存在 if (in_array(strtolower($action), $arr) || in_array('*', $arr)) { return true; } // 没找到匹配 return false; } }