diff --git a/taskExecuter.php b/taskExecuter.php index 245de43..8be9ee7 100644 --- a/taskExecuter.php +++ b/taskExecuter.php @@ -4,10 +4,10 @@ include "read_write_xlsx.php"; include "emailSender.php"; -$maxExecutionTime = 300; +$maxExecutionTime = 62; $taskDir = 'tasks'; $downloadDir = 'download'; -$minTaskOldness = 30; +$minTaskOldness = 5; $latesEndTime = time() + $maxExecutionTime; $smtppassword = getenv("smtppassword"); @@ -21,13 +21,14 @@ function doRequest($data, $filename, $username, $password) $companyArray = json_decode($response, true); $companyData = array(); foreach ($companyArray as $company) { - $companyData[] = [$company['name'],$company['ehraid'],$company['uid'],$company['chid'],$company['legalSeat'],$company['registryOfCommerceId'],$company['legalForm']['name']['de'],$company['status'],$company['sogcDate'],$company['deletionDate']]; + $companyFullData = json_decode(sendAPICompanyInfoRequest($username, $password, $company['uid']), true)[0]; + $companyData[] = [$companyFullData['name'],$companyFullData['address']['street'], $companyFullData['address']['houseNumber'], $companyFullData['address']['swissZipCode'], $companyFullData['address']['city'],$companyFullData['uid'],$companyFullData['legalSeat'],$companyFullData['legalForm']['name']['de'],$companyFullData['status'],$companyFullData['sogcDate'],$companyFullData['deletionDate']]; } if (! file_exists($filename)) { // If File doesn't exist yet $file = fopen($filename, 'w'); if($file) { - fputcsv($file, ['name', 'ehraid', 'uid', 'chid', 'legalSeat', 'registryOfCommerceId', 'legalForm', 'status', 'sogcDate', 'deletionDate']); + fputcsv($file, ['name', 'street', 'houseNumber', 'swissZipCode', 'city', 'uid', 'legalSeat', 'legalForm', 'status', 'sogcDate', 'deletionDate']); } } else { // If file already exists diff --git a/zefixAPI.php b/zefixAPI.php index 1dabb4f..b06c22c 100644 --- a/zefixAPI.php +++ b/zefixAPI.php @@ -3,6 +3,37 @@ include 'env_vars.php'; $username = getenv("username"); $password = getenv("password"); +function sendAPICompanyInfoRequest(string $username, string $password, string $uid): string|bool { + +// API endpoint + $apiUrl = 'https://www.zefix.admin.ch/ZefixPublicREST/api/v1/company/uid/'.$uid; + +// Headers + $headers = array( + "accept: application/json", + "Content-Type: application/json" + ); + +// Initialize cURL session + $ch = curl_init(); +// Set cURL options + curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); + curl_setopt($ch, CURLOPT_URL, $apiUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, false); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification + +// Execute cURL session and get the response + $response = curl_exec($ch); +// Check for cURL errors + if (curl_errno($ch)) { + echo 'Curl error: ' . curl_error($ch); + } +// Close cURL session + curl_close($ch); + return $response; +} /** * @param string $