2015-01-18 4 views
-1

Я хочу отправить сообщение клиентам eBay (через eBay messenger) после того, как они приобрели товар. Я продаю цифровые коды для xbox one и создаю автоматическую систему доставки. Я видел это раньше, поэтому знаю, что это возможно.eBay API PHP - Отправить сообщение клиентам

Я изучал его, и я столкнулся с AddMemberMessageAAQToPartner, но я не знаю, как его использовать в PHP. Единственными поддерживаемыми API на сайте являются Java и C#, по какой-то причине eBay не использует PHP.

Я уже сделал PayPal IPN, поэтому знаю, когда клиент покупает продукт, я могу использовать его для отправки электронной почты, но я бы скорее послал прямое сообщение eBay.

+0

Если API eBay является стандартом, например REST или SOAP, вы можете назвать его на любом языке. – halfer

ответ

1

Я создал SDK, который позволяет людям использовать API eBay в своих проектах PHP. Если вы знакомы с Composer он может быть установлен с,

php composer.phar require dts/ebay-sdk-trading 

В приведенном ниже примере показано, как SDK может быть использован для вызова AddMemberMessageAAQToPartner. Более подробная информация о SDK также содержится в файле available.

<?php 
/** 
* Include the SDK by using the autoloader from Composer. 
*/ 
require __DIR__.'/vendor/autoload.php'; 

/** 
* The namespaces provided by the SDK. 
*/ 
use \DTS\eBaySDK\Constants; 
use \DTS\eBaySDK\Trading\Services; 
use \DTS\eBaySDK\Trading\Enums; 
use \DTS\eBaySDK\Trading\Types; 

/** 
* Create the service object with the following configuration. 
* 
* authToken The token that authenticates your request on behalf of a user. 
*   For this example it will be for the seller. 
*   See the eBay guide for more information on tokens. 
*   http://developer.ebay.com/devzone/guides/ebayfeatures/Basics/Tokens.html 
* 
* apiVersion The API version that your application supports. 
*   Since this can change see the release notes to obtain the current version. 
*   http://developer.ebay.com/DevZone/XML/docs/ReleaseNotes.html 
* 
* siteId  The numerical id for the site that you want to send the request to. 
*   For this example it will be the site that the seller is registered on. 
*   A complete list of IDs can be found at, 
*   http://developer.ebay.com/devzone/finding/Concepts/SiteIDToGlobalID.html 
* 
* sandbox Optional configuration. Set to true to use the sandbox API. 
*   If this option is not included or is set to false the production API will be used. 
* 
* For more configuration options see http://devbay.net/sdk/guides/trading/ 
* 
*/ 
$service = new Services\TradingService(array(
    'authToken' => 'AUTH TOKEN', 
    'apiVersion' => '903', 
    'siteId' => Constants\SiteIds::US, 
    'sandbox' => true 
)); 

/** 
* Create the request object. 
* 
* Note how the properties on the object match those found in the documentation 
* for AddMemberMessageAAQToPartner. 
* 
* http://developer.ebay.com/DevZone/xml/docs/Reference/ebay/AddMemberMessageAAQToPartner.html 
*/ 
$request = new Types\AddMemberMessageAAQToPartnerRequestType(); 
/** 
* The id of the listing that the message is regarding. 
*/ 
$request->ItemID = 'ITEM ID'; 

$request->MemberMessage = new Types\MemberMessageType(); 
$request->MemberMessage->QuestionType = Enums\QuestionTypeCodeType::C_GENERAL; 
/** 
* The eBay ID of the buyer that the message is for. 
* Note that the API allows you to send the same message to multiple buyers. 
* Multiple request values are handled as arrays by the SDK hence using [] when specifying the buyer. 
*/ 
$request->MemberMessage->RecipientID[] = 'EBAY ID'; 
$request->MemberMessage->EmailCopyToSender = true; 
$request->MemberMessage->Subject = 'A test message'; 
$request->MemberMessage->Body = 'This is a test message'; 

/** 
* Send the request. 
*/ 
$response = $service->addMemberMessageAAQtoPartner($request); 

/** 
* Display any errors or warnings that the API may have returned. 
*/ 
if (isset($response->Errors)) { 
    foreach ($response->Errors as $error) { 
     printf("%s: %s\n%s\n\n", 
      $error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning', 
      $error->ShortMessage, 
      $error->LongMessage 
     ); 
    } 
} 

if ($response->Ack !== 'Failure') { 
    print("Message sent\n"); 
} 
+0

Как бы вы поделили выделение предмета как отправленного ? – Jake

-2

Вы можете взглянуть на eBay's documentation for AddMemberMessageAAAQToPartner, чтобы ознакомиться с образцом запроса XML и любыми параметрами.

Все, что вам нужно сделать, это генерировать XML-строку, а затем POST ее в конечную точку API eBay, используя cURL. Есть некоторые заголовки, которые вам нужно передать для учетных данных API, но это все охватывает общую документацию eBay «Making a Call».

+2

Я удалил комментарии здесь. Если вы хотите продолжить обсуждение этого вопроса, я рекомендую сделать это в Meta: http://meta.stackoverflow.com/questions/329915/are-consulting-solicitations-acceptable –

Смежные вопросы