12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- // 应用公共文件
- //失败返回值
- if(!function_exists("error")){
- /**
- * @param $message
- * @param int $code
- * @param null $data
- * @return \think\response\Json
- */
- function error($message,$code=1004,$data=null){
- return json(["code"=>$code,"message"=>$message,"data"=>$data]);
- }
- }
- //成功返回值
- if(!function_exists('success')){
- /**
- * @param $message
- * @param int $code
- * @param null $data
- * @return \think\response\Json
- */
- function success($message,$data=null,$code=0){
- return json(['code'=>$code,'message'=>$message,'data'=>$data]);
- }
- }
- if (!function_exists('action_in_arr')) {
- /**
- * 检测一个访问的方式是否在白名单内 白名单不验token
- * @param array $arr
- * @return bool
- */
- function action_in_arr(array $arr = []): bool
- {
- $arr = is_array($arr) ? $arr : explode(',', $arr);
- if (!$arr) {
- return false;
- }
- $arr = array_map('strtolower', $arr);
- if (in_array(strtolower(request()->action()), $arr) || in_array('*', $arr)) {
- return true;
- }
- return false;
- }
- }
- if(!function_exists("startTime")){
- function startTime($time){
- return date('Y-m-d 00:00:00',strtotime($time));
- }
- }
- if(!function_exists('endTime')){
- function endTime($time){
- return date('Y-m-d 23:59:59',strtotime($time));
- }
- }
- if(!function_exists("makeToken")){
- function makeToken($strs,$salt="",$type="md5"){
- if($salt=="") $salt=time();
- $type = is_callable($type) ? $type : 'md5';
- $token = call_user_func($type,$strs.$salt);
- return $token;
- }
- };
- if(!function_exists('__')){
- function __($msg){
- return $msg;
- }
- };
|