我正在尝试使用 PHP 中的 CURL 获取沃尔玛退货 API。
https://developer.walmart.com/tryout/us/mp/returns
由于某种原因,它不接受我的方法或者返回错误,例如...
INVALID_REQUEST.GMP_ORDER_API requestParam
Could not find acceptable representation
Request invalid.
这是我的代码:
$getTokenUrl='https://marketplace.walmartapis.com/v3/token';
$client_id=CLIENT_ID;
$secret_key=SECETE_KEY;
$authorization_key=base64_encode($client_id.":".$secret_key);
$generated_corelation_id=md5(date('Y-m-d H:i:s'));
$Tokenheaders = array(
'Authorization:Basic '.$authorization_key,
'WM_SVC.NAME:Walmart Marketplace',
'WM_QOS.CORRELATION_ID:'.$generated_corelation_id,
'Content-Type: application/x-www-form-urlencoded'
);
$createString='grant_type=client_credentials';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $getTokenUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $createString,
CURLOPT_HTTPHEADER => $Tokenheaders,
));
$accessToken = curl_exec($curl);
$accessToken = trim($accessToken);
$result = explode('<\/accessToken>',json_encode($accessToken));
$accessToken=str_replace( '"', "", $result[0] );
$generateToken = explode('<accessToken>',trim($accessToken));
$updateData['generateToken'] = $generateToken[1];
$header=array(
'Authorization: AUTH',
'WM_SEC.ACCESS_TOKEN: '.$generateToken[1],
'WM_QOS.CORRELATION_ID: '.trim($generated_corelation_id),
'WM_SVC.NAME: Walmart Marketplace',
'Content-Type: application/xml',
'Cookie: TS01f4281b=01c5a4e2f9d2e37f503c87a5acab256d9aa105b3dfa312ae726f9a85fa0e52b76d3fa46124800be0568fc6d32e9e54cb0d3ab31120'
);
$url='https://marketplace.walmartapis.com/v3/returns';
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $header,
));
$response = curl_exec($curl);
WM_QOS.CORRELATION_ID
使用 guid
,而不是 md5