<?php
namespace BLS;
/* sendDocument Cevap Sınıfı */
class documentReturnType {
private $msg;
private $hash;
public function msg($veri=null) {
if($veri == null) return $this->msg;
else return $this->msg = $veri;
}
public function hash($veri=null) {
if($veri == null) return $this->hash;
else return $this->hash = $veri;
}
}
?>
<?php
namespace BLS;
/* Hata Sınıfı */
class EFaturaFault {
private $code;
private $msg;
public function code($veri=null) {
if($veri == null) return $this->code;
else return $this->code = $veri;
}
public function msg($veri=null) {
if($veri == null) return $this->msg;
else return $this->msg = $veri;
}
}
?>
<?php
namespace BLS;
/* getApplicationResponse Cevap Sınıfı */
class getAppRespResponseType {
private $applicationResponse;
public function applicationResponse($veri=null) {
if($veri == null) return $this->applicationResponse;
else return $this->applicationResponse = $veri;
}
}
?>
<?php
namespace BLS;
/* GUID İşlemleri */
class NTGEFaturaGUID{
public static $zarf_md5=null;
public static $yeni_dosya_adi = null;
public static $ozel_guid = null; /* Varsayılan Fatura No - 3HANELIEK-YIL-SIRANO toplam 16 hane. */
/* Guid Oluşturma */
Public static function uuid($id, $isim, $boyut=true)
{
$idSonuc = str_replace(array('-','{','}'), '', $id);
$sha1 = sha1($idSonuc . $isim);
$sha1Sonuc = sprintf('%08s-%04s-%04x-%04x-%12s',
substr($sha1, 0, 8),
substr($sha1, 8, 4),
(hexdec(substr($sha1, 12, 4)) & 0x0fff) | 0x5000,
(hexdec(substr($sha1, 16, 4)) & 0x3fff) | 0x8000,
substr($sha1, 20, 12)
);
return (($boyut == true) ? strtoupper($sha1Sonuc) : $sha1Sonuc);
}
/* Guid Oluşturma */
/* Özel Guid */
Public static function ozelGuid($fatura_no, $dosya_adi)
{
/* Zarf InstanceIdentifier oluşturuluyor */
self::$zarf_md5 = self::$ozel_guid = self::uuid($fatura_no.'-'.pathinfo($dosya_adi,PATHINFO_FILENAME), 'NTGEFaturaGUID'.time(), false);
/* Zarf InstanceIdentifier ile zip ve yeni xml dosyası adı oluşturuluyor */
self::$yeni_dosya_adi = self::$ozel_guid.'.'.pathinfo($dosya_adi,PATHINFO_EXTENSION);
}
/* Özel Guid */
}
/* GUID İşlemleri */
?>
<?php
namespace BLS;
/* Log Sınıfı */
class NTGEFaturaLog {
public static function log($gelen=array()) {
if(!isset($gelen[3])) $gelen[3] = true;
/* Dosya Adı : $gelen[0] - Dosya İçeriği : $gelen[1] - Dosya Sil : $gelen[2] */
if((file_exists($gelen[0])) AND ($gelen[2] == true)) unlink($gelen[0]);
if(!$dosya = fopen($gelen[0], 'a+')) die('Dosyayı Yazamadım !');
fwrite($dosya, (($gelen[3] == true) ? print_r($gelen[1], true) : $gelen[1]));
fclose($dosya);
}
}
?>
<?php
namespace BLS;
use DOMDocument;
use DOMXpath;
use BLS\NTGEFaturaGUID;
use BLS\NTGEFatura;
use BLS\NTGEFaturaSoapIstemci;
NTGEFatura::$java_dosyasi_ubl = "Java/NTG_UBLTR_Schematron.jar";
NTGEFatura::$sertifika_dosya = 'cert/[email protected]';
NTGEFatura::$sertifika_sifre = '633225';
NTGEFatura::$dosya_xsd = 'ubl/xml/PackageProxy_1_2.xsd';
NTGEFatura::$ubl_dosyasi = "ubl/schematron/UBL-TR_Main_Schematron.xml";
NTGEFatura::$zarf_turu = 'SYSTEMENVELOPE'; /* SYSTEMENVELOPE - SENDERENVELOPE - fatura ve iade / POSTBOXENVELOPE - yanıt / USERENVELOPE - kullanıcı */
NTGEFatura::$zarf_icerik_tur = 'APPLICATIONRESPONSE'; /* INVOICE - fatura ve iade / APPLICATIONRESPONSE - yanıt / PROCESSUSERACCOUNT - kullanıcı açma / CANCELUSERACCOUNT - kullanıcı silme */
NTGEFatura::$zarf_icerik_adet = '1';
NTGEFatura::$ZarfBilgileri['satici']['unvan'] = $a['tedarikci_unvan'];
NTGEFatura::$ZarfBilgileri['satici']['vkn_tckn'] = $a['tedarikci_vkn'];
if($a['test'] == 'false') NTGEFatura::$ZarfBilgileri['satici']['mail'] = $a['tedarikci_mail_pk'];
else NTGEFatura::$ZarfBilgileri['satici']['mail'] = $a['test_gonderici_mail'];
/* Sistem Yanıtı Sınıfı */
class NTGEFaturaSistemYaniti {
public static function SistemYaniti($gelen=array()) {
// extract($GLOBALS);
global $a;
if($a['test'] == 'true') NTGEFatura::$ZarfBilgileri['satici']['mail'] = (($gelen['mail'] == $a['test_posta_kutusu_mail']) ? $a['test_gonderici_mail'] : $a['test_posta_kutusu_mail']);
else NTGEFatura::$ZarfBilgileri['satici']['mail'] = (($gelen['tur'] == 'gelen_yanit') ? $a['tedarikci_mail_gb'] : $a['tedarikci_mail_pk']);
$gmt_bolge = $a['gmt_bolge'];
$IssueDate = gmdate('Y-m-d', (time()+$gmt_bolge));
$IssueTime = gmdate('H:i:s', (time()+$gmt_bolge));
$xml = new DOMDocument();
$xml->load(NTGEFatura::$dizin. DIRECTORY_SEPARATOR .'sablonlar/SistemYanitiPostaKutusu.xml');
$xpath = new DOMXPath($xml);
$xpath->query('//cbc:ID')->item(0)->nodeValue = NTGEFatura::uuid($gelen['kod'].$gelen['mesaj'], 'NTGEFatura-'.$IssueDate.' '.$IssueTime.$gelen['hash'], true);
$xpath->query('//cbc:UUID')->item(0)->nodeValue = NTGEFatura::uuid($gelen['kod'].$gelen['mesaj'], 'NTGEFatura-'.$IssueDate.' '.$IssueTime, true);
$xpath->query('//cbc:IssueDate')->item(0)->nodeValue = $IssueDate;
$xpath->query('//cbc:IssueTime')->item(0)->nodeValue = $IssueTime;
$xpath->query('cac:ReceiverParty/cac:PartyIdentification/cbc:ID')->item(0)->nodeValue = $gelen['vkn_tckn'];
if(strlen($gelen['vkn_tckn']) == 10)
$xpath->query('cac:ReceiverParty/cac:PartyIdentification/cbc:ID')->item(0)->setAttribute('schemeID','VKN');
else $xpath->query('cac:ReceiverParty/cac:PartyIdentification/cbc:ID')->item(0)->setAttribute('schemeID','TCKN');
$xpath->query('cac:ReceiverParty/cac:PartyName/cbc:Name')->item(0)->nodeValue = $gelen['unvan'];
$xpath->query('cac:ReceiverParty/cac:PostalAddress/cbc:StreetName')->item(0)->nodeValue = $gelen['adres'];
$xpath->query('cac:ReceiverParty/cac:PostalAddress/cbc:CityName')->item(0)->nodeValue = $gelen['il'];
$xpath->query('cac:ReceiverParty/cac:PostalAddress/cbc:PostalZone')->item(0)->nodeValue = $gelen['posta_kodu'];
$xpath->query('cac:ReceiverParty/cac:PostalAddress/cac:Country/cbc:Name')->item(0)->nodeValue = $gelen['ulke'];
$xpath->query('//cac:DocumentResponse/cac:Response/cbc:ReferenceID')->item(0)->nodeValue = NTGEFatura::uuid($gelen['mesaj'], 'NTG-'.$IssueDate.' '.$IssueTime, false);
$xpath->query('//cac:DocumentResponse/cac:LineResponse/cac:LineReference/cbc:LineID')->item(0)->nodeValue = '0';
$xpath->query('//cac:DocumentResponse/cac:DocumentReference/cbc:ID')->item(0)->nodeValue = $gelen['hash'];
$xpath->query('//cac:DocumentResponse/cac:LineResponse/cac:LineReference/cac:DocumentReference/cbc:ID')->item(0)->nodeValue = $gelen['hash'];
$xpath->query('//cac:DocumentResponse/cac:DocumentReference/cbc:IssueDate')->item(0)->nodeValue = $IssueDate;
$xpath->query('//cac:DocumentResponse/cac:LineResponse/cac:LineReference/cac:DocumentReference/cbc:IssueDate')->item(0)->nodeValue = $IssueDate;
$xpath->query('//cac:DocumentResponse/cac:LineResponse/cac:Response/cbc:ReferenceID')->item(0)->nodeValue = NTGEFatura::uuid($gelen['mesaj'], $gelen['kod'].'-'.$IssueDate.' '.$IssueTime, true);
$xpath->query('//cac:DocumentResponse/cac:LineResponse/cac:Response/cbc:ResponseCode')->item(0)->nodeValue = $gelen['kod'];
$xpath->query('//cac:DocumentResponse/cac:LineResponse/cac:Response/cbc:Description')->item(0)->nodeValue = $gelen['mesaj'];
$XMLSonuc = $xml->saveXML();
NTGEFatura::$dosya_adi = null;
NTGEFatura::$fatura_no = NTGEFatura::uuid(microtime().md5(rand(1111111,99999999999)), 'NTGbot');
$XMLImza = new NTGEFatura();
/*$XMLImza->XSDTesti();
$XMLImza->UBLTesti();*/
if($a['test'] == 'false') NTGEFatura::$ZarfBilgileri['musteri']['mail'] = $gelen['mail'];
else NTGEFatura::$ZarfBilgileri['musteri']['mail'] = (($gelen['mail'] == 'GIB') ? $gelen['mail'] : (($gelen['mail'] == $a['test_posta_kutusu_mail']) ? $a['test_posta_kutusu_mail'] : $a['test_gonderici_mail']));
NTGEFatura::$ZarfBilgileri['musteri']['unvan'] = $gelen['unvan'];
NTGEFatura::$ZarfBilgileri['musteri']['vkn_tckn'] = $gelen['vkn_tckn'];
return $XMLImza->zarf($XMLSonuc);
}
}
?>
<?php
namespace BLS;
use DOMDocument;
use DOMXpath;
use SoapFault;
use BLS\NTGEFaturaGUID;
use BLS\NTGEFatura;
use BLS\EFaturaFault;
use BLS\documentReturnType;
use BLS\getAppRespResponseType;
use BLS\NTGEFaturaLog;
use BLS\NTGEFaturaSistemYaniti;
/* Soap Sunucu Sınıfı */
class NTGEFaturaSoapSunucu {
private static function DosyaSil($dosya)
{
$dosya_adi_zip = NTGEFatura::$dizin. DIRECTORY_SEPARATOR .'temp/gecici/'.$dosya;
$dosya_adi_xml = NTGEFatura::$dizin. DIRECTORY_SEPARATOR .'temp/gecici/'.pathinfo($dosya,PATHINFO_FILENAME).'.xml';
/* Dosyalar Kontrol Edildi Ve Siliniyorlar */
if(is_file($dosya_adi_zip)) @unlink($dosya_adi_zip);
if(is_file($dosya_adi_xml)) @unlink($dosya_adi_xml);
}
private static function GelenZip($gelen)
{
$dosya_adi_zip = NTGEFatura::$dizin. DIRECTORY_SEPARATOR .'temp/gecici/'.$gelen['uuid'];
$dosya_adi_xml = NTGEFatura::$dizin. DIRECTORY_SEPARATOR .'temp/gecici/'.pathinfo($dosya_adi_zip,PATHINFO_FILENAME).'.xml';
$binaryData = base64_decode($gelen['efatura_base64']);
/* GECERSIZ ZARF ADI */
if(pathinfo($gelen['uuid'],PATHINFO_EXTENSION) != 'zip')
{
self::DosyaSil($gelen['uuid']);
return array('kod' => 2006, 'zip' => '');
}
/* ZIP ACILAMADI */
if (strpos($binaryData, "\0") == FALSE)
{
self::DosyaSil($gelen['uuid']);
return array('kod' => 1130, 'zip' => '');
}
/* ZİP DOSYA OLARAK KAYDEDİLİYOR */
NTGEFatura::DosyaYaz($dosya_adi_zip, $binaryData);
/* DOSYA KONUMU ATANIYOR */
NTGEFatura::$dosya_adi = $dosya_adi_zip;
/* ZİP DOSYASI AÇILIYOR */
$zipAc = NTGEFatura::zipAc(true, NTGEFatura::$dizin. DIRECTORY_SEPARATOR .'temp/gecici/');
self::DosyaSil($gelen['uuid']);
/* ZIP OKUMA HATALARI */
if(!is_array($zipAc) AND is_numeric($zipAc))
{
return array('kod' => $zipAc, 'zip' => '');
}
/* ZIP ACILAMADI */
else if(!is_array($zipAc) AND !is_numeric($zipAc))
{
return array('kod' => 1130, 'zip' => '');
}
/* OZET DEGERLER ESIT DEGIL */
else if(strtoupper($gelen['hash']) != strtoupper(hash('md5', $binaryData)))
{
return array('kod' => 2000, 'zip' => '');
}
/*NTGEFatura::$dosya_adi = $dosya_adi_xml;
NTGEFatura::$dosya_xsd = 'ubl/xml/PackageProxy_1_2.xsd';
$XMLImza = new NTGEFatura();*/
/* XML SEMA KONTROLUNDEN GECEMEDI VS. */
/*$xsdSonuc = $XMLImza->XSDTesti(true);
if ($xsdSonuc != '')
{
self::DosyaSil($gelen['uuid']);
return array('kod' => $xsdSonuc, 'zip' => '');
}*/
return array('kod' => 1200, 'zip' => $zipAc);
}
public function sendDocument($gelen) {
extract($GLOBALS);
// NTGEFaturaLog::log(['sendDocument.txt', $gelen, true]);
// 9 = gelen belge / 10 = hatalı belge / 0 = giden fatura / 2 = gelen fatura / 4 = gelen yanıt - giden yanıt
$dcRtrn = new documentReturnType();
if((isset($gelen->fileName)) AND (isset($gelen->binaryData)) AND (isset($gelen->hash)))
{
$gDosya = str_replace('.zip', '', $gelen->fileName);
$FTRSorgu = $SQL->sorgu("SELECT no FROM $onek_efatura_base64 WHERE (uuid like '%$gDosya%' and kutu!='0' and kutu!='1' and kutu!='4' and iptal='0') or (uuid like '%$gDosya%' and kutu='4' and tur='gelen_yanit' and iptal='0') limit 1");
if($SQL->num_rows($FTRSorgu) == 0)
{
$zarf_md5 = $gelen->fileName;
$base64 = base64_encode($gelen->binaryData->_);
$tarih = time();
$GelenZip = $this->GelenZip(array(
'uuid' => $zarf_md5,
'efatura_base64' => $base64,
'hash' => $gelen->hash,
));
if((is_array($GelenZip['zip'])) AND (count($GelenZip['zip']) > 0))
{
$MySQL_Ekle = "INSERT INTO $onek_efatura_base64 (kutu, tur, uuid, efatura_base64, tarih)";
$MySQL_Ekle .= "VALUES ('9', 'gelen_belge', '$zarf_md5', '$base64', '$tarih')";
$SQLAS = $SQL->sorgu($MySQL_Ekle);
$SQL->free_result($SQLAS);
$dcRtrn->hash($gelen->hash);
$dcRtrn->msg('BASARIYLA ISLENDI'); /* BASARIYLA ISLENDI */
return $dcRtrn;
}
else return $this->EFaturaFaultMessage($GelenZip['kod'], $DurumKodu[$GelenZip['kod']], $gDosya); /* HATALI */
}
else return $this->EFaturaFaultMessage(2001, $DurumKodu[2001], $gDosya); /* ZARF ID SISTEMDE MEVCUT */
}
else return $this->EFaturaFaultMessage(1110, $DurumKodu[1110], $gDosya); /* ZIP DOSYASI DEGIL */
}
public function getApplicationResponse($gelen) {
extract($GLOBALS);
NTGEFaturaLog::log(['temp/log/Istekler.txt', $gelen, false]);
// if(is_array($gelen))
// {
// $gelen = new getAppRespRequestType();
// $gelen->instanceIdentifier($gelen['instanceIdentifier']); /* Zip Dosyası Adı - Zarf "InstanceIdentifier" İle Aynı Olmalı ! */
// }
if((isset($gelen->instanceIdentifier)) AND (strlen($gelen->instanceIdentifier) > 20))
{
$instanceIdentifier = $gelen->instanceIdentifier;
$FTRSorgu = $SQL->sorgu("SELECT * FROM $onek_efatura_base64 WHERE uuid='$instanceIdentifier' and iptal='0' limit 1");
$FTRSonuc = $SQL->fetch_assoc($FTRSorgu);
if($SQL->num_rows($FTRSorgu) > 0)
{
$XMLSonuc = NTGEFaturaSistemYaniti::SistemYaniti(array(
'hash' => $instanceIdentifier,
'kod' => $FTRSonuc['durum_no'],
'mesaj' => (($FTRSonuc['durum_no'] == 1200) ? $DurumKodu[$FTRSonuc['durum_no']] : $FTRSonuc['durum_mesaji']),
'vkn_tckn' => $FTRSonuc['vkn_tckn'],
'unvan' => $FTRSonuc['unvan'],
'mail' => $FTRSonuc['mail'],
'adres' => $FTRSonuc['adres'],
'il' => $FTRSonuc['il'],
'posta_kodu' => $FTRSonuc['posta_kodu'],
'ulke' => $FTRSonuc['ulke']
));
$rtn = new getAppRespResponseType();
$rtn->applicationResponse($XMLSonuc);
NTGEFaturaLog::log(['temp/log/Cevaplar.txt', $rtn, false]);
return $rtn;
}
else return $this->EFaturaFaultMessage(2004, $DurumKodu[2004], $instanceIdentifier); /* ZARF ID BULUNAMADI */
}
else return $this->EFaturaFaultMessage(2006, $DurumKodu[2006]); /* GECERSIZ ZARF ADI */
}
public function EFaturaFaultMessage($code, $msg, $id='') {
NTGEFaturaLog::log(['temp/log/Hatalar.txt', gmdate('d.m.Y H:i:s', (time()+10800)).': ['.$id.' / '.$code.' - '.$msg."]\r\n", false]);
$Fault = new EFaturaFault();
$Fault->code($code);
$Fault->msg($msg);
return (new SoapFault("Server", $code.":".$msg, null, $Fault, null));
}
}
?>
<?php
define('ANA_DIZIN',(realpath(__DIR__)));
include_once 'Veritabani.php';
include_once 'inc/DurumKodlari.inc';
include_once 'Siniflar/NTGEFaturaGUID.php';
include_once 'Siniflar/documentReturnType.php';
include_once 'Siniflar/EFaturaFault.php';
include_once 'Siniflar/getAppRespResponseType.php';
include_once 'Siniflar/NTGEFaturaLog.php';
include_once 'Siniflar/NTGEFaturaSistemYaniti.php';
include_once 'Siniflar/NTGEFaturaSoapSunucu.php';
try {
$snc=new SoapServer((($a['test'] == 'true') ? './wsdl/EFatura_Test.wsdl' : './wsdl/EFatura_Canli.wsdl'), array('uri'=>'http://www.w3.org/2003/05/soap-envelope','encoding'=>'UTF-8'));
$snc->setClass('BLS\NTGEFaturaSoapSunucu');
$snc->setPersistence(SOAP_PERSISTENCE_SESSION);
$snc->handle();
}catch(SoapFault $e) {
error_log("SOAP ERROR: ". $e->getMessage());
// echo $exc->getTraceAsString();
}
?>
<?php
/* SOAP İşlemleri */
@ini_set('xdebug.max_nesting_level', "100000000000000000000");
@ini_set('xdebug.remote_autostart', "0");
@ini_set('xdebug.remote_enable', "0");
@ini_set('max_allowed_packet', "2000M");
set_time_limit(259200);
@ini_set('magic_quotes_runtime', 0);
@ini_set('default_charset', 'UTF-8');
@ini_set('safe_mode', 0);
@ini_set('register_globals', 0);
@ini_set('memory_limit', '2048M');
@ini_set('post_max_size', '2048M');
@ini_set('upload_max_filesize', '2048M');
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
ini_set('mysql.connect_timeout', 120);
ini_set('default_socket_timeout', 120);
$AnaDizin = 'efatura_loglar/';
$DizinSonuc = $AnaDizin.gmdate('d.m.Y').'/';
$LogDizini = $DizinSonuc.'log/';
$ZipDizini = $DizinSonuc.'zip/';
/* Dizin oluşturucu */
function dizinVEchmod($dizin, $chmod=0777, $index=true)
{
$aDzvn = '';
foreach(explode('/', $dizin) as $dzn)
{
if($dzn != '')
{
$aDzvn .= $dzn.'/';
if (!is_dir($aDzvn))
{
@mkdir($aDzvn, $chmod); // 0777 tüm hakları(yaz,değiştir,sil) herkese ver demek
@chmod($aDzvn, $chmod); // 0777 tüm hakları(yaz,değiştir,sil) herkese ver demek
if($index == true) @fopen($aDzvn.'index.html','w');
}
}
}
return $aDzvn;
}
/* #Dizin oluşturucu */
/* GİB WSDL */
if((isset($_SERVER['HTTP_USER_AGENT'])) AND ($_SERVER['HTTP_USER_AGENT'] == 'NTGEFaturaSoap'))
{
$WSDLAdres = 'https://merkeztest.efatura.gov.tr/EFaturaMerkez/services/EFatura?wsdl';
// $WSDLAdres = 'https://merkez.efatura.gov.tr/EFaturaMerkez/services/EFatura?wsdl';
$istek = 'NTG';
}
else if((isset($_SERVER['HTTP_USER_AGENT'])) AND ($_SERVER['HTTP_USER_AGENT'] == 'TEST'))
{
$WSDLAdres = 'https://merkeztest.efatura.gov.tr/EFaturaMerkez/services/EFatura?wsdl';
// $WSDLAdres = 'http://site.com/EFatura/EFaturaSunucu.php?wsdl';
$istek = 'TEST';
}
else
{
$WSDLAdres = 'http://site.com/EFatura/EFaturaSunucu.php?wsdl';
$istek = 'GİB';
}
function loglar($dosya, $yaz)
{
global $LogDizini;
$logDurumu = true;
if($logDurumu == true)
{
@dizinVEchmod($LogDizini);
if($dsy = fopen($LogDizini.$dosya, 'a+'))
{
fwrite($dsy, gmdate('d-m-Y H:i:s', time()+10800).":\r\n\r\n".$yaz."\r\n\r\n----------------------------------------------------------------------------------\r\n");
fclose($dsy);
}
@dizinVEchmod($LogDizini, 0755);
}
}
class NTGEFIstemci extends SoapClient
{
public function __construct()
{
extract($GLOBALS);
parent::__construct($WSDLAdres, array(
'location' => $WSDLAdres,
'uri' => $WSDLAdres,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'authentication'=> SOAP_AUTHENTICATION_DIGEST,
'ssl' => array(
'ciphers'=> "SHA1",
'verify_peer' => false,
'allow_self_signed' => true
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false
),
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
'encoding' => 'utf-8',
'stream_context' => stream_context_create(array('http'=>array('user_agent' => 'NTGEFaturaSoap'), 'socket' => array('bindto' => $_SERVER['SERVER_ADDR'].':0'))),
'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
"connection_timeout" => 120
));
}
/* PHP SOAP MTOM */
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
$start=strpos($response,'<soap');
$end=strrpos($response,'>');
$response_string=substr($response,$start,$end-$start+1);
return($response_string);
}
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
$istemci = new NTGEFIstemci($WSDLAdres, array('trace' => false, 'exceptions' => false));
$php_input = file_get_contents('php://input');
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
if((isset($_GET['istek'])) AND ($_GET['istek'] == 'TEKRAR') AND (isset($_GET['dosya_adi'])) AND ($_GET['dosya_adi'] != ''))
{
try {
$dosyaBinary = file_get_contents($AnaDizin.urldecode($_GET['dosya_adi']));
$istemci->__soapCall('sendDocument', array(array(
'fileName' => @end(explode('/', urldecode($_GET['dosya_adi']))), /* Zip Dosyası Adı - Zarf "InstanceIdentifier" İle Aynı Olmalı ! */
'binaryData' => $dosyaBinary, /* Zip Dosyası Verisi ! */
'hash' => strtoupper(hash('md5', $dosyaBinary)) /* Zip Dosyası MD5 Verisi ! */
)));
header('Content-Type: text/xml');
echo $istemci->__getLastResponse();
} catch(SoapFault $e) {
$hataSonucu = $istemci->__getLastResponse();
header('Content-Type: text/xml');
echo $hataSonucu;
}
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
elseif($istek == 'GİB')
{
$GibLogGenel = false;
if($GibLogGenel == true) loglar('__GIB_GENEL.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
try {
$basliklar = getallheaders();
preg_match("#action=\"([^\"]+)\";?#", $basliklar['Content-Type'], $action);
if((isset($action[1])) AND ($action[1] == 'sendDocument'))
{
if($GibLogGenel == false) loglar('__GIB_SENDDOCUMENT.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
preg_match('#"cid:(.*?)"#', $php_input, $uuid);
preg_match('#<fileName>(.*?)</fileName>#', $php_input, $dosya_adi);
preg_match('#<hash>(.*?)</hash>#', $php_input, $hash);
$ara = '<'.$uuid[1].'>';
$start=strpos($php_input, $ara);
$ilk = $start+strlen($ara);
$end=strrpos($php_input, '--uuid:');
$son=($end-$ilk);
$veri=rtrim(ltrim(substr($php_input,$ilk,$son)),"\r\n");
@dizinVEchmod($ZipDizini);
if($GibLogGenel == false) @file_put_contents($ZipDizini.$dosya_adi[1], $veri);
@dizinVEchmod($ZipDizini, 0755);
$istemci->__soapCall($action[1], array(array(
'fileName' => $dosya_adi[1], /* Zip Dosyası Adı - Zarf "InstanceIdentifier" İle Aynı Olmalı ! */
'binaryData' => $veri, /* Zip Dosyası Verisi ! */
'hash' => $hash[1] /* Zip Dosyası MD5 Verisi ! */
)));
header('Content-Type: text/xml');
echo $istemci->__getLastResponse();
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
else if((isset($action[1])) AND ($action[1] == 'getApplicationResponse'))
{
preg_match('#<instanceIdentifier>(.*?)</instanceIdentifier>#', $php_input, $instanceIdentifier);
// loglar('__GIB_GETAPPLICATIONRESPONSE_GENEL.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
if((isset($instanceIdentifier[1])) AND ($instanceIdentifier[1] != ''))
{
if($GibLogGenel == false) loglar('__GIB_GETAPPLICATIONRESPONSE_HTTP.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
$istemci->__soapCall($action[1], array(array(
'instanceIdentifier' => $instanceIdentifier[1]
)));
$sonuc = $istemci->__getLastResponse();
header('Content-Type: text/xml');
echo $sonuc;
}
else
{
if($GibLogGenel == false) loglar('__GIB_GETAPPLICATIONRESPONSE_SOAP.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
try {
$snc=new SoapServer($WSDLAdres, array(
'location' => $WSDLAdres,
'uri' => $WSDLAdres,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'authentication'=> SOAP_AUTHENTICATION_DIGEST,
'ssl' => array(
'ciphers'=> "SHA1",
'verify_peer' => false,
'allow_self_signed' => true
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false
),
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
'encoding' => 'utf-8',
'stream_context' => stream_context_create(array('http'=>array('user_agent' => 'NTGEFaturaSoap'), 'socket' => array('bindto' => $_SERVER['SERVER_ADDR'].':0'))),
'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
"connection_timeout" => 120
));
$snc->setClass('NTGEFIstemci');
$snc->handle();
}
catch(SoapFault $e) {
loglar('__GIB_SORGU_HATA_GETAPP.txt', $e);
echo $e->getTraceAsString();
}
}
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
else
{
if($GibLogGenel == false) loglar('__GIB_KONTROL_LOGLARI.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
header('Content-Type: text/xml');
die(file_get_contents($WSDLAdres));
}
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
catch(SoapFault $e) {
$hataSonucu = $istemci->__getLastResponse();
loglar('__GIB_SORGU_HATA_GENEL.txt', $hataSonucu);
header('Content-Type: text/xml');
echo $hataSonucu;
}
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
elseif($istek == 'TEST')
{
$GibLogGenel = false;
if($GibLogGenel == true) loglar('__TEST_GENEL.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
$basliklar = getallheaders();
preg_match("#action=\"([^\"]+)\";?#", $basliklar['Content-Type'], $action);
if((isset($action[1])) AND ($action[1] == 'sendDocument'))
{
if($GibLogGenel == false) loglar('__TEST_SENDDOCUMENT.txt', print_r(getallheaders(), true)."\r\n".print_r($php_input, true));
@dizinVEchmod($LogDizini);
if($GibLogGenel == false) @file_put_contents($LogDizini.$basliklar['fileName'], $php_input);
@dizinVEchmod($LogDizini, 0755);
}
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
else
{
try {
$basliklar = getallheaders();
if((isset($basliklar['action'])) AND ($basliklar['action'] == 'sendDocument'))
{
$istemci->__soapCall('sendDocument', array(array(
'fileName' => $basliklar['fileName'], /* Zip Dosyası Adı - Zarf "InstanceIdentifier" İle Aynı Olmalı ! */
'binaryData' => $php_input, /* Zip Dosyası Verisi ! */
'hash' => $basliklar['hash'] /* Zip Dosyası MD5 Verisi ! */
)));
/*** ######################################### ***/
/*** ######################################### ***/
/*** ######################################### ***/
/*if($dsy = fopen('efatura_loglar/'.$basliklar['fileName'], 'a+'))
{
fwrite($dsy, $php_input);
fclose($dsy);
}*/
/*** ######################################### ***/
/*** ######################################### ***/
/*** ######################################### ***/
}
else if((isset($basliklar['action'])) AND ($basliklar['action'] == 'getApplicationResponse'))
{
$istemci->__soapCall('getApplicationResponse', array(array(
'instanceIdentifier' => $basliklar['instanceIdentifier']
)));
}
else
{
header('Content-Type: text/xml');
die(file_get_contents($WSDLAdres));
}
$sonuc = $istemci->__getLastResponse();
header('Content-Type: text/xml');
echo $sonuc;
loglar('__NTG_SORGU.txt', $sonuc);
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
catch(SoapFault $e) {
$hataSonucu = $istemci->__getLastResponse();
loglar('__NTG_SORGU_HATA.txt', $hataSonucu);
header('Content-Type: text/xml');
echo $hataSonucu;
}
}
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
/*** ########################################################################################################### ***/
?>
<soap12:address location="https://site.com/NTGEFatura.php" />
$dcRtrn->hash($gelen->hash);
$dcRtrn->msg('BASARIYLA ISLENDI'); /* BASARIYLA ISLENDI */