我正在尝试使用他们的 API 在 eBay 上列出项目,但SoapClient
出现问题。
概述:
我像这样初始化SoapClient
:
$this->client = new SOAPClient($this->wsdlURL, array('trace' => 1, 'exceptions' => true, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
然后我打这样的电话:
$responseObj = $this->client->__soapCall($method, array($parameters), null, $header);
$parameters
是这样的:
$parameters = array(
'Version' => 903,
'WarningLevel' => 'High',
'Item' => array(
// ....
'Storefront' => array(
'StoreCategoryID' => $storeCategoryId,
'StoreCategory2ID' => $storeCategoryId
);
// ....
);
);
$storeCategoryId
在哪里8046618015
.
问题所在
eBay说类别ID不正确,因此使用以下方法转储XML:
$this->client->__getLastRequest();
我看到以下内容:
......
<ns1:Storefront>
<ns1:StoreCategoryID>2147483647</ns1:StoreCategoryID>
<ns1:StoreCategory2ID>2147483647</ns1:StoreCategory2ID>
</ns1:Storefront>
....
显然,请求中的商店类别 ID 与我传递SoapClient
不同。
碰巧2147483647
是 PHP 中 INT 的最大大小(或任何有符号的 32 位数字,因为 2^32/2 = 2147483647),所以看起来SoapClient
正在将类别 ID 解析为 INT,并且由于"数字"大于 INT 的最大大小,这就是它被转换为的内容。
这是我的理论。
在将 $storeCategoryId
变量分配给数组时,我尝试在变量周围添加引号,但这似乎没有区别。
导致此问题的原因是什么,我该如何解决?
我不
明白为什么这会起作用,但是经过更多的搜索,我发现在变量之前添加(float)
可以防止SoapClient
搞砸它们。