VIES增值税号验证

Min*_*oso 26 html javascript php jquery vies

有谁知道在我们的网站上整合表格以验证VIES的方法?我找到了通过欧盟网站验证的信息.

http://ec.europa.eu/taxation_customs/vies/vieshome.do

我感兴趣的是直接从我的网站的支付数据形式验证.

谢谢.

Nik*_*ski 92

实际上,可以通过API查询VIES数据库.
它们仅支持SOAP协议,但这应该足够了.

这是一个简单的例子:

$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
var_dump($client->checkVat(array(
  'countryCode' => $countryCode,
  'vatNumber' => $vatNo
)));
Run Code Online (Sandbox Code Playgroud)

这是WSDL:http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

有多个API提供程序基于原始提供程序,但使用不同的协议提供它.简单地说,它们就像翻译一样 - 将json与您的应用程序一起使用,并使用SOAP连接到原始API.这些连接超时存在严重问题.

有时VIES数据库响应缓慢,因此需要更多时间来返回响应.在设计应用程序时应考虑这一点.

  • 令人震惊的服务可靠性!尝试实施以遵守新的欧盟增值税法律,但始终出现"SERVER_BUSY"错误. (8认同)
  • 您可能希望此SOAP接口只检查增值税号的中央数据库,但这不存在.每个国家都管理自己的数据库,欧盟委员会只是在调度查询.查询甚至不会一直停留在Web服务上,它们通过传统的海关网络(CCN/CSI)传输,并且远程系统在某些国家可能非常糟糕.甚至整个国家都会退出系统几天甚至几周! (7认同)

Ger*_*ied 29

他们最近(2022 年 9 月)能够实现新的 REST API。我通过检查他们自己的网络表单的请求发现了这一点。API 网址为:

https://ec.europa.eu/taxation_customs/vies/rest-api/ms/[国家]/vat/[增值税]

例如增值税 ID = DE122268496

https://ec.europa.eu/taxation_customs/vies/rest-api/ms/DE/vat/122268496

结果:

{
  "isValid" : true,
  "requestDate" : "2022-09-15T13:02:47.009Z",
  "userError" : "VALID",
  "name" : "---",
  "address" : "---",
  "requestIdentifier" : "",
  "vatNumber" : "122268496",
  "viesApproximate" : {
    "name" : "---",
    "street" : "---",
    "postalCode" : "---",
    "city" : "---",
    "companyType" : "---",
    "matchName" : 3,
    "matchStreet" : 3,
    "matchPostalCode" : 3,
    "matchCity" : 3,
    "matchCompanyType" : 3
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 你救了我的命。它甚至还没有出现在文档中。 (4认同)

Eug*_*scu 23

如果由于某些原因你不能在你的服务器上使用SOAP(没有可用的话),那么file_get_contents就是你的朋友.

下面的实现不依赖于SOAP,Curl,XMLParser(简单或不简单).它是标准的PHP代码,适用于您可能拥有的任何PHP版本.

该函数返回以下项:

  • 国家代码
  • VATNUMBER
  • 查询日期
  • 有效
  • 名称
  • 地址

好吧,我希望它有所帮助:-)

<?php
DEFINE ( 'VIES_URL', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService' );

/**
 * VIES VAT number validation
 *
 * @author Eugen Mihailescu
 *        
 * @param string $countryCode           
 * @param string $vatNumber         
 * @param int $timeout          
 */
function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) {
    $response = array ();
    $pattern = '/<(%s).*?>([\s\S]*)<\/\1/';
    $keys = array (
            'countryCode',
            'vatNumber',
            'requestDate',
            'valid',
            'name',
            'address' 
    );

    $content = "<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'>
      <tns1:countryCode>%s</tns1:countryCode>
      <tns1:vatNumber>%s</tns1:vatNumber>
    </tns1:checkVat>
  </s11:Body>
</s11:Envelope>";

    $opts = array (
            'http' => array (
                    'method' => 'POST',
                    'header' => "Content-Type: text/xml; charset=utf-8; SOAPAction: checkVatService",
                    'content' => sprintf ( $content, $countryCode, $vatNumber ),
                    'timeout' => $timeout 
            ) 
    );

    $ctx = stream_context_create ( $opts );
    $result = file_get_contents ( VIES_URL, false, $ctx );

    if (preg_match ( sprintf ( $pattern, 'checkVatResponse' ), $result, $matches )) {
        foreach ( $keys as $key )
            preg_match ( sprintf ( $pattern, $key ), $matches [2], $value ) && $response [$key] = $value [2];
    }
    return $response;
}

print_r ( viesCheckVAT ( 'RO', '19386256' ) );
?>
Run Code Online (Sandbox Code Playgroud)


Mar*_*mro 5

此网站将普通的HTML表单发送到服务器.

最简单的解决方案是在URL中传递params并使用file_get_contents来获取响应.

然后可以解析响应以提取所需的信息.未经测试,但显示了这个想法:

$country1 = 'PL';
$country2 = 'PL';
$vatnum1 = '123456';
$vatnum2 = '789012';

//Prepare the URL
$url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms='.$country1.'&iso='.$country1.'&vat='.$vatnum1.'&name=&companyType=&street1=&postcode=&city=&requesterMs='.$country2.'&requesterIso='.$country2.'&requesterVat='.$vatnum2.'&BtnSubmitVat=Verify';

$response = file_get_contents($url);
// Do sth with the response
echo $response;
Run Code Online (Sandbox Code Playgroud)

  • @Johan本文介绍如何使用VIES VAT SOAP Web服务:http://www.webmastersdiary.com/2011/12/php-vies-vat-number-validation-european.html (10认同)
  • @LesCarbonaro这里更新链接:http://www.webmastersdiary.com/blog/php-vies-vat-number-validation-european-vat-id/(对不起,但博客从那时起得到了一些更新) (3认同)