• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
获取订单接口示例

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;
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP异常处理和错误处理发布时间:2022-07-10
下一篇:
Weevely-0.7(php菜刀)工具使用详解发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap