jq 分頁對接介面_Mercadolibre 美客多平臺 API介面 相關
阿新 • • 發佈:2021-02-18
技術標籤:jq 分頁對接介面
官方介面地址
API Docsglobal-selling.mercadolibre.comgithub SDK 及 示例程式碼
mercadolibre/php-sdkgithub.com下面是示例個人示例程式碼
token重新整理及授權
function token($row){ $user_id = $row['user_id']; $client_id = $row['client_id']; $client_secret = $row['client_secret']; $refresh_token = $row['refresh_token']; $access_token = $row['access_token']; $redirect_uri = $row['redirect_uri']; $date = $row['date']; $time = time(); if($access_token){//獲取重新整理token $url='https://api.mercadolibre.com/oauth/token?grant_type=refresh_token&client_id='.$client_id.'&client_secret='.$client_secret.'&refresh_token='.$refresh_token; $overtime = $date+6*60*60; if($overtime<$time){//檢視token是否過期 $culpost = json_decode(curl_post($url),true); var_dump($culpost); $token = $culpost['access_token']; if($token){ //更新token } return $token; }else{ return $access_token; } }else{ $url='https://api.mercadolibre.com/oauth/token?grant_type=authorization_code&client_id='.$client_id.'&client_secret='.$client_secret.'&code='.$refresh_token.'&redirect_uri='.$redirect_uri; $culpost = json_decode(curl_post($url), true); $token = $culpost['access_token']; return $token; } } function curl_post($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1);//post提交方式 $data = curl_exec($ch);//執行curl curl_close($ch); return $data; }
訂單下載簡單示例
//獲取指定狀態的訂單 $status = "paid"; $time = time() - 3600*24*5; $from = date('Y-m-d',$time); $url = "https://api.mercadolibre.com/marketplace/orders/search?order.status={$status}&date_created.from={$from}&access_token={$access_token}"; $list = file_get_contents($url); //訂單列表 $orderlist = json_decode($list,true); //檢視單獨訂單的資料 $order_url = "https://api.mercadolibre.com/marketplace/orders/{$order_id}?access_token={$access_token}"; $order = file_get_contents($order_url); $order_arr = json_decode($order,true); //獲取物流資訊 $shipping_url = "http://api.mercadolibre.com/marketplace/shipments/{$order_arr['shipping']['id']}?access_token={$access_token}"; $shipping = file_get_contents($shipping_url); $shipping_list = json_decode($shipping,true);