//就在官方文档中修改了akid和aksecret, 其它未做改动,是不是还有修改其它信息?
function ali_rec_auth(){
$akId = "nGtfqgMd5k1j*****";
$akSecret = "dDxObDYXfWkpHiODF31eszsj******";
//更新api信息
$url = "https://shujuapi.aliyun.com/org_code/service_code/api_name?param1=xxx¶m2=xxx";
$body = array('requests' => array("asr", "ds"));
$options = array(
'http' => array(
'header' => array(
'accept'=> "application/json",
'content-type'=> "application/json",
'date'=> gmdate("D, d M Y H:i:s \G\M\T"),
'authorization' => ''
),
'method' => "GET", //可以是 GET, POST, DELETE, PUT
'content' => json_encode($body)
)
);
$http = $options['http'];
$header = $http['header'];
$urlObj = parse_url($url);
if(empty($urlObj["query"]))
$path = $urlObj["path"];
else
$path = $urlObj["path"]."?".$urlObj["query"];
$body = $http['content'];
if(empty($body))
$bodymd5 = $body;
else
$bodymd5 = base64_encode(md5($body,true));
$stringToSign = $http['method']."\n".$header['accept']."\n".$bodymd5."\n".$header['content-type']."\n".$header['date']."\n".$path;
$signature = base64_encode(
hash_hmac(
"sha1",
$stringToSign,
$akSecret, true));
$authHeader = "Dataplus "."$akId".":"."$signature";
$options['http']['header']['authorization'] = $authHeader;
$options['http']['header'] = implode(
array_map(
function($key, $val){
return $key.":".$val."\r\n";
},
array_keys($options['http']['header']),
$options['http']['header']));
$context = stream_context_create($options);
$file = file_get_contents($url, false, $context );
echo($file);
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。