0

我想用soap每月将我的发票上传到远程服务器,但是上传以某种方式失败而没有错误消息。

我使用数据库中的 DomDocument生成 XML 文件(发票) 。然后我根据 XSD 对其进行验证,如果返回正常,我将启动 SOAP 请求。

远程 SOAP 服务器的文档说,首先我必须调用身份验证服务来识别我自己并获取会话 ID,然后我才能开始上传。但是上传不起作用,我没有收到错误消息。我对肥皂不熟悉,所以我现在不知道该怎么办。

我就是这样做的:

$xml = $doc->saveXML(); /*before this is a very long code which creates the XML*/
$xmlauth = new DomDocument();
$xmlauth = loadXML($xml);
if(!$xmlauth->schemaValidate('https://test.e-szamla.hu/apeh_xml.xsd')){
echo 'Error: <br />';
libxml_display_errors(); /*this is a function that formats the error code and saves it to a log file*/
}
else {
    try {
      $trace = '1';
      $url = 'https://test.e-szamla.hu/soap/AuthenticationService.wsdl';
      $client = new SoapClient($url, array('trace' => $trace));
      $params = array(
        'username' => 'hu-0000000x-x-xx',
        'password' => 'XXXXXXX'
      );
    }
    catch(exception $e){
      echo '<h2>Error in connection: </h2>';
      echo $e->getMessage();
    }
    try {
      $result = $client->startSession($params);
      $_SESSION['sessid'] = $result->sessionid;
      //echo $_SESSION['sessid'];
    }
    catch(exception $e) {
      echo '<h2>Something went wrong:</h2>';
      echo $e->getMessage();
    }
    try {
    $urlinv = 'https://test.e-szamla.hu/soap/InvoiceService.wsdl';
    $clientinv = new SoapClient($urlinv, array('trace' => $trace));
    $paramsinv = array('sessionid' => $_SESSION['sessid'], 'partner' => 'hu-xxxxxxxx-x-xx', 'xml' => $xmlauth);
    }
    catch(exception $err) {
      echo '<h2>ERROR:</h2>';
      echo $err->getMessage();
    }
    try {
      $resultinv = $clientinv->uploadInvoice($paramsinv);
      echo 'Uploaded with this session id: '. $_SESSION['sessid'];
    }
    catch(exception $err){
      echo '<h2>Something went wrong: </h2>';
      echo $err->getMessage();
    }
}

XSD 和 WSDL URL 都是测试服务的真实 URL,这里是一个测试 XML:https ://test.e-szamla.hu/samples/dijbekero.xml

这是文档中的示例:

授权。服务

$client = new SoapClient($url."AuthenticationService.wsdl", array('trace' => $trace));
$params = array(
"username" => "hu-12345678-1-90",
"password" => "12345678"
);
$result = $client->startSession($params);
$_SESSION["sessid"] = $result->sessionid;

发票服务

$client = new SoapClient($url."InvoiceService.wsdl", array('trace' => $trace));
$xml = file_get_contents("samples/invoice.xml");
$params = array(
"sessionid" => $_SESSION["sessid"],
"partner" => "hu-00000000-2-00",
"xml" => $xml
);
$result = $client->uploadInvoice($params);

我怎样才能使这项工作或至少得到一条错误消息。如您所见,我正在传递每个必需的变量,例如用户名、密码和合作伙伴 ID,而我唯一更改的是我没有从文件中加载 XML。

4

0 回答 0