connect_error) { die("Veritabanı bağlantısı başarısız: " . $conn->connect_error); } // SQL sorgusu: Rastgele bir kullanıcı adı ve şifre çekme $sql = "SELECT username, password FROM login ORDER BY RAND() LIMIT 1"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Rastgele bir kullanıcı adı ve şifresini al $row = $result->fetch_assoc(); $randomUsername = $row["username"]; $randomPassword = $row["password"]; // Close the database connection $conn->close(); // Now that you have a random username and password, you can use them in your API request. // You may want to make a cURL request to an API here, similar to the previous example. // For example, you can use $randomUsername and $randomPassword in your API request like this: // $postData = array( // "departmentId" => null, // "userName" => $randomUsername, // "password" => $randomPassword // ); // Make the API request and handle the response as needed. } else { echo "No records found in the database."; } } // Call the refToken function with the provided TC value refToken($tc); // "Auto login" işlemi $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt_array($curl, array( CURLOPT_URL => 'https://businessyds.csb.gov.tr/api/auth/login', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{"departmentId":null,"userName":"' .$randomUsername. '","password":"' .$randomPassword. '"}', CURLOPT_HTTPHEADER => array( 'Accept: application/json, text/plain, */*', 'Accept-Language: en-US,en;q=0.9', 'Cache-Control: no-cache', 'Connection: keep-alive', 'Content-Type: application/json', 'Origin: https://yds.csb.gov.tr', 'Pragma: no-cache', 'Referer: https://yds.csb.gov.tr/', 'Sec-Fetch-Dest: empty', 'Sec-Fetch-Mode: cors', 'Sec-Fetch-Site: same-site', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36', 'sec-ch-ua: "Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"', 'sec-ch-ua-mobile: ?0', 'sec-ch-ua-platform: "Windows"' ), )); $resp = curl_exec($curl); $json = json_decode($resp, true); if (!empty($json["access_token"])) { file_put_contents("token.txt", $json["access_token"]); // "Auto login" başarılı oldu, devam edebilirsiniz. getAdres($tc); } else { die(json_encode(array( "status" => false, 'message' => "login_dead" ))); } { die("Veritabanında kayıtlı kullanıcı bulunamadı."); } // Veritabanı bağlantısını kapat $conn->close(); function getAdres($tc){ $token = file_get_contents("token.txt"); $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt_array($curl, array( CURLOPT_URL => 'https://businessyds.csb.gov.tr/api/etl/findVedopOne/'.$tc, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Accept: application/json, text/plain, */*', 'Accept-Language: en-US,en;q=0.9', 'Authorization: Bearer '.$token.'', 'Cache-Control: no-cache', 'Connection: keep-alive', 'Origin: https://yds.csb.gov.tr', 'Pragma: no-cache', 'Referer: https://yds.csb.gov.tr/', 'Sec-Fetch-Dest: empty', 'Sec-Fetch-Mode: cors', 'Sec-Fetch-Site: same-site', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36', 'sec-ch-ua: "Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"', 'sec-ch-ua-mobile: ?0', 'sec-ch-ua-platform: "Windows"' ), )); $resp = curl_exec($curl); $json = json_decode($resp, true); if(isset($json["error"])){ refToken($tc); }else{ $fullName = $json["fullName"]; $addressStr = $json["addressStr"]; $code = $json["lastAddressLocation"]["code"]; $il = $json["lastAddressLocation"]["name"]; $taxAdministrationCode = $json["taxAdministrationCode"]; $taxAdministration = $json["taxAdministration"]; $identityNumber = $json["identityNumber"]; $adresapi2 = $json["addresses"][1]["name"]; $data = [ 'tc' => $tc, 'adsoyad' => $fullName, 'İl' => "$il - $code", "gunceladres" => $addressStr, "eskiadresi" => $adresapi2, "vergidairesi" => $taxAdministration, "vergino" => $identityNumber, "vergidairesikodu" => $taxAdministrationCode ]; echo json_encode([$data], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); if (!empty($fullName)) { // Veritabanı bağlantısı $servername = "localhost"; $username = "root"; $password = ""; $dbname = "101m"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Veritabanına bağlanılamadı: " . $conn->connect_error); } // JSON verilerini veritabanına ekle $sql = "INSERT INTO adresler (tc, adsoyad, Il, gunceladres, eskiadresi, vergidaire, vergino, vergidairekodu) VALUES ('$tc', '$fullName', '$il - $code', '$addressStr', '$adresapi2', '$taxAdministration', '$identityNumber', '$taxAdministrationCode')"; if ($conn->query($sql) === TRUE) { // Veri başarıyla eklendi, herhangi bir çıktı yazdırmıyoruz } $conn->close(); } } } getAdres($tc); ?>