开发者社区> 问答> 正文

调用推荐引擎API 没有返回结果,也没有提示错误信息(php)

//就在官方文档中修改了akid和aksecret, 其它未做改动,是不是还有修改其它信息?

function ali_rec_auth(){

    $akId = "nGtfqgMd5k1j*****";
    $akSecret = "dDxObDYXfWkpHiODF31eszsj******";
    //更新api信息
    $url = "https://shujuapi.aliyun.com/org_code/service_code/api_name?param1=xxx&param2=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);
}

展开
收起
楚天新媒 2017-01-17 16:30:44 3025 0
1 条回答
写回答
取消 提交回答
  • 需要导入数据,没有数据怎么输出结果

    2019-07-17 20:43:26
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
CUDA MATH API 立即下载
API PLAYBOOK 立即下载
传统企业的“+互联网”-API服务在京东方的实践 立即下载