VIES增值税号验证不起作用

时间:2017-12-20 13:27:19

标签: php

我使用此代码检查有效的vies vat:

$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
$clientValues = ($client->checkVat(array(
  'countryCode' => $afmCountry,
  'vatNumber' => $afmCode
)));
if ($clientValues->valid == 1) {
    echo "ok";
} else {
    echo "Not ok";
}

最后几天,此脚本停止工作。造成很大的延迟,然后没有返回任何结果。我认为问题是我的PHP(版本5.3),我无法改变

1 个答案:

答案 0 :(得分:0)

这是实现服务的另一种方法

的index.php

<?php
    require 'VatService.php';
    $service = new VatService();

    if (!empty($_POST)) {
        if (isset($_POST['txt_vat_number'])) $_POST['txt_vat_number'] = trim(str_replace(['.', ' ',], '', $_POST['txt_vat_number']));
        try {
            $response = $service->checkVat(new CheckVat($_POST['cbo_country'], $_POST['txt_vat_number']));
        }catch(Exception $e){
            $response = $e->getMessage();
        }
    }
?>
<!DOCTYPE html>
<html>
    <head>
        <title>CheckVat</title>
        <meta charset="UTF-8" />
    </head>
    <body>
        <form method="POST">
            <select name="cbo_country">
                <option value="BE">Belgium</option>
                <option value="NL">Netherlands</option>
            </select>
            <input type="text" name="txt_vat_number" value="<?=@$_POST['txt_vat_number']?>" />
            <button type="submit">Lookup</button>
        </form>
        <?php if (isset($response)) {?>
        <div>
            <pre><?php print_r($response) ?></pre>
        </div>
        <?php } ?>
    </body>
</html>

VatService.php

<?php

class checkVat {
    var $countryCode;//string
    var $vatNumber;//string

    public function __construct($countryCode, $vatNumber) {
        $this->countryCode = $countryCode;
        $this->vatNumber = $vatNumber;
    }
}

class checkVatResponse {
    var $countryCode;//string
    var $vatNumber;//string
    var $requestDate;//date
    var $valid;//boolean
    var $name;//string
    var $address;//string
}
class checkVatApprox {
    var $countryCode;//string
    var $vatNumber;//string
    var $traderName;//string
    var $traderCompanyType;//companyTypeCode
    var $traderStreet;//string
    var $traderPostcode;//string
    var $traderCity;//string
    var $requesterCountryCode;//string
    var $requesterVatNumber;//string
}
class checkVatApproxResponse {
    var $countryCode;//string
    var $vatNumber;//string
    var $requestDate;//date
    var $valid;//boolean
    var $traderName;//string
    var $traderCompanyType;//companyTypeCode
    var $traderAddress;//string
    var $traderStreet;//string
    var $traderPostcode;//string
    var $traderCity;//string
    var $traderNameMatch;//matchCode
    var $traderCompanyTypeMatch;//matchCode
    var $traderStreetMatch;//matchCode
    var $traderPostcodeMatch;//matchCode
    var $traderCityMatch;//matchCode
    var $requestIdentifier;//string
}
class VatService  {
    var $soapClient;

    private static $classmap = array(
        'checkVat'                  =>'checkVat',
        'checkVatResponse'          =>'checkVatResponse',
        'checkVatApprox'            =>'checkVatApprox',
        'checkVatApproxResponse'    =>'checkVatApproxResponse',

    );

    function __construct($url='http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl') {
        $this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
    }

    function checkVat($checkVat) {
        return $this->soapClient->checkVat($checkVat);
    }
    function checkVatApprox($checkVatApprox) {
        return $this->soapClient->checkVatApprox($checkVatApprox);
    }
}<?php

class checkVat {
    var $countryCode;//string
    var $vatNumber;//string

    public function __construct($countryCode, $vatNumber) {
        $this->countryCode = $countryCode;
        $this->vatNumber = $vatNumber;
    }
}

class checkVatResponse {
    var $countryCode;//string
    var $vatNumber;//string
    var $requestDate;//date
    var $valid;//boolean
    var $name;//string
    var $address;//string
}
class checkVatApprox {
    var $countryCode;//string
    var $vatNumber;//string
    var $traderName;//string
    var $traderCompanyType;//companyTypeCode
    var $traderStreet;//string
    var $traderPostcode;//string
    var $traderCity;//string
    var $requesterCountryCode;//string
    var $requesterVatNumber;//string
}
class checkVatApproxResponse {
    var $countryCode;//string
    var $vatNumber;//string
    var $requestDate;//date
    var $valid;//boolean
    var $traderName;//string
    var $traderCompanyType;//companyTypeCode
    var $traderAddress;//string
    var $traderStreet;//string
    var $traderPostcode;//string
    var $traderCity;//string
    var $traderNameMatch;//matchCode
    var $traderCompanyTypeMatch;//matchCode
    var $traderStreetMatch;//matchCode
    var $traderPostcodeMatch;//matchCode
    var $traderCityMatch;//matchCode
    var $requestIdentifier;//string
}
class VatService  {
    var $soapClient;

    private static $classmap = array(
        'checkVat'                  =>'checkVat',
        'checkVatResponse'          =>'checkVatResponse',
        'checkVatApprox'            =>'checkVatApprox',
        'checkVatApproxResponse'    =>'checkVatApproxResponse',

    );

    function __construct($url='http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl') {
        $this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
    }

    function checkVat($checkVat) {
        return $this->soapClient->checkVat($checkVat);
    }
    function checkVatApprox($checkVatApprox) {
        return $this->soapClient->checkVatApprox($checkVatApprox);
    }
}