使用PHP SoapClient调用XML Soap失败



我正在尝试使用PHP SoapClient调用SOAP xml。然而,我得到的错误是

org.springframework.jdbc。CannotGetJdbcConnectionException:无法获得JDBC连接;嵌套异常是org.apache.commons.dbcp.SQLNestedException: Cannot create class " for connect URL 'null'的JDBC驱动程序

这是我使用SoapClient的代码。

$headers = array(
"POST /AGS/services/GetVIXNCD HTTP/1.1",
"Host: d1.financial-link.com.my",
"SOAPAction: "https://d1.financial-link.com.my/AGS/services/GetVIXNCD"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache", 
"Content-Type: text/xml; charset=utf-8 ",
"Authorization: Bearer " . $token, //to post from end user
"Content-Length: " . $this->getXmlLength($request)
);
$client = new SoapClient('https://d1.financial-link.com.my/AGS/services/GetVIXNCD?wsdl', $headers);
$arrExtraParam = array (
'paramIndicator' => $paramIndicator,
'paramRemark' => $paramRemark,
'paramValue' => $paramValue,
);
$params = array (
'agentcode' => $agentcode,
'arrExtraParam' => $arrExtraParam,
'bizregno' => $bizregno,
'compcode' => $compcode,
'newic' => $newic,
'oldic' => $oldic,
'passportno' => $passportno,
'regno' => $regno,
'requestid' => $requestid,
'signature' => $signature
);
$response = $client->__soapCall('getVixNcdResult', $params);

但是我已经成功地使用curl向服务器发送了一个SOAP请求。这是我的代码。

$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if($result === false) {
$err = 'Curl error: ' . curl_error($ch);
curl_close($ch);
print $err;
} else {
curl_close($ch);
try {
$xml = simplexml_load_string($result);
$xml->registerXPathNamespace('success', 'http://servlet');
$resultAfter = (array) $xml->xpath('//success:getVixNcdReqReturn')[0];
} catch (Exception $fault) {
return response()->json($fault->getMessage());

}
return response()->json($resultAfter);
}

在try块中,我将xml解析为数组。但是,只有当XML响应返回预期的数据时才会发生这种情况。我想得到这个XML的错误字符串的消息。

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:axis2ns15="http://schemas.xmlsoap.org/soap/envelope/">axis2ns15:Client</faultcode>
<faultstring>Authentication Failure</faultstring>
<detail>Invalid Credentials</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

有人能帮我解析XML的错误或找到一种方法来成功地使用SoapClient连接?谢谢你。

我找到了一种方法来获取xml的错误消息。

$xml = simplexml_load_string($result);
$faultstring = (array) $xml->xpath('//faultstring')[0];
$detail = (array) $xml->xpath('//detail')[0];
return response()->json(['faultstring' => $faultstring[0], 'detail' => $detail[0]]);

这将返回:

{"faultstring":"Authentication Failure","detail":"Invalid Credentials"}

这可能不是最好的解决方案,但目前这对我来说是可行的。