码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2018-08-04 21:03:58      阅读:397      评论:0      收藏:0      [点我收藏+]

标签:示例   sage   模拟   orm   ssl   erro   fail   ons   cer   

获取订单接口示例

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("\n", $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)对接示例

标签:示例   sage   模拟   orm   ssl   erro   fail   ons   cer   

原文地址:https://www.cnblogs.com/zonehoo/p/9419843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!