dongpan9760
2015-01-18 21:55
浏览 102
已采纳

eBay API PHP - 向客户发送消息

I want to send a message to eBay customers (via eBay messenger) after they have purchased an item. I am selling digital codes for xbox one and making an auto delivery system. I've seen this done before so I know it's possible.

I've been looking into it and I've came across AddMemberMessageAAQToPartner but I don't know how to use this in PHP. The only supported API's on the website are Java and C#, for some reason eBay doesn't use PHP.

I have already made PayPal IPN so I know when a customer buys a product, I can use this to send an email but I'd rather send a direct eBay message.

图片转代码服务由CSDN问答提供 功能建议

我想在购买物品后向eBay客户(通过eBay信使)发送信息。 我正在销售xbox one的数字代码并制作自动发送系统。 我之前已经看过这个,所以我知道这是可能的。

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

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsf5632 2015-01-21 06:59
    已采纳

    I have created a SDK that enables people to use the eBay API in their PHP projects. If you are familiar with Composer it can be installed with,

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

    The example below shows how the SDK can be used to call AddMemberMessageAAQToPartner. More information about the SDK is also 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
    %s
    
    ",
                $error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
                $error->ShortMessage,
                $error->LongMessage
            );
        }
    }
    
    if ($response->Ack !== 'Failure') {
      print("Message sent
    ");
    }
    
    点赞 打赏 评论
  • du8794 2015-01-19 06:17

    You can take a look at eBay's documentation for AddMemberMessageAAAQToPartner to get a look at a sample of the XML request and whatever parameters are available.

    All you need to do is generate an XML string and then POST it to eBay's API endpoint using cURL. There are some headers that you'll need to pass for API credentials, but that's all covered eBay's general "Making a Call" documentation.

    点赞 打赏 评论

相关推荐 更多相似问题