对接wayfair API

本文档介绍如何使用PHP对接Wayfair API,包括API的选择、参数获取、请求处理及令牌有效期的注意事项。通过示例代码展示获取token的过程。
摘要由CSDN通过智能技术生成

文档地址

Wayfair API Documentation

拉单有两个,一个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);
}
评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值