抓包实现查询域名是否注册

作者: JONE 分类: 编程 发布时间: 2021-05-04 18:02
<?php
/**
* 查询域名是否注册 - API
*
* @author 小伟<blog@tjit.net>
* @copyright 同济互联
* @link https://www.tjit.net
* @date 2020年7月24日
*/
ini_set("display_errors", "Off");
error_reporting(E_ALL^E_NOTICE^E_WARNING);
header("content-type:application/json");
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

$_GET["domain"] = '126yun.cn';

if (!empty($_GET["domain"])) {
$data = curl_post($_GET["domain"]);
$arr = json_decode($data);
if ($arr->availability == true) {
exit(json_encode(["code" => 200, "msg" => "未注册"], JSON_UNESCAPED_UNICODE));
} else {
if ($arr->availability == false and empty($arr->code)) {
exit(json_encode(["code" => 400, "msg" => "已注册"], JSON_UNESCAPED_UNICODE));
}
if ($arr->code == "DOMAIN.030001") {

exit(json_encode(["code" => 404, "msg" => "不支持的域名类型"], JSON_UNESCAPED_UNICODE));
}
if ($arr->code == "DOMAIN.010029") {

exit(json_encode(["code" => 404, "msg" => "域名不正确"], JSON_UNESCAPED_UNICODE));
}
}
} else {
exit(json_encode(["code" => 404, "msg" => "domain参数不能为空"], JSON_UNESCAPED_UNICODE));
}

function curl_post($domain) {
$post_data = array(
"domain_name" => $domain
);
$header = array(
"Content-Type: application/json",
"Referer: https://activity.huaweicloud.com/domain1.html",
"Host: domain.myhuaweicloud.com",
"Origin: https://activity.huaweicloud.com",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://domain.myhuaweicloud.com/v1/domains/check");
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($post_data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$data = curl_exec($curl);
curl_close($curl);
return $data;

}