This document is generated by Gname.com.
$params = array (
'appid' => 'APPID',
'gntime' => 1234567890,
'ym' => 'gname.com',
'url' => 'https://www.gname.com'
);$stringA = "appid=APPID&gntime=1234567890&value=https%3A%2F%2Fwww.example.com&ym=example.com";$appkey = "APPKEY" //注:appkey
$stringB = "appid=APPID&gntime=1234567890&value=https%3A%2F%2Fwww.example.com&ym=example.comAPPKEY";
//注:MD5签名方式 并转成大写
$gntoken = strtoupper(md5($stringB)); //B48D34C9A15A3F33ED61396E5BD8F1F8 //Curl Post
function getHttpResponsePOST($url,$para) {
$curl = curl_init($url);
//SSL
if(substr($url, 0, 8)=== 'https://'){
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_HEADER, 0 );
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($para));
$responseText = curl_exec($curl);
curl_close($curl);
return $responseText;
}
//All elements of the array are concatenated into strings with "&" characters according to the mode of "parameter=parameter value", and the strings are urlencoded
function createLinkstringUrlencode($para,$char="&") {
$arg = "";
if($para){
ksort($para);
$params = [];
foreach($para as $key=>$val){
$params[]=$key."=".urlencode($val);
}
$arg = implode($char,$params);
}
return $arg;
}
//Sign
function md5Sign($prestr, $key) {
$signstr = $prestr . $key;
return strtoupper(md5($signstr));
}
//sign verify
function md5Verify($prestr, $sign, $key) {
$mysgin = md5Sign($prestr,$key);
if($mysgin == $sign) {
return true;
}
else {
return false;
}
}
//UTC+8 timestamp
function getTimeStamp($datetime){
$target_timezone = 'Asia/Singapore';
$system_timezone = date('e');
date_default_timezone_set($target_timezone);
$timestamp = strtotime($datetime);
date_default_timezone_set($system_timezone);
return $timestamp;
}
$appid="YOUR_APPID";
$appkey = "YOUR_APPSECRET";
$apiHost = "API HOST";
$endPoint="api/domain/dns";
$data['appid'] = $appid;
$data['gntime'] = time();
$data['ym']="example.com";
$data['dns']="ns1.gname-dns.com,ns2.gname-dns.com";
$gntoken = md5Sign(createLinkstringUrlencode($data),$appkey);
$data['gntoken'] = $gntoken;
$requestUrl = "https://{$apiHost}/{$endPoint}";
$response = getHttpResponsePOST($requestUrl,$data);
exit($response);