$v) { $k = str_replace(self::PREFIX, '', $k); if(!isset($config[$key]['request'][$k])) { Output::abert('api_param_exists', $k); } Input::set($k, $v); self::$log['add_request'][0][$k] = $v; } } else { //Output::abert('api_param_exists', 'request'); } } } /** * 得到数据结果 * * @return mixed */ static public function out($data) { if(self::$state == true) { if(!$data) { //Output::abert('api_param_exists', 'response'); } # 记录日志 暂时不做记录 if(Project::load('manage')) { self::$log['add_response'][0] = $data; //Load::get('manage/api_log-insert', $param); } $result['msg'] = 'success'; $result['status'] = 1; $result['data'] = $data; if(Input::get('maze_api_data') == 'yes') { print_r($result);die; } Output::result($result); } } /** * 得到解密结果 * * @return mixed */ static public function result($info) { $time = Input::get('time'); # 验证时间是否超时,默认为5分钟 if(time() - $time > self::TIME) { Output::abert('api_signature_exists'); } $nonce = Input::get('nonce'); $key = Input::get('signature'); $signature = self::signature($time, $nonce, $info); if(Input::get('signature') != $signature) { Output::abert('api_signature_exists'); } } /** * 得到签名及其数据 * * @return mixed */ static public function get($info) { $time = time(); $nonce = self::nonce(); $signature = self::signature($time, $nonce, $info); $info += array ( 'time' => $time, 'nonce' => $nonce, 'signature' => $signature, //'token' => self::token(), //'status' => 1, //'msg' => 'success', ); return $info; } /** * 获取signature * * @return mixed */ static public function signature($time, $nonce, $info = array()) { $info['token'] = self::token(); $info['time'] = $time; $info['nonce'] = $nonce; ksort($info); $signature_string = ''; foreach($info as $k => $v) { $signature_string .= $k . '=' . $v . '&'; } $signature_string = substr($signature_string, 0, -1); return sha1($signature_string); } /** * 获取token * * @return mixed */ static public function token() { self::$token = isset(Config::$global['base']['token']) ? Config::$global['base']['token'] : self::$token; return md5(self::$token); } /** * 获取nonce * * @return mixed */ static public function nonce() { return substr(md5(microtime()), rand(10, 15)); } }