dongpan9760 2015-01-18 13:55
浏览 137
已采纳

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.

  • 写回答

2条回答 默认 最新

  • dsf5632 2015-01-20 22: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
    ");
    }
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 pycharm倒入虚拟环境的时候,显示这个,但是我的虚拟环境已经创建了
  • ¥15 FPGA芯片60进制计数器
  • ¥15 前端js怎么实现word的.doc后缀文件在线预览
  • ¥20 macmin m 4连接iPad
  • ¥15 DBIF_REPO_SQL_ERROR
  • ¥15 根据历年月数据,用Stata预测未来六个月汇率
  • ¥15 DevEco studio开发工具 真机联调找不到手机设备
  • ¥15 请教前后端分离的问题
  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部