我正在使用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