问题补充:
header('Content-Type: text/html; charset=utf-8');
// header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token, X-Requested-With, Authorization');
$start = time() + microtime();
$req_params = array_merge($_GET, $_POST);
if(!array_key_exists('dn', $req_params)) {
die(json_encode(array(
'error' => true,
'result' => '缺少 dn'
)));
}
$enc = (isset($req_params['enc']) && !empty($req_params['enc'])) ? $req_params['enc'] : 'E';
$method = (isset($req_params['method']) && !empty($req_params['method'])) ? $req_params['method'] : 'queryDomainInfo';
$client = (isset($req_params['client']) && !empty($req_params['client'])) ? $req_params['client'] : 'agent15422';
$queryType = (isset($req_params['queryType']) && !empty($req_params['queryType']) ? $req_params['queryType'] : 'admType';
$password = (isset($req_params['password']) && !empty($req_params['password']) ? $req_params['password'] :'24265528';
$url = 'http://api.xinnet.com/domain/api.gb';
$data = array(
'enc' => $enc,
'method' => $method,
'queryType' => $queryType,
'client' => $client,
'charset' => 'utf-8',
'dn' => $req_params['dn'],
'checksum' => MD5('queryDomainInfo'.$client.$password.$dn.$queryType),
);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$error = false;
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
/*Handle error*/
// echo "error
\n";
$error = true;
}
// echo($result) . "
\n";
$end = time() + microtime();
// echo ($end - $start);
echo json_encode(array(
'error' => $error,
'result' => $result,
'time' => $end - $start
));
?>补充:哪位高人指点我一下啊