脚本宝典收集整理的这篇文章主要介绍了SAE实时日志接口SDK用法示例,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了SAE实时日志接口SDK用法。分享给大家供大家参考,具体如下:
新浪SAE是新浪研发中心开发的国内首个公有云平台,从2009年开始到现在也是也来越成熟,开放了很多接口以及服务供开发者使用。这次为了方便开发者调试分析,SAE新增实时日志查询接口。今后您可以通过API对日志信息进行筛选,并下载所需的实时日志。但是新浪SAE官方只给出的Python的实现,这里给出PHP版本的接口调用SDK
accessKey = $key; $this->secretKey = $sec; $this->timestamp = time(); } /** * 重载get方法 */ public function __call($name,$arg){ $ret = array(); if (is_array($arg[0])) { $len = count($arg); for ($i=0; $i < $len;="" $i++)="" {="" $ret[$i]="$arg[$i]['fop']" $this-="">$name($arg[$i]['service'],$arg[$i]['date'],$arg[$i]['ident'],$arg[$i]['fop']):$this->$name($arg[$i]['service'],$arg[$i]['ident']); } }else{ $ret = $arg[3] ? $this->$name($arg[0],$arg[1],$arg[2],$arg[3]) : $this->get($arg[0],$arg[2]); } return $ret; } /** * 获取日志 * @param string 需要的日志 * @param string 时间 * @param string 日志类型 * @param string 过滤符 * @return array */ PRivate function getLOG($service,$date,$ident,$fop=null){ if ($fop) { $uri = '/log/'.$service.'/'.$date.'/'.$_SERVER['HTTP_APpvERSION'].'-'.$ident.'.log?'.$fop; }else{ $uri = '/log/'.$service.'/'.$date.'/'.$_SERVER['HTTP_APPVERSION'].'-'.$ident.'.log'; } $ret = explode(PHP_EOL,$this->get($uri)); array_splice($ret,7); array_pop($ret); return $ret; } private function get($uri){ $host = 'http://g.SAE.sina.COM.cn'.$uri; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$host); curl_setopt($ch,CURLOPT_RETURNtransfer,1); curl_setopt($ch,CURLOPT_HTTPHEADER,$this->SAEHeader($uri)); curl_setopt($ch,CURLOPT_HEADER,1); $ret = curl_exec($ch); curl_close($ch); return $ret; } /** * SAE请求头 * @return array */ private function SAEHeader($uri){ return array( 'Host: g.SAE.sina.com.cn','Accept: text/plain','x-SAE-accesskey: '.$this->accessKey,'x-SAE-timestamp: '.$this->timestamp,'Authorization: '. $this->getAuthorization($uri) ); } /** * 获取gAuthorization */ private function getAuthorization($uri){ $header = array( 'x-SAE-timestamp' => $this->timestamp,'x-SAE-accesskey' => strtolower($this->accessKey) ); ksort($header); $SAE_header = array('GET',$uri); foreach ($header as $key => $value) { $SAE_header[count($SAE_header)] = $key.':'.$value; } $ret = implode(PHP_EOL,$SAE_header); $auth = 'SAEV1_HMAC_SHA256 '.base64_encode(hash_hmac('sha256',$ret,$this->secretKey,true)); return $auth; } }
以上是脚本宝典为你收集整理的SAE实时日志接口SDK用法示例全部内容,希望文章能够帮你解决SAE实时日志接口SDK用法示例所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。