From 5701d9fdeb3bab8f076d014257471e3b2138cf8d Mon Sep 17 00:00:00 2001 From: mlevent Date: Sun, 18 Dec 2022 05:49:58 +0300 Subject: [PATCH] first commit --- .gitignore | 1 + README.md | 209 ++++++++++++++++++++++++ composer.json | 27 ++++ composer.lock | 20 +++ examples/index.php | 19 +++ src/Autoload.php | 33 ++++ src/IvdException.php | 62 ++++++++ src/IvdService.php | 370 +++++++++++++++++++++++++++++++++++++++++++ src/Request.php | 74 +++++++++ 9 files changed, 815 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 examples/index.php create mode 100644 src/Autoload.php create mode 100644 src/IvdException.php create mode 100644 src/IvdService.php create mode 100644 src/Request.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49ce3c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4de6e11 --- /dev/null +++ b/README.md @@ -0,0 +1,209 @@ +# 💸 İnteraktif Vergi Dairesi + +GİB İnteraktif Vergi Dairesi üzerinden şifresiz/şifreli işlemlere olanak tanır. + +- https://ivd.gib.gov.tr + +## Kurulum + +🛠️ Paketi composer ile projenize dahil edin; + +```bash +composer require mlevent/ivd +``` + +## Kullanım + +```php +use Mlevent\Ivd\IvdException; +use Mlevent\Ivd\IvdService; + +try { + + // Şifresiz Giriş + $ivd = (new IvdService)->login(); + + // Vergi Numarası Doğrulama + $result = $ivd->taxIdVerification( + trId : '11111111111', + province : '016', + taxOffice : '016252' + ); + + print_r($result); + + // Oturumu Sonlandır + $ivd->logout(); + +} catch(IvdException $e){ + + print_r($e->getMessage()); + print_r($e->getResponse()); + print_r($e->getRequest()); +} +``` + +### Gerçek Kullanıcı + +Kullanıcı bilgilerinizi `setCredentials` ya da `login` metoduyla tanımlayabilirsiniz. + +```php +use Mlevent\Ivd\IvdService; + +// Kullanıcı Bilgileriyle Giriş +$ivd = (new IvdService)->login('TC Kimlik No', 'Parola'); + +// Şirketlerdeki Ortaklık ve Yöneticilik Bilgileri +print_r($ivd->getPartnerships()); +``` + +> Not: Token değerini herhangi bir yerde kullanmanız gerekmeyecek. + +## Şifresiz İşlemler + +İnteraktif Vergi Dairesi üzerindeki bazı servisler şifresiz/giriş yapmadan kullanılabilir; + +#### Vergi Kimlik Numarası Sorgulama + +```php +$result = $ivd->taxIdInquiry( + name : 'Mert', // Zorunlu · Ad + lastName : 'Levent', // Zorunlu · Soyad + fatherName : 'Walter', // Zorunlu · Baba Adı + province : '016', // Zorunlu · İl + dateOfBirth : '19890511' // Zorunlu · Doğum Tarihi +); + +print_r($result); +``` + +#### Yabancılar İçin Vergi Kimlik Numarasından Sorgulama + +```php +$result = $ivd->taxIdInquiryForForeigners( + taxId : '1234567890' // Zorunlu · Vergi Numarası +); + +print_r($result); +``` + +#### Vergi Kimlik Numarası Doğrulama + +```php +$result = $ivd->taxIdVerification( + //taxId : '1234567890', // Opsiyonel · Vergi Numarası + trId : '11111111111', // Opsiyonel · TcKN + province : '016', // Zorunlu · İl + taxOffice : '016252' // Zorunlu · Vergi Dairesi +); + +print_r($result); +``` + +#### Diğer Metodlar + +```php +print_r($ivd->getTaxOffices()); // Vergi Daireleri +print_r($ivd->getTaxList()); // Vergiler +print_r($ivd->getCountries()); // Ülkeler +print_r($ivd->getProvinces()); // İller +print_r($ivd->getProvincesAndDistricts()); // İller ve İlçeler +``` + +## Şifreli İşlemler + +İnteraktif Vergi Dairesinde kayıtlı TcKN ve şifre bilgileriyle oturum açılarak kullanılabilecek metodlar; + +#### Sicil Kaydı + +```php +$ivd->getRegistry(); +``` + +#### Kimlik Bilgileri + +```php +$ivd->getIdInformation(); +``` + +#### Şirketlerdeki Ortaklık ve Yöneticilik Bilgileri + +```php +$ivd->getPartnerships(); +``` + +#### Borç Durumu + +```php +$ivd->getDebtStatus(); +``` + +#### KYK Borç Durumu + +```php +$ivd->getKYKDebtStatus(); +``` + +#### Banka Hesaplarına Uygulanan Elektronik Hacizler + +```php +$ivd->getGarnishmentsAppliedToBankAccounts(); +``` + +#### Araçlara Uygulanan Elektronik Hacizler + +```php +$ivd->getGarnishmentsAppliedToVehicles(); +``` + +#### Mevcut Araç Bilgileri + +```php +$ivd->getCurrentVehicles(); +``` + +#### Geçmiş Araç Bilgileri + +```php +$ivd->getPreviousVehicles(); +``` + +#### Vergi Ceza İhbarname Bilgileri + +```php +$ivd->getTaxPenaltyNoticeInformation(); +``` + +#### Sanal Pos Ödemeleri + +```php +$ivd->getVirtualPosPayments( + year: 2018 // Zorunlu · Yıl +); +``` + +#### E-Devlet Ödemeleri + +```php +$ivd->getEDevletPayments( + year: 2018 // Zorunlu · Yıl +); +``` + +#### Diğer Ödemeler + +```php +$ivd->getOtherPayments( + year: 2018 // Zorunlu · Yıl +); +``` + +#### Servis Mesajları + +```php +$ivd->getServiceMessages(); +``` + +## 📧İletişim + +İletişim için ghergedan@gmail.com adresine e-posta gönderin. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..151ce3a --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "mlevent/ivd", + "description": "İnternet Vergi Dairesi Yardımcı Aracı", + "keywords": [ + "gib", + "ivd", + "interaktif vergi dairesi", + "maliye", + "vergi" + ], + "autoload": { + "psr-4": { + "Mlevent\\Ivd\\": "src/" + } + }, + "authors": [ + { + "name": "mlevent", + "email": "ghergedan@gmail.com" + } + ], + "require": { + "php": "^8.0" + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..229b9a3 --- /dev/null +++ b/composer.lock @@ -0,0 +1,20 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "fa33f0ebf5560ded70cb0a89c65d29d9", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": { + "php": "^8.0" + }, + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/examples/index.php b/examples/index.php new file mode 100644 index 0000000..ea2b6db --- /dev/null +++ b/examples/index.php @@ -0,0 +1,19 @@ +login(); + + var_dump($ivd->getTaxList()); + + $ivd->logout(); + +} catch(IvdException $e){ + + print_r($e->getMessage()); + print_r($e->getResponse()); + print_r($e->getRequest()); +} \ No newline at end of file diff --git a/src/Autoload.php b/src/Autoload.php new file mode 100644 index 0000000..b45729e --- /dev/null +++ b/src/Autoload.php @@ -0,0 +1,33 @@ +response = $response; + $this->request = $request; + } + + /** + * getResponse + * + * @return mixed + */ + public function getResponse(): mixed + { + return $this->response; + } + + /** + * hasResponse + * + * @return boolean + */ + public function hasResponse(): bool + { + return $this->response !== null; + } + + /** + * getRequest + * + * @return mixed + */ + public function getRequest(): mixed + { + return $this->request; + } +} \ No newline at end of file diff --git a/src/IvdService.php b/src/IvdService.php new file mode 100644 index 0000000..d2cf540 --- /dev/null +++ b/src/IvdService.php @@ -0,0 +1,370 @@ +username = $username; + $this->password = $password; + return $this; + } + + /** + * getCredentials + */ + public function getCredentials(): array + { + return ['username' => $this->username, 'password' => $this->password]; + } + + /** + * setToken + */ + public function setToken(string $token = null): self + { + $this->token = $token; + return $this; + } + + /** + * getToken + */ + public function getToken(): ?string + { + return $this->token; + } + + /** + * guestLogin + */ + public function guestLogin(): self + { + $response = new Request(self::ApiAuth, [ + 'assoscmd' => 'cfsession', + 'rtype' => 'json', + 'fskey' => 'intvrg.fix.session', + 'fuserid' => 'INTVRG_FIX', + ]); + + $this->setToken($response->get('token')); + return $this; + } + + /** + * login + */ + public function login(string $username = null, string $password = null): self + { + if ($username && $password) { + $this->setCredentials($username, $password); + } + + if (!$this->username || !$this->password) { + return $this->guestLogin(); + } + + $response = new Request(self::ApiAuth, [ + 'assoscmd' => 'multilogin', + 'rtype' => 'json', + 'userid' => $this->username, + 'sifre' => $this->password, + 'parola' => 'maliye', + 'controlCaptcha' => 'false', + 'dk' => '', + 'imageID' => '', + ]); + + $this->setToken($response->get('token')); + return $this; + } + + /** + * logout + */ + public function logout(): bool + { + $response = new Request(self::ApiDispatch, + $this->setParams(['kullaniciBilgileriService_logout', 'PG_MAIN_DYNAMIC', 'cbf1b5447b6cc-44']) + ); + + $this->setCredentials(); + $this->setToken(); + + return $response->object('data')->logout == 1; + } + + /** + * Vergi Numarası Sorgulama + */ + public function taxIdInquiry(string $name, string $lastName, string $fatherName, string $province, string $dateOfBirth) + { + $response = new Request(self::ApiDispatch, + $this->setParams(['vergiNoIslemleri_vergiNoSorgulaSorgu', 'P_INTVRG_INTVD_VKN_SORGULA_SORGU', '64864a0c5ef08-14'], [ + 'isim' => $name, + 'soyisim' => $lastName, + 'babaAdi' => $fatherName, + 'il' => $province, + 'dogumYili' => $dateOfBirth, + ]) + ); + return $response->get('data'); + } + + /** + * Yabancılar İçin Vergi Kimlik Numarasından Sorgulama + */ + public function taxIdInquiryForForeigners(string $taxId) + { + $response = new Request(self::ApiDispatch, + $this->setParams(['vergiNoService_yabanciVKNSorguSonuc', 'P_INTVRG_INTVD_YABANCI_VKN_SORGULA', '64864a0c5ef08-16'], [ + 'eVknWithValidationTx' => $taxId, + ]) + ); + return $response->get('data'); + } + + /** + * Vergi Kimlik Numarası Doğrulama + */ + public function taxIdVerification(string $province, string $taxOffice, string $taxId = '', string $trId = '') + { + $response = new Request(self::ApiDispatch, + $this->setParams(['vergiNoIslemleri_vergiNumarasiSorgulama', 'R_INTVRG_INTVD_VERGINO_DOGRULAMA', '64864a0c5ef08-15'], [ + 'dogrulama' => [ + 'vkn1' => $taxId, + 'tckn1' => $trId, + 'iller' => $province, + 'vergidaireleri' => $taxOffice, + ] + ]) + ); + return $response->get('data'); + } + + /** + * Sicil Kaydı + */ + public function getRegistry() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['sicilIslemleri_evdoYsicilTckimliknoVknCevrimiMernisAdsoyad', 'RG_SICIL', '151218977cdcc-29']) + ); + return $response->get('data'); + } + + /** + * Kimlik Bilgileri + */ + public function getIdInformation() + { + if ($registry = $this->getRegistry()) { + return $registry['kimlikBilgileri']; + } + } + + /** + * Şirketlerdeki Ortaklık ve Yöneticilik Bilgileri + */ + public function getPartnerships() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['yoneticiOrtaklikIslemleri_sirketOrtaklikYoneticilikSorgula', 'P_MEVCUT_SIRKET_ORTAKLIK_YONETICILIK', '0861bf80b5f42-27'], [ + 'bilgi' => 1 + ]) + ); + return $response->get('data'); + } + + /** + * Borç Durumu + */ + public function getDebtStatus() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['tvdBorcIslemleri_borcGetirYeni', 'P_DASHBOARD', 'e95931c2f24ce-145']) + ); + return $response->get('data'); + } + + /** + * KYK Borç Durumu + */ + public function getKYKDebtStatus() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['kykBorcDurum_borcDurumGetir', 'PG_KYK_BORC_DURUMU', 'cbf1b5447b6cc-32']) + ); + return $response->get('data'); + } + + /** + * Banka Hesaplarına Uygulanan Elektronik Hacizler + */ + public function getGarnishmentsAppliedToBankAccounts() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['ehacizSorgulamaService_EhacizSorgulamaSonuc', 'P_INTVRG_INTVD_EHACIZ_ARAC_SRG', 'e95931c2f24ce-119'], [ + 'secim' => 2 + ]) + ); + return $response->get('data'); + } + + /** + * Araçlara Uygulanan Elektronik Hacizler + */ + public function getGarnishmentsAppliedToVehicles() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['ehacizSorgulamaService_EhacizSorgulamaSonuc', 'P_INTVRG_INTVD_EHACIZ_ARAC_SRG', 'e95931c2f24ce-146'], [ + 'secim' => 2 + ]) + ); + return $response->get('data'); + } + + /** + * Mevcut Araç Bilgileri + */ + public function getCurrentVehicles() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['aracBilgileriService_aracBilgileriGetir', 'P_MEVCUT_ARAC_BILGILERI', 'cbf1b5447b6cc-43'], [ + 'sorgulamaTip' => 1 + ]) + ); + return $response->get('data'); + } + + /** + * Geçmiş Araç Bilgileri + */ + public function getPreviousVehicles() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['aracBilgileriService_aracBilgileriGetir', 'P_GECMIS_ARAC_BILGILERI', '3be8a89c47b6c-31'], [ + 'sorgulamaTip' => 2 + ]) + ); + return $response->get('data'); + } + + /** + * Vergi Ceza İhbarname Bilgileri + */ + public function getTaxPenaltyNoticeInformation() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['cezaIhbarnameleriService_cezaIhbarnameleriGetir', 'P_CEZA_IHBARNAMELERI', '0861bf80b5f42-37']) + ); + return $response->get('data'); + } + + /** + * Sanal Pos Ödemeleri + */ + public function getVirtualPosPayments(int $year) + { + $response = new Request(self::ApiDispatch, + $this->setParams(['borcIslemleri_odemeSorgulaSpos', 'P_INTVRG_INTVD_ODEME_SORGULAMA', '0884d5a31205c-38'], [ + 'year' => $year + ]) + ); + return $response->get('data'); + } + + /** + * E-Devlet Ödemeleri + */ + public function getEDevletPayments(int $year) + { + $response = new Request(self::ApiDispatch, + $this->setParams(['tahsilatIslemleri_edevletOdemeleriSorgula', 'P_EDEVLET_ODEMELERIM', 'f3c28c5d3009f-35'], [ + 'tarih' => $year + ]) + ); + return $response->get('data'); + } + + /** + * Diğer Ödemeler + */ + public function getOtherPayments(int $year) + { + $response = new Request(self::ApiDispatch, + $this->setParams(['tahsilatIslemleri_mukellefeAitdemeleriSorgula', 'P_MUKELLEF_ODEME_SORGULAMA', '57a00a6bf5f92-38'], [ + 'yil' => $year + ]) + ); + return $response->get('data'); + } + + /** + * Servis Mesajları + */ + public function getServiceMessages() + { + $response = new Request(self::ApiDispatch, + $this->setParams(['kullaniciMesajlariService_kullaniciMesajlariGetir', 'PG_MAIN_DYNAMIC', 'e61d39920010c-61']) + ); + return $response->get('data'); + } + + /** + * __call + */ + public function __call($name, $arguments) + { + $keysAndCommands = [ + 'getTaxOffices' => 'RF_VERGI_DAIRELERI', + 'getTaxList' => 'RF_FILTRELI_VERGIKODLARI', + 'getCountries' => 'RF_EVDO_ULKELER', + 'getProvinces' => 'RF_INTVRG_INTVD_ILLER', + 'getProvincesAndDistricts' => 'RF_SICIL_DOGUMYERI_ILILCELER', + ]; + + if (array_key_exists($name, $keysAndCommands)) { + $response = new Request(self::ApiDispatch, + $this->setParams(['referenceDataService_getCacheableRfDataInfo', 'undefined', 'e61d39920010c-56'], [ + 'status' => [['rf' => $keysAndCommands[$name]]] + ]) + ); + return $response->get('data')[0]['values']; + } + } + + /** + * setParams + */ + public function setParams(array $command, array $payload = []): array + { + list($cmd, $pageName, $callId) = $command; + + return [ + 'callid' => $callId, + 'cmd' => $cmd, + 'pageName' => $pageName, + 'token' => $this->token, + 'jp' => json_encode($payload ?: (object) $payload), + ]; + } +} \ No newline at end of file diff --git a/src/Request.php b/src/Request.php new file mode 100644 index 0000000..7422f4c --- /dev/null +++ b/src/Request.php @@ -0,0 +1,74 @@ + 'application/json', + 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', + ]; + + /** + * request + * + * @param string $url + * @param array|null $parameters + * @param boolean $post + */ + public function __construct(string $url, ?array $parameters = null, bool $post = true) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLINFO_HEADER_OUT, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 20); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters)); + $response = json_decode(curl_exec($ch), true); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if (!$response || isset($response['error']) || !empty($response['data']['hata'])) { + throw new IvdException('İstek başarısız oldu.', $parameters, $response, $httpcode); + } + $this->response = $response; + } + + /** + * get + */ + public function get(?string $element = null) + { + return is_null($element) + ? $this->response + : $this->response[$element]; + } + + /** + * object + */ + public function object(?string $element = null) + { + $response = json_decode(json_encode($this->response, JSON_FORCE_OBJECT), false); + + return is_null($element) + ? $response + : $response->$element; + } +} \ No newline at end of file