Integrace webové služby v PHP

Vzorové metody pro přístup k WS CreditCheck z prostředí PHP.




Metody jsou přizpůsobené pro CZ webovou službu. Pro využití SK WS stačí pozměnit wsdl/location/uri webové služby.

function downloadCreditCheck()
{
    $wsdl = 'http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx?wsdl';
    $cc = new SoapClient($wsdl,  array('location' => "http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx",
        'uri'      => "http://creditcheck.cz/"));
    try {
        $ch = array(
            "Login" => "jmeno",
            "Password" => "heslo",
        );

        $cc->__setSoapHeaders(new SoapHeader("http://creditcheck.cz/", "CreditCheckHeader", $ch));
        $ret = $cc->GetCreditChecks();
    } catch (SoapFault $e) {
        print_r($e);
        $ret = $e->faultstring;
        print_r($ret);
    }

    return $ret;
}


function downloadCreditCheckBatch($batchIndex)
{
    $wsdl = 'http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx?wsdl';
    $cc = new SoapClient($wsdl,  array('location' => "http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx",
        'uri'      => "http://creditcheck.cz/"));
    try {
        $ch = array(
            "Login" => "jmeno",
            "Password" => "heslo",
        );

        $cc->__setSoapHeaders(new SoapHeader("http://creditcheck.cz/", "CreditCheckHeader", $ch));
        $ret = $cc->GetCreditCheckBatch(
            array("lastBatchIndex" => $batchIndex)
        );
    } catch (SoapFault $e) {
        print_r($e);
        $ret = $e->faultstring;
        print_r($ret);
    }

    return $ret;
}

function downloadGetSubjectBasicReport(){
    $wsdl = 'http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx?wsdl';
    $cc = new SoapClient($wsdl,  array('location' => "http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx",
        'uri'      => "http://creditcheck.cz/"));
    try {
        $ch = array(
            "Login" => "jmeno",
            "Password" => "heslo",
        );

        $cc->__setSoapHeaders(new SoapHeader("http://creditcheck.cz/", "CreditCheckHeader", $ch));
        $params = new \SoapVar("
                <GetSubjectBasicReport xmlns='http://creditcheck.cz/'>
                <subjectData>
                <requestSubject xmlns=''>
                  <reportVersion>2</reportVersion>
                  <subjectType>privatePerson</subjectType>
                  <birthNumber>7710109856</birthNumber>
                  <firstName>Jméno</firstName>
                  <surname>Příjmení</surname>
                  <address>
                    <street>Ulice</street>
                    <number>Číslo popisné</number>
                    <city>Město</city>
                    <zip>Psč</zip>
                  </address>
                </requestSubject>
                </subjectData>
                </GetSubjectBasicReport>", XSD_ANYXML);

        $ret = $cc->GetSubjectBasicReport($params);
    } catch (SoapFault $e) {
        print_r($e);
        $ret = $e->faultstring;
        print_r($ret);
    }

    return $ret;
}



function downloadGetSubjectFullReport(){
    $wsdl = 'http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx?wsdl';
    $cc = new SoapClient($wsdl,  array('location' => "http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx",
        'uri'      => "http://creditcheck.cz/"));
    try {
        $ch = array(
            "Login" => "jmeno",
            "Password" => "heslo",
        );
 
        $cc->__setSoapHeaders(new SoapHeader("http://creditcheck.cz/", "CreditCheckHeader", $ch));
        $params = new \SoapVar("
                <GetSubjectFullReport xmlns='http://creditcheck.cz/'>
                <subjectData>
                <requestSubject xmlns=''>
                  <subjectType>Company</subjectType>
                  <reportVersion>2</reportVersion>
                  <ic>25055305</ic>
                  <history>0</history>
                  <ucetniZaverky>0</ucetniZaverky>
                </requestSubject>
                </subjectData>
                </GetSubjectFullReport>", XSD_ANYXML);
 
        $ret = $cc->GetSubjectFullReport($params);
    } catch (SoapFault $e) {
        print_r($e);
        $ret = $e->faultstring;
        print_r($ret);
    }
 
    return $ret;
}
 
 
 
function downloadCreditChecksCompressed(){
	$wsdl = 'http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx?wsdl';
	$cc = new SoapClient($wsdl,  array('location' => "http://creditwebservices.creditcheck.cz/CreditCheckAktualizace.asmx",
        	'uri'      => "http://creditcheck.cz/"));
    try {
        $ch = array(
            "Login" => "jmeno",
            "Password" => "heslo",
        );
 
	$cc->__setSoapHeaders(new SoapHeader("http://creditcheck.cz/", "CreditCheckHeader", $ch));
	$result = $cc->GetCreditChecksCompressed();
	$xml = simplexml_load_string($result->GetCreditChecksCompressedResult, 'SimpleXMLElement', LIBXML_PARSEHUGE);
	$ret = gzuncompress(base64_decode($xml->data));
	}
	catch (SoapFault $e) {
        print_r($e);
        $ret = $e->faultstring;
        print_r($ret);
    }
	
	return $ret;
}