文档地址
拉单有两个,一个Wayfair API Documentation,另一个Wayfair API Documentation,根据自己业务选择
wayfair后面有完整的参数查看,文档的不太全,他的请求没有分页且只有开始时间,limit设置为0他就能返回全部,所以自己还要筛除重复单,他的toke有效期86400,有一天的时效
得到token
$url="https://sso.auth.wayfair.com/oauth/token"; $array=array( 'client_id' => $client_id, 'client_secret' =>$client_secret, 'audience' => 'https://api.wayfair.com/', 'grant_type' => 'client_credentials'); $header=array('Content-Type'=>'application/json'); $result=$this->curlPost($url,$array,$header); $tokenArray=json_decode($result,true);
public function curlPost($url,$data,$HEADER){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_HTTPHEADER,$HEADER); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_TIMEOUT,120); // POST数据 curl_setopt($ch, CURLOPT_POST, 1); // 把post的变量加上 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); return $output; }
example:
$query = '{"query":"query getDropshipPurchaseOrders{getDropshipPurchaseOrders(limit: 0,hasResponse: false,fromDate:\"'.$this->getFormattedTimestamp($BeginTime).'\",sortOrder: DESC) {id,storePrefix,poNumber,poDate,estimatedShipDate,scheduledDeliveryDate,deliveryMethodCode,customerName,customerAddress1,customerAddress2,customerCity,customerState,customerCountry,customerPostalCode,orderType,shippingInfo {shipSpeed,carrierCode,poolPointAgent{id,name},crossDockAgent{id,name},deliveryAgent{id,name}},packingSlipUrl,warehouse {id,name,address {name,address1,address2,address3,city,state,country,postalCode}},products {sku,totalCost,estShipDate,partNumber,quantity,price,pieceCount,fillDate,event {id,type,name,startDate,endDate}},shipTo {name,address1,address2,address3,city,state,country,postalCode,phoneNumber},,billingInfo {vatNumber}}}"}';
$result=$this->curlPost($url,$query,$arr_header);
public function getFormattedTimestamp($dateTime='2021-07-22') { if (!is_object($dateTime)) { if (is_string($dateTime)) { $dateTime = new DateTime($dateTime); } else { throw new Exception("Invalid date value."); } } else { if (!($dateTime instanceof DateTime)) { throw new Exception("Invalid date value."); } } return $dateTime->format(DATE_ISO8601); }