php - eBay API PHP - 向客户发送消息

标签 php paypal ebay-api

我想在 eBay 客户购买商品后向他们发送消息(通过 eBay Messenger)。我正在销售 xbox one 的数字代码并制作自动送货系统。我以前见过这种做法,所以我知道这是可能的。

我一直在研究它并且遇到了 AddMemberMessageAAQToPartner 但我不知道如何在 PHP 中使用它。网站上唯一支持的 API 是 Java 和 C#,出于某种原因 eBay 不使用 PHP。

我已经创建了 PayPal IPN,所以我知道当客户购买产品时,我可以使用它来发送电子邮件,但我更愿意直接发送 eBay 消息。

最佳答案

我创建了一个 SDK使人们能够在他们的 PHP 项目中使用 eBay API。如果您熟悉 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");
}

关于php - eBay API PHP - 向客户发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28015244/

相关文章:

php - 在一个 SQL 查询中倒数 parent ?

php - 在 PHP 中使用函数 vs include as "subroutine"

PayPal ipn 通知请求未发送

asp.net - 如何通过 eBay API 获取 PayPal TransactionID

php - 值得从头开始制作 CMS 吗?

php - div定位的概率

c# - 使用 Paypal API/SDK,我将如何检查某个订阅 ID? C#

php - 如何解决 Paypal 保险库信用卡扣费失败的问题

ruby-on-rails - 在 Rails 中获取 eBay 时间

使用 Curl HTTP Post 到 Ebay 交易 API