当前位置: 首页 > 工具软件 > eBay jsonpipe > 使用案例 >

ebay api 对接

李鹏
2023-12-01

沙盒测试

对于以下参数的获取

1

注册账户参看:http://blog.csdn.net/terry_water/article/details/18597753

2

登录账户后,访问:https://developer.ebay.com/DevZone/build-test/test-tool/

进入开发测试页面

这个页面会给与下面的所有参数


3

获取数据文件,使用的是xml方式的获取方式

<?php
require "./EbaySession.php";
class Erp_Ebayproduct_Model_Productactivelistsynch
{
    
    private $devID;   
    private $appID;
    private $certID;
    private $serverUrl;
    private $userToken;
    private $siteID;
    private $verb;
    private $CreateTimeFrom;
    private $CreateTimeTo;
    private $compatabilityLevel;

    public function productactivelist()
    {
        self::GetProductActiveList("COMEBUY");
        //self::GetProductActiveList("ABBYDRESS");
    }
//web - ebay account
    public function GetProductActiveList($web)
    {
        //http header --> X-EBAY-API-COMPATIBILITY-LEVEL
        $this->_compatabilityLevel = 857;
        //http header --> X-EBAY-API-SITEID
        $this->_siteID = 0;
        //http header --> X-EBAY-API-CALL-NAME
        $this->_verb = 'GetMyMessages';  //函数名ebay
        //$keys_class=new Erp_Ebaydata_Model_Keys();
        //$keys_array=$keys_class->getKeys($web); //正式环境
        //http header --> X-EBAY-API-DEV-NAME
        $this->_devID= "7c0d5f7b-dc39-4afd-868b-f508358ff1b4";
        //http header --> X-EBAY-API-APP-NAME
        $this->_appID= "comebuyg-bf1b-4965-b789-bdda40e9ca3c";
        //http header --> X-EBAY-API-CERT-NAME
        $this->_certID= "7a89c28b-ee8a-48ce-bb0b-1cf203349f4e";
        // Web Service URI (Endpoint)
        $this->_serverUrl= "https://api.sandbox.ebay.com/ws/api.dll";
        // eBayAuthToken
        $this->_userToken= "AgAAAA**AQAAAA**aAAAAA**TeLcUg**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4GhC5eFogWdj6x9nY+seQ**r38CAA**AAMAAA**wP64w38E1oYCwOY3hBq0VUpyHhCs9SXZc7rE7I3T7O4Fbk88UhHEPInYtTME8mKCrJjnRLEmxr7OX+iTlPEvICgTCAd6u8aHuvcVQsPlsazL2nH1cPpFefYnRokhvKE/2odkCG87clkjplNYgyZ4fjWFVNzpqe+zWcE+gsUy8Sk7ciRMB4/vluF1AzxlpxdAFzhKOdV4AFCi92XRSgaa7aLX3GboCIwChAqkatVkJRlCD9yXrXzGQmqb8Valrp1j4U/V2Ne27Ng5WABu+eyk3xtV/8hP/cLGmwsg3ODtCVejiXi0VQ72Fq0IijBKHkaS4wzrKNVkasMgPIB1Iv2x87xvzjt9HNIVzM0gGolDumBxV1uIdThPtrcjNUB9aNT3OOtrUHPltEKt7HaXlEOw/CKaXLkgxAlkMWejFbkgQn0mAj8V7t4+P61XyikRtRuRFiW8wksaQ9t/BL5ye6yNNlxCCHVJcCAZkkHymLv+Y/hZ1VuJIeGwacVjOAntt5h8kgNLiUW16/RCye3r7zrfNx372w6dnCceizUTtHHd26wJfqWP1IBWd0P2pnw/NaT30XCWxzA4XqTsuGbLsP9iONttk4jvAmIb6cNQ90NW3bFC8XfAEgYWYcxd5A/2Oi9Cd/nPNVtPBCa1LE5AwXOxeBJFsIyL5mh93nb+FPAt5ZtFvNiq5bFT2WLBqOgkUs6do6ygM5OjgxDSRihCF/h1oJl28uD+C64RN2tx5KsV3B014B7P25h2g9X+ugRtq6M0";
        //curl  --> CURLOPT_POSTFIELDS
        $requestXmlBody = '<?xml version="1.0" encoding="utf-8"?>
                            <GetMyMessagesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
                            <RequesterCredentials>
                            <eBayAuthToken>$this->_userToken</eBayAuthToken>
                            </RequesterCredentials>
                            <WarningLevel>High</WarningLevel>
                              <DetailLevel>ReturnHeaders</DetailLevel>
                            </GetMyMessagesRequest>';

        
        $session = new Erp_Ebaydata_Model_EbaySession($this->_userToken, $this->_devID, $this->_appID, $this->_certID, $this->_serverUrl, $this->_compatabilityLevel, $this->_siteID, $this->_verb);
        $responseXml = $session->sendHttpRequest($requestXmlBody);
        if (stristr($responseXml, 'HTTP 404') || $responseXml == '')die('<P>Error sending request');
        $responseDoc = new DomDocument();
        $responseDoc->loadXML($responseXml);
        
        $errors = $responseDoc->getElementsByTagName('Errors');
        $response = simplexml_import_dom($responseDoc);
       

 echo $response->Version;
        echo $response->Build;

下面是其他的例子,可能报错。
        //在售商品
        $product_sum=$response->ActiveList->PaginationResult->TotalNumberOfEntries;
        echo "在售商品总数:".$product_sum."</br>";
        //同步在售商品
        $products=$response->ActiveList->ItemArray->Item;
      
        foreach ($products as $product)
        {
            $product_sku=$product->SKU;
            $product_name=$product->Title;
            $itemid=$product->ItemID;
            $ebay_account=$web;
            $gallery_url=$product->PictureDetails->GalleryURL;
            $viewitem_url=$product->ListingDetails->ViewItemURL;
            $viewitemurlfor_naturalsearch=$product->ListingDetails->ViewItemURLForNaturalSearch;
            
            $select=Mage::getModel('erpebayproduct/erpebayproduct')->getCollection();
            $select->addFieldToFilter('ebay_account',array('eq'=>$web));
            $select->addFieldToFilter('product_sku',array('eq'=>$product_sku));
            $select_data=$select->load()->getData();
            $select_data_count=count($select_data);
            if($select_data_count==0)
            {
                $insert=Mage::getModel('erpebayproduct/erpebayproduct');
                $insert->setProduct_sku($product_sku);
                $insert->setProduct_name($product_name);
                $insert->setItemid($itemid);
                $insert->setEbay_account($web);
                $insert->setGallery_url($gallery_url);
                
                $insert->setViewitem_url($viewitem_url);
                $insert->setViewitemurlfor_naturalsearch($viewitemurlfor_naturalsearch);
                
                $insert->save();
            }
        }
        
        echo $web."同步完成!!</br>";
    }    
}

$dd = new Erp_Ebayproduct_Model_Productactivelistsynch();
$dd->productactivelist();
?>

2

需要包含进去的文件:

<?php
/*  ?2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 -  http://opensource.org/licenses/cddl1.php */

class Erp_Ebaydata_Model_EbaySession
{
    private $requestToken;
    private $devID;
    private $appID;
    private $certID;
    private $serverUrl;
    private $compatLevel;
    private $siteID;
    private $verb;
    
    /**    __construct
        Constructor to make a new instance of eBaySession with the details needed to make a call
        Input:    $userRequestToken - the authentication token fir the user making the call
                $developerID - Developer key obtained when registered at http://developer.ebay.com
                $applicationID - Application key obtained when registered at http://developer.ebay.com
                $certificateID - Certificate key obtained when registered at http://developer.ebay.com
                $useTestServer - Boolean, if true then Sandbox server is used, otherwise production server is used
                $compatabilityLevel - API version this is compatable with
                $siteToUseID - the Id of the eBay site to associate the call iwht (0 = US, 2 = Canada, 3 = UK, ...)
                $callName  - The name of the call being made (e.g. 'GeteBayOfficialTime')
        Output:    Response string returned by the server
    */
    public function __construct($userRequestToken, $developerID, $applicationID, $certificateID, $serverUrl,
                                $compatabilityLevel, $siteToUseID, $callName)
    {
        $this->requestToken = $userRequestToken;
        $this->devID = $developerID;
        $this->appID = $applicationID;
        $this->certID = $certificateID;
        $this->compatLevel = $compatabilityLevel;
        $this->siteID = $siteToUseID;
        $this->verb = $callName;
        $this->serverUrl = $serverUrl;    
    }
    
    
    /**    sendHttpRequest
        Sends a HTTP request to the server for this session
        Input:    $requestBody
        Output:    The HTTP Response as a String
    */
    public function sendHttpRequest($requestBody)
    {
        //build eBay headers using variables passed via constructor
        $headers = $this->buildEbayHeaders();
        
        //initialise a CURL session
        $connection = curl_init();
        //set the server we are using (could be Sandbox or Production server)
        curl_setopt($connection, CURLOPT_URL, $this->serverUrl);
        
        //stop CURL from verifying the peer's certificate
        curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
        
        //set the headers using the array of headers
        curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
        
        //set method as POST
        curl_setopt($connection, CURLOPT_POST, 1);
        
        //set the XML body of the request
        curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);
        
        //set it to return the transfer as a string from curl_exec
        curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
        
        //Send the Request
        $response = curl_exec($connection);
        
        //close the connection
        curl_close($connection);
        
        //return the response
        return $response;
    }
    
    
    
    /**    buildEbayHeaders
        Generates an array of string to be used as the headers for the HTTP request to eBay
        Output:    String Array of Headers applicable for this call
    */
    private function buildEbayHeaders()
    {
        $headers = array (
            //Regulates versioning of the XML interface for the API
            'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $this->compatLevel,
            
            //set the keys
            'X-EBAY-API-DEV-NAME: ' . $this->devID,
            'X-EBAY-API-APP-NAME: ' . $this->appID,
            'X-EBAY-API-CERT-NAME: ' . $this->certID,
            
            //the name of the call we are requesting
            'X-EBAY-API-CALL-NAME: ' . $this->verb,            
            
            //SiteID must also be set in the Request's XML
            //SiteID = 0  (US) - UK = 3, Canada = 2, Australia = 15, ....
            //SiteID Indicates the eBay site to associate the call with
            'X-EBAY-API-SITEID: ' . $this->siteID,
        );
        
        return $headers;
    }
}
?>

 类似资料: