关于ebay平台接口(php)对接示例

Posted zonehoo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于ebay平台接口(php)对接示例相关的知识,希望对你有一定的参考价值。

获取订单接口示例

public function importEbayOrder(){
set_time_limit(0);
if(empty( $this->_ShopApiEbay->token )){
self::fail(self::CODE_FAILURE, ‘shop:‘ . Shop::findOne($this->_ShopApiEbay->id)->name . ‘ empty token‘);
}else {
$ps = 100;
$cp = 0;
$total_entries = 1;
$mod_time_from = date(‘c‘, strtotime(‘-24 hours‘));
$mod_time_to = date(‘c‘, time());
$header = array(
‘Content-Type: text/xml‘,
‘X-EBAY-API-COMPATIBILITY-LEVEL:‘ . self::X_EBAY_API_COMPATIBILITY_LEVEL,
‘X-EBAY-API-DEV-NAME:‘. self::X_EBAY_API_DEV_NAME,
‘X-EBAY-API-APP-NAME:‘ . self::X_EBAY_API_APP_NAME,
‘X-EBAY-API-CERT-NAME‘ . self::X_EBAY_API_CERT_NAME,
‘X-EBAY-API-SITEID:‘ . 0,
‘X-EBAY-API-CALL-NAME:GetOrders‘,
‘X-EBAY-API-REQUEST-ENCODING:XML‘
);
$message = [];
while ($ps*$cp < $total_entries)
{
sleep(60);
$cp ++;
$xml = ‘<?xml version="1.0" encoding="utf-8"?>‘;
$xml .= ‘<GetOrdersRequest xmlns="urn:ebay:apis:eBLBaseComponents">‘;
$xml .= ‘<RequesterCredentials>‘;
$xml .= ‘<eBayAuthToken>‘ . $this->_ShopApiEbay->token . ‘</eBayAuthToken>‘;
$xml .= ‘</RequesterCredentials>‘;
$xml .= ‘<ModTimeFrom>‘ . $mod_time_from . ‘</ModTimeFrom>‘;
$xml .= ‘<ModTimeTo>‘ . $mod_time_to . ‘</ModTimeTo>‘;
$xml .= ‘<DetailLevel>ReturnAll</DetailLevel>‘;
$xml .= ‘<IncludeFinalValueFee>True</IncludeFinalValueFee>‘;
$xml .= ‘<OrderStatus>All</OrderStatus>‘;
$xml .= ‘<Pagination>‘;
$xml .= ‘<EntriesPerPage>‘ . $ps . ‘</EntriesPerPage>‘;
$xml .= ‘<PageNumber>‘ . $cp . ‘</PageNumber>‘;
$xml .= ‘</Pagination>‘;
$xml .= ‘</GetOrdersRequest>‘;
$response = $this->_curl($header, $xml);
if( $response->isSuccess ){
OriginDataEbayOrder::importOrder($response->data->OrderArray, $this->_ShopApiEbay);
if(isset($response->data->PaginationResult->TotalNumberOfEntries)){
$total_entries = (int)$response->data->PaginationResult->TotalNumberOfEntries;
}
}else{
$message[] = Shop::findOne($this->_ShopApiEbay->id)->name . ‘:getOrder ‘ . $response->message ;
}
}
if( empty($message) ){
return self::success(self::CODE_SUCCESS, self::CODE_SUCCESS);
}else{
return self::fail(self::CODE_FAILURE, join(" ", $message));
}
}
}

curl 模拟请求
public function _curl($header, $xml){
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, self::EBAY_WS_URI);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
$response = $this->transformXmlToObject($response);
if( $response->Ack == ‘Success‘ ){
return self::success($response, self::CODE_SUCCESS);
}else{
return self::fail(self::CODE_FAILURE, (string)$response->Errors->LongMessage);
}
}

将请求的xml对象转化为对象
    public function transformXmlToObject($xml){
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml, ‘SimpleXMLElement‘, LIBXML_NOCDATA);
// echo ‘<pre>‘;var_dump($xmlstring);die;
// $val = json_decode(json_encode($xmlstring),true);//转数组
return $xmlstring;
}






















































































以上是关于关于ebay平台接口(php)对接示例的主要内容,如果未能解决你的问题,请参考以下文章

对接第三方平台JAVA接口问题推送和解决

php 实现快递鸟API接口 快递查询对接签名验证

关于第三方Api接口对接安全性的总结

PHP对接微信扫码登录

php与国付宝对接过程吐槽

JAVA示例-1分钟对接35家主流快递公司的电子面单