阿里语音识别和OSS后台token获取

去github上下载阿里phpsdk

strtotime($zero2)){
$myfile = fopen("TokenTime.txt", "w") or die("Unable to open file!");
$txt =date("Y/m/d");
fwrite($myfile, $txt);
fclose($myfile);
$client = new DefaultAcsClient($clientProfile);
# 创建API请求并设置参数
$request = new CreateTokenRequest();
# 发起请求并处理返回
try {
    $response = $client->getAcsResponse($request);
    $txt1 =$response->Token;
       print_r($txt1);

$myfile1 = fopen("Token.txt", "w") or die("Unable to open file!");
fwrite($myfile1,json_encode($txt1, JSON_FORCE_OBJECT));
fclose($myfile1);
} catch(ServerException $e) {
    print "Error: " . $e->getErrorCode() . " Message: " . $e->getMessage() . "\n";
} catch(ClientException $e) {
    print "Error: " . $e->getErrorCode() . " Message: " . $e->getMessage() . "\n";
}

}else{
$myfile1 = fopen("Token.txt", "r") or die("Unable to open file!");
$token= fread($myfile1,filesize("Token.txt"));
fclose($myfile1); 
print_r(json_decode($token));
}

?>

阿里oss的使用需要先去后台创建角色和用户,使用的sdk和语音识别一样。

setRoleSessionName("client_name");
$request->setRoleArn($roleArn);
//$request->setPolicy($policy);
$request->setDurationSeconds(3600);
try {
    $response = $client->getAcsResponse($request);
    print_r($response);
} catch(ServerException $e) {
    print "Error: " . $e->getErrorCode() . " Message: " . $e->getMessage() . "\n";
} catch(ClientException $e) {
    print "Error: " . $e->getErrorCode() . " Message: " . $e->getMessage() . "\n";
}
?>

你可能感兴趣的:(阿里语音识别和OSS后台token获取)