在ebay API调用中更改siteid

时间:2013-10-06 02:06:50

标签: php curl opencart

我需要使用openbay中的功能连接eBay电机站点,这是一个opencart扩展。 eBay电机的网站ID是100,但对于我的生活,我不能用这个函数写的方式改变它,我在这里遗漏了什么?

API function call

public function openbay_call($call, array $post = NULL, array $options = array(), $content_type = 'json', $statusOverride = false){

        if(defined("HTTPS_CATALOG")){
            $domain = HTTPS_CATALOG;
        }else{
            $domain = HTTPS_SERVER;
        }

        $data = array(
            'token'             => $this->token, 
            'language'          => $this->config->get('openbay_language'), 
            'secret'            => $this->secret, 
            'server'            => $this->server, 
            'domain'            => $domain, 
            'openbay_version'   => (int)$this->config->get('openbay_version'),
            'data'              => $post, 
            'content_type'      => $content_type
        );

       $defaults = array(
            CURLOPT_POST            => 1,
            CURLOPT_HEADER          => 0,
            CURLOPT_URL             => $this->url.$call,
            CURLOPT_USERAGENT       => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1",
            CURLOPT_FRESH_CONNECT   => 1,
            CURLOPT_RETURNTRANSFER  => 1,
            CURLOPT_FORBID_REUSE    => 1,
            CURLOPT_TIMEOUT         => 0,
            CURLOPT_SSL_VERIFYPEER  => 0,
            CURLOPT_SSL_VERIFYHOST  => 0,
            CURLOPT_POSTFIELDS      => http_build_query($data, '', "&")       
        );

        $ch = curl_init();
        curl_setopt_array($ch, ($options + $defaults));
        if( ! $result = curl_exec($ch)){
            $this->log('openbay_call() - Curl Failed '.curl_error($ch).' '.curl_errno($ch));
        }
        curl_close($ch);

        /* There may be some calls we just dont want to log */
        if(!in_array($call, $this->noLog)){
            $this->log('openbay_call() - Result of : "'.$result.'"');
        }
        /* JSON RESPONSE */
        if($content_type == 'json'){
            $encoding = mb_detect_encoding($result);

            /* some json data may have BOM due to php not handling types correctly */
            if($encoding == 'UTF-8') {
              $result = preg_replace('/[^(\x20-\x7F)]*/','', $result);    
            } 

            $result             = json_decode($result, 1);
            $this->lasterror    = $result['error'];
            $this->lastmsg      = $result['msg'];

            if(!empty($result['data'])){
                return $result['data'];
            }else{
                return false;
            }
        /* XML RESPONSE */
        }elseif($content_type == 'xml'){
            $result             = simplexml_load_string($result);
            $this->lasterror    = $result->error;
            $this->lastmsg      = $result->msg;

            if(!empty($result->data)){
                return $result->data;
            }else{
                return false;
            }
        }
    }else{
        $this->log('openbay_call() - OpenBay not active');
        $this->log('openbay_call() - Data: '.serialize($post));
    }
}

predefined parameters within the class - 反正可能没有帮助。

public function __construct($registry) {
    $this->registry     = $registry;
    $this->token        = $this->config->get('openbaypro_token');
    $this->secret       = $this->config->get('openbaypro_secret');
    $this->logging      = $this->config->get('openbaypro_logging');
    $this->tax      = $this->config->get('tax');
    $this->server       = 1;
    $this->lasterror    = '';
    $this->lastmsg      = '';
}

the function call

$this->data['test_category_features'] = $this->ebay->openbay_call('listing/getCategoryFeatures/', array('id' => 35618));

一切正常但是我如何才能将siteid更改为100,我能解决的唯一方法就是重新编写自己的API调用类,但是客户端正在支付openbay的订阅并且想要使用API通过它们调用,所以我必须使用那里的函数。我试图返回eBay电机类别的功能,所以他可以用他多年来“使用过的部件”的方式列出它们。如果您没有切换到易趣电机网站ID“100”,那么当尝试通过opencart扩展程序向eBay添加产品时,它不会返回所需的类别变化或更少接受类别。 任何建议将不胜感激,真的卡在这里!在此先感谢:)

1 个答案:

答案 0 :(得分:1)

根据此页面:http://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html您需要为每个API调用添加“... X-EBAY-SOA-GLOBAL-ID HTTP标头”,因此请将其添加到curl选项中。