gpt4 book ai didi

java - 如何在 php 中使用 SOAP 进行 wsdl 请求响应?

转载 作者:太空宇宙 更新时间:2023-11-04 14:05:53 24 4
gpt4 key购买 nike

所以我现在真的陷入困境了。我是 SOAP 和 WSDL 的新手。我了解一些 Oop Java 和一些 Oop Php。我尝试调用 Java WSDL API 中的函数。不需要任何参数的方法可以正常工作并返回值。但是当我尝试将参数发送到需要参数的方法时,它只会抛出异常。我使用的是 php > 5.4。这是我第三天试图解决这个问题,但没有运气。API 的提供者没有任何技术人员为我提供帮助,而且我被他们的系统的无穷无尽的文档所困扰。

我需要在系统中获取一个人过去一周的所有签到,根据我的预感,我选择了这个 API 端点 (BookingAPI)

$allEndpoints = [AccessAPI, AccountReceivableAPI, BookingAPI, ChildCareAPI, CompanyAPI, CrmAPI, ExtractAPI, GiftCardAPI, PersonAPI, PrivilegeAPI, ProductAPI, QuestionnaireAPI, ResourceBookingAPI, SelfServiceAPI, StaffBookingAPI, StaffBookingAPI, SubscriptionAPI, TestAPI]

但是为了简化这个问题,我选择了一个参数较少的函数。

一些代码:

echo "<pre style=\"display:block;word-wrap: break-word;\">";

$client = new SoapClient($wsdl, array(
"login" => $login,
"password" => $password,
"trace" => 1,
"exceptions" => 0)
);


// TRY DIFFERENT OBJECTIFICATIONS HERE; SEE BELOW


print "Client : \n";
var_dump($client);
print "<br>Functions : \n";
// var_dump($client->__getFunctions());
print "<br>Types : \n";
// var_dump($client->__getTypes());
// print "<br />\n Request : ".htmlspecialchars($client->__getLastRequest());
// print "<br />\n Response: ".htmlspecialchars(utf8_decode($client->__getLastResponse()));

print "<br>Values : \n";
print_r($value);

根据一些图和一些SO线程,我尝试了以下操作:

当我尝试时:

$myClass->token = new \stdClass;
$myClass->personId = '6204';
$value = $client->getDetails($myClass);

我得到:

Warning:  Creating default object from empty value in /path/to/dist/index.php on line 143
Fatal error: SOAP-ERROR: Encoding: object has no 'center' property in /path/to/dist/index.php on line 145

如果我尝试:

$myParam = new SoapParam("6204", "PersonKey");
$value = $client->getDetails($myParam);

我得到:

SoapFault Object
(
[message:protected] => dk.procard.eclub.api.v4.exceptions.APIException: dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /path/to/dist/index.php
[line:protected] => 154
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /path/to/dist/index.php
[line] => 154
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => getDetails
[1] => Array
(
[0] => SoapParam Object
(
[param_name] => PersonKey
[param_data] => 6204
)
)
)
)
[1] => Array
(
[file] => /path/to/dist/index.php
[line] => 154
[function] => getDetails
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => SoapParam Object
(
[param_name] => PersonKey
[param_data] => 6204
)
)
)
)
[previous:Exception:private] =>
[faultstring] => dk.procard.eclub.api.v4.exceptions.APIException: dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
[faultcode] => env:Server
[detail] => stdClass Object
(
[APIException] => stdClass Object
(
[errorCode] => ILLEGAL_ARGUMENT
[errorMessage] => dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
[message] => dk.procard.eclub.api.v4.exceptions.APIException: dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
)
)
)

来自文档:

Person getDetails(PersonKey personId) throws APIException

Gets the details for a person. 

Parameters:

personId - Required. The id of the person for which the details should be returned

Returns:

the details of the person

Throws: APIException - Will only throw

general error codes.

See Also: blabla

如何提出请求并获得所需的响应?非常感谢所有帮助和指示,谢谢!

[编辑]

后续问题:

如何在请求中发送“id”参数?findPersons(arg0->属性->id);

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v4="path/to/api?wsdl">
<soapenv:Header/>
<soapenv:Body>
<v4:findPersons>
<arg0>
<!--Zero or more repetitions:-->
<attributes>
<!--Optional:-->
<id>?</id>
<!--Optional:-->
<value>?</value>
</attributes>
<!--Optional:-->
<birthday>?</birthday>
<!--Optional:-->
<center>?</center>
<!--Optional:-->
<country>?</country>
<!--Optional:-->
<name>?</name>
<!--Optional:-->
<personType>?</personType>
<!--Optional:-->
<phoneNumber>?</phoneNumber>
<!--Optional:-->
<socialSecurityNumber>?</socialSecurityNumber>
</arg0>
</v4:findPersons>
</soapenv:Body>
</soapenv:Envelope>

最佳答案

第一种方法:

$myClass = new \stdClass;
$myClass->personId = 6204;
$value = $client->getDetails(array($myParam));

第二种方法:

$myParam = new SoapVar("6204", XSD_STRING); // it should be the same type of personId at wsdl
$value = $client->getDetails(array('personId' => $myParam));

关于java - 如何在 php 中使用 SOAP 进行 wsdl 请求响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28876435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com