您好
首先,我要道歉你有一点错误在测试文件中,请使用此:
PHP Code:
<?php
require_once('./global.php');
function get_token(){
global $vbulletin;
$obj_connection = curl_init();
$arr_query_bits = array (
'grant_type' => 'client_credentials',
'scope' => 'http://api.microsofttranslator.com',
'client_id' => $vbulletin->options['vbenterprisetranslator_Microsoft_key'],
'client_secret' => $vbulletin->options['vbenterprisetranslator_Microsoft_secret']
);
$str_query = http_build_query($arr_query_bits);
curl_setopt($obj_connection, CURLOPT_URL, 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13');
curl_setopt($obj_connection, CURLOPT_HEADER, 0);
curl_setopt($obj_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($obj_connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($obj_connection, CURLOPT_POSTFIELDS, $str_query);
curl_setopt($obj_connection, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($obj_connection, CURLOPT_POST, TRUE);
print_r('Full token: </br>'.curl_exec($obj_connection).'</br></br>');
$token = json_decode (curl_exec($obj_connection));
curl_close($obj_connection);
return 'Authorization: Bearer '.$token->{'access_token'};
}
echo 'Starting test for Microsft Translation API by Azure<br/><br/>';
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?&from=pl&to=en&text=Witaj!');
curl_setopt($connection, CURLOPT_HEADER, 0);
curl_setopt($connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($connection, CURLOPT_HTTPHEADER, array(get_token()));
$str_response = curl_exec($connection);
$time = microtime(true) * 1000;
$result = curl_exec($connection);
$time = microtime(true) * 1000 - $time;
echo 'Test result: '.$result."<br/>\n";
echo 'Test error: '.curl_error($connection)."<br/>\n";
curl_close($connection);
echo 'Connection time (ms): '.$time;
?>
请运行此测试并告诉我结果