阿里云人脸检测定位

<?php
header("content-type:text/html;charset=utf-8");
$akId = '';
$akSecret = '';
//更新api信息
//官方API   https://help.aliyun.com/knowledge_detail/53399.html
$url = "https://dtplus-cn-shanghai.data.aliyuncs.com/face/detect";
$rq_data['type']=0;
$rq_data['image_url']='http://imgsrc.baidu.com/imgad/pic/item/38dbb6fd5266d01671f6f0dc9d2bd40734fa3552.jpg';
$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' => "POST", //可以是 GET, POST, DELETE, PUT
        'content' => json_encode($rq_data) //如有数据,请用json_encode()进行编码
    )
);
$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;
?>

 

posted @ 2018-07-26 15:16  zhuzhipeng  阅读(910)  评论(0编辑  收藏  举报