$code,"message"=>$message]; echo json_encode($result,JSON_UNESCAPED_UNICODE); die(); } // 应用公共文件 function app_show($code=0,$message="",$data=[]){ $result = ['code'=>$code,"message"=>$message,"data"=>$data]; echo json_encode($result,JSON_UNESCAPED_UNICODE); die(); } function makeNo($str){ $date=date("mdHis"); $year = date("Y")-2000; $msec=randomkeys(4); return $str.$msec.$year.$date; } function randomkeys($length) { $returnStr=''; $pattern = '1234567890abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ for($i = 0; $i < $length; $i ++) { $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数 } return $returnStr; } //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies function curl_request($url,$post=''){ $header = headerSign($post); if(is_array($post)) $post=http_build_query($post); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_AUTOREFERER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); if($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); } curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); $data = curl_exec($curl); if (curl_errno($curl)) { return curl_error($curl); } curl_close($curl); return $data; } if(!function_exists("headerSign")){ function headerSign($post){ $config = Config::get("sign"); $appid=$config['appid']; $appkey=$config['appkey']; $headerArr=["appid"=>'123',"noce"=>randomkeys(16),"sign"=>'',"timestamp"=>time()]; $value =array_merge($post,$headerArr); $Sign= new \Sign($appid,$appkey); $headerArr['sign'] = $Sign->makeSign($value); $list=["Content-Type"=>"multipart/json;charset=utf-8"]; foreach ($headerArr as $key=>$value){ $list[]=$key.":".$value; } return $list; } } /** * @param $token * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function VerifyTokens($token){ $url =env("user.hosturl")."verifyToken"; $data=[ "token"=>$token ]; $response=curl_request($url,$data); return json_decode($response,true); } /** * @param $token * @param $condition * @return mixed */ function GetUserlist($token,$condition){ $url = env("user.hosturl")."userlist"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } /** * @param $token * @param $condition * @return mixed */ function GetAccountall($token, $condition){ $url = env("user.hosturl")."userall"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } function GetList($token,$condition){ $url = env("user.hosturl")."userlist"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } function GetUserInfo($condition){ $url = env("user.hosturl")."userinfo"; $response=curl_request($url,$condition); return json_decode($response,true); } /**手机号验证 * @param $mobile * @return bool */ function checkMobile($mobile){ if (!is_numeric($mobile)) { return false; } return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false; } /** * @param $token * @param $condition * @return mixed */ function resetinfo($token,$condition){ $url = env("user.hosturl")."usersave"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } /** * @param $token * @param $condition * @return mixed */ function resetstatus($token,$condition){ $host = Config::get("app"); $url = env("user.hosturl")."userstatus"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } function crea($data,$vio=0) { $db = Db::name("company_item")->where(['pid'=>$data['id'],'is_del'=>0])->select()->toArray(); if($vio==1){ $d = Db::name("depart_user")->where(['itemid'=>$data['id'],'is_del'=>0])->select()->toArray(); if(empty($d)){ $data['item']=[]; }else{ $data['item']=$d; } } if(empty($db)){ $data['child']=[]; return $data; } //var_dump($db); foreach ($db as $p){ $data['child'][]=crea($p,$vio); } return $data; } /** * @param $files * @return array */ function UploadImg($files) { $savename = []; $files = !is_array($files) ? [$files] : $files; try { //验证 validate(['imgFile' => ['fileSize' => 10240000, 'fileExt' => 'jpg,jpeg,png,bmp,gif', 'fileMime' => 'image/jpeg,image/png,image/gif']])->check(['imgFile' => $files]); foreach ($files as $file) { $url = Filesystem::disk('public')->putFile('topic/' . date("Ymd"), $file, function () use ($file) { return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . "_" . date('YmdHis')); }); $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName()); $temp = ["url" => $url, "name" => $name]; $savename[] = $temp; } return $savename; } catch (\think\exception\ValidateException $e) { return $e->getMessage(); } } function made($var,$data=[]){ $str = Db::name('model')->where(['id'=>$var])->find(); $vmn =[]; $vmn['id'] =$str['id']; $vmn['rename'] =$str['name']; array_unshift($data,$vmn); if($str['pid']==0){ return $data; }else{ return made($str['pid'],$data); } } /** * @param $token * @param $condition ['id'=>1] * @return mixed */ function GetInfoById($token,$condition){ $url = env("user.hosturl")."userinfo"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } function make($var,$data=[]){ $str = Db::name('company_item')->where(['id'=>$var])->find(); $vmn =[]; $vmn['id'] =$str['id']; $vmn['name'] =$str['name']; array_unshift($data,$vmn); // $var['id']=made(); if($str['pid']==0){ // krsort($data); return $data; }else{ return make($str['pid'],$data); } }