1

一直试图使用 walmart api 获取项目报告 csv 文件但没有运气,而是得到这个不可读的响应。需要帮忙。我怎样才能使这项工作?

这是响应的屏幕截图:

cURL 获取响应

这是我的代码:

$walmart_consumer_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$walmart_channel_type = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$dtd = date("Y_m_d");

$request_type = "GET";

$url = "https://marketplace.walmartapis.com/v2/getReport?type=item";

// We need a timestamp to generate the signature and to send as part of the header
$timestamp = round(microtime(true) * 1000);

$signature = getClientSignature($url, $request_type, $timestamp);

$headers = array();
$headers[] = "Accept: application/xml";
$headers[] = "WM_SVC.NAME: Walmart Marketplace";
$headers[] = "WM_CONSUMER.ID: ".$walmart_consumer_id;
$headers[] = "WM_SEC.TIMESTAMP: ".$timestamp;
$headers[] = "WM_SEC.AUTH_SIGNATURE: ".$signature;
$headers[] = "WM_QOS.CORRELATION_ID: ".mt_rand();
$headers[] = "WM_CONSUMER.CHANNEL.TYPE: " .$walmart_channel_type;
$headers[] = "Content-type: text/";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_type);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

var_dump($result);
4

1 回答 1

0

看起来响应是 ZIP 格式的;注意结果中的前两个字符是“ PK”——这很神奇,说它是 zip 格式。可能是 curl 解码 ZIP 格式的一个选项。

于 2018-06-13T20:00:26.853 回答