' . $label . htmlspecialchars($output, ENT_QUOTES) . ''; } else { $output = $label . print_r($var, true); } } else { ob_start(); var_dump($var); $output = ob_get_clean(); if (!extension_loaded('xdebug')) { $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); $output = '
' . $label . htmlspecialchars($output, ENT_QUOTES) . '
'; } } if ($echo) { echo($output); return null; }else return $output; } /** * 数据过滤函数 * @param $string 要过滤的字符串 */ function safe_replace($string) { $string = trim($string); $string = str_replace('%20','',$string); $string = str_replace('%27','',$string); $string = str_replace('%2527','',$string); $string = str_replace('*','',$string); $string = str_replace('"','"',$string); $string = str_replace(' ','',$string); $string = str_replace(' ','',$string); $string = str_replace("'",'',$string); $string = str_replace('"','',$string); $string = str_replace(';','',$string); $string = str_replace('<','<',$string); $string = str_replace('>','>',$string); $string = str_replace("{",'',$string); $string = str_replace('}','',$string); $string = str_replace('\\','',$string); return $string; } function exsl_safe_replace($string) { $string = trim($string); $string = str_replace('%20','',$string); $string = str_replace('%27','',$string); $string = str_replace('%2527','',$string); $string = str_replace('*','',$string); $string = str_replace('"','"',$string); $string = str_replace("'",'',$string); $string = str_replace('"','',$string); $string = str_replace(';','',$string); $string = str_replace('<','<',$string); $string = str_replace('>','>',$string); $string = str_replace("{",'',$string); $string = str_replace('}','',$string); $string = str_replace('\\','',$string); $string = str_replace(' ','',$string); $string = str_replace(',','',$string); return $string; } /** * @param $string 需要加密解密的字符串 * @param $operation 判断是加密还是解密,E表示加密,D表示解密 * @param $key 密匙 */ function fasterEncrypt($string,$operation,$key='kzb_business_2015'){ $key = md5($key); $key_length = strlen($key); $string = $operation == 'D' ? base64_decode($string):substr(md5($string.$key),0,8).$string; $string_length = strlen($string); $rndkey = $box = array(); $result = ''; for($i=0;$i<=255;$i++){ $rndkey[$i] = ord($key[$i%$key_length]); $box[$i] = $i; } for($j=$i=0;$i<256;$i++){ $j = ($j+$box[$i]+$rndkey[$i])%256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for($a=$j=$i=0;$i<$string_length;$i++){ $a = ($a+1)%256; $j = ($j+$box[$a])%256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256])); } if($operation == 'D'){ if(substr($result,0,8)==substr(md5(substr($result,8).$key),0,8)){ return substr($result,8); }else{ return''; } }else{ return str_replace('=','',base64_encode($result)); } } // 获取唯一id function getUUID(){ $command = Yii::app()->businessDb->createCommand('select RIGHT(UUID_SHORT(), 20) as uuid'); $uninfo = $command->queryAll(); if (empty($uninfo[0]['uuid'])) { Yii::app()->jump->error('获取uuid失败!'); } return $uninfo[0]['uuid']; } function getUniqueId($schoolId){ $api=Yii::app()->params['getUniqueIdApi']['urlSingle']; $key=Yii::app()->params['getUniqueIdApi']['key']; $userName=$schoolId; $password=md5($userName.$key); $maxRequestCount=3; $uuid=0; for($i=1;$i<=$maxRequestCount;$i++){ $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD,$userName .':'. $password); curl_setopt( $ch, CURLOPT_URL, $api ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt( $ch, CURLOPT_HEADER, false ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $response = curl_exec( $ch ); curl_close( $ch ); $data=json_decode($response,true); if($data['errCode']==00 && !empty($data['data'])){ $uuid= $data['data']; break; } } if($uuid){ return $uuid; }else{ Yii::app()->jump->error('获取uuid失败!'); } } /** * 获取批量uuid * @param $school_id * @param int $uuid_num * @return mixed */ function getBatchUuid($school_id,$uuid_num = 1){ $uuid_arr = array(); $api=Yii::app()->params['getUniqueIdApi']['urlBatch']; $key=Yii::app()->params['getUniqueIdApi']['key']; $url = $api.$uuid_num; $params['method'] = 'get'; $params['username'] = $school_id; $params['password'] = md5($school_id . $key); $params['timeout'] = 2; //最多调3次 foreach (array(1, 2, 3) as $value) { $rs = commonCurl($url, $data = null, $params); if (isset($rs['errCode']) && $rs['errCode'] == '00') { $uuid_arr = $rs['data']; break; }else{ $msg = '获取uuid接口失败' . $value . '次,' . (isset($rs['errMsg']) ? $rs['errMsg'] : '无信息返回'); if ($value == 3) { Yii::app()->jump->error($msg); } } } if (count($uuid_arr) < $uuid_num) { $msg = '接口返回uuid数量不符合'; Yii::app()->jump->error($msg); } $returnData=array(); if($uuid_arr){ foreach ($uuid_arr as $id){ $returnData[(string)$id]=(string)$id; } } return $returnData; } // curl获取接口数据 function getCurlData($url,$data){ $data = json_encode($data); $header = array( 'Content-Type: application/json', 'Content-Length: '. strlen($data), ); $ch = curl_init();//初始化CURL句柄 // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC); //curl_setopt($ch, CURLOPT_USERPWD,'test:123456'); curl_setopt($ch, CURLOPT_USERPWD,Yii::app()->params['api_verify_username'] .':'. Yii::app()->params['api_verify_password']); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 15 ); //在发起连接前等待的时间,如果设置为0,则不等待 curl_setopt( $ch, CURLOPT_HEADER, false ); //设定是否输出页面内容 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );//设定是否显示头信息 curl_setopt( $ch, CURLOPT_POST, true ); //启用POST方式 //curl_setopt( $ch, CURLOPT_POSTFIELDS, $data); //请求参数 curl_setopt( $ch, CURLOPT_POSTFIELDS, $data ); //请求参数 //curl_setopt( $ch, CURLOPT_REFERER, "http://mall.xkhouse.com" ); //伪造来源地址 $response = curl_exec( $ch ); curl_close( $ch ); return trim($response); } /** * Curl方法 * @param $path * @param string $method * @param null $data * @param array $params (method,username,password) * @return mixed */ function commonCurl($url, $data = null,$params = array()){ $timeout = 5; if (isset($params['method']) && $params['method']) { $method = strtoupper($params['method']); }else{ $method = 'POST'; } $auth_username = isset($params['username']) ? trim($params['username']) : ''; $auth_password = isset($params['password']) ? trim($params['password']) : ''; if (isset($params['timeout']) && $params['timeout']) { $timeout = $params['timeout']; } $headers = array('Accept: application/json', 'Content-Type: application/json', ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//5秒 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);//5秒 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $auth_username .':'. $auth_password); switch($method) { case 'GET' : break; case 'POST' : if ($data) { $data = json_encode($data); } curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); break; case 'PUT' : curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); break; case 'DELETE' : curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; } if( !curl_errno($ch)){ $response = json_decode(curl_exec($ch), true); }else{ $response = false; } // $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 释放资源 curl_close($ch); return $response; } // curl获取接口数据 function getCurlDataFor($url,$data){ $header = array(); $ch = curl_init();//初始化CURL句柄 // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC); //curl_setopt($ch, CURLOPT_USERPWD,'test:123456'); curl_setopt($ch, CURLOPT_USERPWD,Yii::app()->params['api_verify_username'] .':'. Yii::app()->params['api_verify_password']); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 15 ); //在发起连接前等待的时间,如果设置为0,则不等待 curl_setopt( $ch, CURLOPT_HEADER, false ); //设定是否输出页面内容 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );//设定是否显示头信息 curl_setopt( $ch, CURLOPT_POST, true ); //启用POST方式 //curl_setopt( $ch, CURLOPT_POSTFIELDS, $data); //请求参数 curl_setopt( $ch, CURLOPT_POSTFIELDS, $data ); //请求参数 //curl_setopt( $ch, CURLOPT_REFERER, "http://mall.xkhouse.com" ); //伪造来源地址 $response = curl_exec( $ch ); curl_close( $ch ); return trim($response); } function apiPost($url, $data, $type = 0) { $ch = @curl_init(); $result = FALSE; if ($ch) { if (is_array($data) && isset($data['templetA'])) { $paramArray = array(); if (version_compare(PHP_VERSION, '5.4.9') >= 0) { //$cfile = curl_file_create($data['templetAFileName'],'application/vnd.openxmlformats-officedocument.wordprocessingml.document','wordname'); // try adding //$paramStr = 'paperId='.$data['paperId'].'&tpl_name="'.$data['paperName'].'"&tpl="'.$cfile->name.'"'; $cfile = curl_file_create($data['path_tpl'],'application/vnd.openxmlformats-officedocument.wordprocessingml.document',$data['tpl_name']); // try adding $paramArray['tpl'] = $cfile; $paramArray['paperId'] = $data['paperId']; $paramArray['tpl_name'] = $data['tpl_name']; } else { // $paramStr = 'paperId='.$data['paperId'].'&tpl_name="'.$data['paperName'].'"&tpl="@'.$data['templetAFileName'].'"'; //$data['file'] = array('callback_url'=>$word_api_url.'/wordapi/index/wid/'.$word_id,'file' => '@'.$postFilePath,'type'=>'batch'); $paramArray['tpl'] = '@'.$data['path_tpl']; $paramArray['paperId'] = $data['paperId']; $paramArray['tpl_name'] = $data['tpl_name']; } $paramStr = $paramArray; } else { $paramStr = $data; } //debug($paramStr);die; // Basic认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, Yii::app()->params['api_verify_username'] .':'. Yii::app()->params['api_verify_password']); // 不输出头部 $cookies = Yii::app()->request->getCookies(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('MySigInfo:userid='.Yii::app()->session['coachInfo']['coach_id'].'&time='.$cookies['loginTime']->value.'&sig='.$cookies['loginSig']->value.'&session='.$cookies['appLoginSessionId']->value)); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT,'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15'); //curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $paramStr); if( !curl_errno($ch)){ $result = curl_exec($ch); } // 释放资源 curl_close($ch); } return $result; } // 检查是否组长不是无法操作 function checkAuthority($type=1){ if ($type == 1) { if(Yii::app()->session['coachInfo']['leader'] != 1) { Yii::app()->jump->error('您无权限操作!'); } } else if ($type == 2) { if (isset(Yii::app()->session['session_semester_state'])){ //Yii::app()->jump->error('非当前使用学期不能操作!'); } } } function getToken(){ $token=''; if(Yii::app()->params['redis_on_off']){ $cache_accessToken= Yii::app()->cache->getValue('wytk_cache_accessToken_key'); $cache_accessTokenTime= Yii::app()->cache->getValue('wytk_cache_accessToken_time'); if(!empty($cache_accessToken) && !empty($cache_accessTokenTime) && (time()-$cache_accessTokenTimeparams['redis_expires'])){ $token=$cache_accessToken; }else{ $token_odj= new wechataccesstoken(Yii::app()->params['APPID'],Yii::app()->params['secret']); $token_array= $token_odj->get(); if($token_array){ Yii::app()->cache->setValue('wytk_cache_accessToken_key',$token_array['access_token'],7000); Yii::app()->cache->setValue('wytk_cache_accessToken_time',time()+$token_array['expires_in'],7000); $token=$token_array['access_token']; } } }else{ $token=0;//测试 } return $token; } function send_weixin($openId,$name, $url = null){ $inform_config = array( 'url'=> $url ? $url : Yii::app()->params['weixin_realm'], 'openId'=>$openId, 'name'=>$name ); $temapi= new wechattemplateapi(getToken(),$inform_config,1); $temapi->send();//通知不成功,未做记录 }