我正在使用eBay的非官方PHP SDK https://github.com/davidtsadler/ebay-sdk-php。ebay-sdk-php通知处理
这对社区是一个很大的贡献,虽然有限的文档我已经设法做大部分事情。
我一直在绕圈通知,特别是'FixedPriceTransaction'通知。我设法订阅通知并发送请求以确保订阅已正确创建。
不幸的是,当eBay发送通知来处理通知时,我无法确定使用哪种方法。任何人都可以摆脱光线吗?
我正在使用eBay的非官方PHP SDK https://github.com/davidtsadler/ebay-sdk-php。ebay-sdk-php通知处理
这对社区是一个很大的贡献,虽然有限的文档我已经设法做大部分事情。
我一直在绕圈通知,特别是'FixedPriceTransaction'通知。我设法订阅通知并发送请求以确保订阅已正确创建。
不幸的是,当eBay发送通知来处理通知时,我无法确定使用哪种方法。任何人都可以摆脱光线吗?
全面披露:我是eBay SDK
eBay的通知服务的开发者是不是由该SDK,因为它是说我不熟悉的API的一个区域正式支持,但我会尽可能地尽力回答你的问题。
据我了解,eBay的平台通知有两个部分。
第一部分应该可以使用SDK,因为它只需要向SetNotificationPreferences操作发送请求。这听起来像你已经制定了如何做到这一点,但我已经包括了下面的例子,只是在它有帮助的机会。我没有尝试下面的代码,但它应该给你一些想法做什么。
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
/**
* Fill out $request according to your project needs.
*/
$request = new Types\SetNotificationPreferencesRequest();
$request->UserDeliveryPreferenceArray = new Types\NotificationEnableArrayType();
$notification = new Types\NotificationEnableType();
$notification->EventEnable = 'Enable';
$notification->EventType = 'FixedPriceTransaction';
$request->UserDeliveryPreferenceArray->NotificationEnable[] = $notification;
/**
* Handle response according to your project needs.
*/
$response = $service->SetNotificationPreferences($request);
if ($response->Ack !== 'Failure') {
}
第二部分可能与SDK,但是这是我没有任何经验的一个领域。据我了解,eBay将发送POST HTTP请求到您控制的URL。您有责任处理请求中包含的数据,并使用标准HTTP状态200 OK进行响应。我假定POST数据包含一个可以被PHP脚本作为字符串访问的SOAP主体。 SOAP体内应该是通知的XML。只要您有办法获取eBay发送的实际XML字符串,您可以使用XmlParser类。该类是SDK用来将来自API的XML响应转换回PHP对象的内容。这意味着你也可以做同样的事情。
<?php
require __DIR__.'/vendor/autoload.php';
use DTS\eBaySDK\Parser;
/**
* This string is not a complete example of what eBay could send.
* A full example can be found at http://developer.ebay.com/Devzone/guides/ebayfeatures/Notifications/Notif-EndOfAuction.html#Example
* It assumes that eBay sends a POST request to your sever and
* that you can obtain the data as a string, E.g via $_POST[] or some other way.
*/
$soap = <<<EOF_S
<?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:Header>
<ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ns="urn:ebay:apis:eBLBaseComponents" xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
<ebl:NotificationSignature xmlns:ebl="urn:ebay:apis:eBLBaseComponents">1w5Fdyr9V9ofTq67etR0lA==</ebl:NotificationSignature>
</ebl:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<GetItemTransactionsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Item>
<ItemID>123456789</ItemID>
</Item>
</GetItemTransactionsResponse>
</soapenv:Body>
</soapenv:Envelope>
EOF_S;
/**
* Very simple method of extracting the XML from the string.
*/
$matches = array();
preg_match('#<soapenv:Body>(.*?)</soapenv:Body>#s', $soap, $matches);
$xml = $matches[1];
/**
* The parser requires the full namespace and classname of the object that will be built from the XML.
*/
$parser = new Parser\XmlParser('DTS\eBaySDK\Trading\Types\GetItemTransactionsResponseType');
/**
* Pass the XML and the parser will return a PHP object.
*/
$response = $parser->parse($xml);
/**
* Use the object.
*/
echo $response->Item->ItemID;
非常好!第一部分我已经有类似的东西了,但第二部分是非常有用的。非常感激! – jdawg
谢谢。你可以让我知道,如果有方法知道ebay是否发送通知到网址。我添加日志消息,但没有得到调用。电子邮件devliery url作品 – coder771
我正要提交和发布在github上,但这完全回答了我的问题! – nikksan