我正在尝试连接到ebay交易API并使用PHP的SoapClient类发出基本请求,但遇到了麻烦。我已经花了数小时来搜索和摆弄示例,但是我什么也做不了。因此,我编写了以下准系统代码,并试图使其正常工作:

$token  = [token here];

$client = new SOAPClient('http://developer.ebay.com/webservices/latest/eBaySvc.wsdl', array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$header = new SoapHeader('urn:ebay:apis:eBLBaseComponents', 'RequesterCredentials', new SoapVar(array('ebayAuthToken' => $token), SOAP_ENC_OBJECT), false);

$client->__setSoapHeaders(array($header));

$method = 'GeteBayOfficialTime';

$parameters = array(

);

try {
    $responseObj = $client->__soapCall($method, array($parameters));
}
catch (Exception $e)
{
    echo 'Exception caught. Here are the xml request & response:<br><br>';
    echo '$client->__getLastRequest():<br><pre><xmp>' . $client->__getLastRequest() . '</xmp></pre>';
    echo '$client->__getLastResponse():<br><pre><xmp>' . $client->__getLastResponse() . '</xmp></pre><br>';

    echo '<p>Exception trying to call ' . $method . '</p>';
    echo '$e->getMessage()';
    echo '<pre>' . $e->getMessage() . '</pre>';
}


输出为:

Exception caught. Here are the xml request & response:

$client->__getLastRequest():

<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:ebay:apis:eBLBaseComponents" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Header><xsd:RequesterCredentials><ebayAuthToken>[token was here]</ebayAuthToken></xsd:RequesterCredentials></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GeteBayOfficialTimeRequest/></SOAP-ENV:Body></SOAP-ENV:Envelope>

$client->__getLastResponse():

<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <soapenv:Fault> <faultcode>soapenv:Server.userException</faultcode> <faultstring>com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled.</faultstring> <detail/> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope>


Exception trying to call GeteBayOfficialTime
$e->getMessage()

com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled.


谁能帮我解决这个问题?部分原因可能是我不知道SoapHeader函数的第一个参数(“命名空间”)应该包含什么内容。

最佳答案

经过数小时的黑客研究,并独自尝试了新的东西,我终于能够使它工作。我将解决方案发布在这里,以防它对其他人有帮助:

$token    = '';
$appId    = '';
$wsdl_url = 'ebaysvc.wsdl.xml'; // downloaded from http://developer.ebay.com/webservices/latest/eBaySvc.wsdl

$apiCall = 'GetUser';

$client = new SOAPClient($wsdl_url, array('trace' => 1, 'exceptions' => true, 'location' => 'https://api.sandbox.ebay.com/wsapi?callname=' . $apiCall . '&appid=' . $appId . '&siteid=0&version=821&routing=new'));

$requesterCredentials = new stdClass();
$requesterCredentials->eBayAuthToken = $token;

$header = new SoapHeader('urn:ebay:apis:eBLBaseComponents', 'RequesterCredentials', $requesterCredentials);

// the API call parameters
$params = array(
    'Version' => 821,
    'DetailLevel' => 'ReturnSummary',
    'UserID' => ''
);

$responseObj = $client->__soapCall($apiCall, array($params), null, $header);  // make the API call


$token$appIdUserID用适当的值填充的地方。

一些注意事项:


因为异常设置为true,所以SoapClient构造函数调用和所有soapCall都应在try / catch块内
siteid参数设置为0,表示这是针对美国eBay网站的
位置URL应该从api.sandbox.ebay.com更改为api.ebay.com以使用生产环境而不是沙箱
我决定下载WSDL文件,而不是远程使用它,因为它很大(大约5MB),并且大大降低了请求速度


我不知道为什么这样的简单示例在任何地方都无法使用,但是我确实希望那是我试图弄清楚这一点的时候!

关于php - 通过SoapClient连接到eBay Trading API会引发“未正确配置或找不到Web服务eBayAPI并被禁用”异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16502207/

10-12 06:20