關於ebay平臺接口(php)對接示例
阿新 • • 發佈:2018-08-04
sta nts all enum pap lose head disable ring
獲取訂單接口示例
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)對接示例