我一直很难将商品上传到沃尔玛。
我收到以下错误**
_ INVALID_REQUEST_CONTENT.GMP_GATEWAY_APImoreThanOneFeedRequest 内容无效。ERRORDATA
** 我相信它可能与有效负载/数据有关,但是我尝试了许多不同的格式,但无法克服这个一般错误。
我的测试网址是
http://sandbox.gottires.com/api/walmart/senddata-walmart33.php
如果有人可以提供帮助,我将不胜感激。这让我发疯了下面是我的代码:
$URL = 'https://marketplace.walmartapis.com/v3/feeds?feedType=item';
$RequestMethod = 'POST';//Request method type i.e GET, POST
$Timestamp = round(microtime(true) * 1000); //Current system timestamp
$WalmartConsumerID = '66543541tedyhyde3t53.524';
function _GetWalmartAuthSignature($URL, $RequestMethod, $Timestamp) {
$WalmartPrivateKey = 'dgjsdhsehsethsethsehsetjrdjrj';//Your Walmart Private Key;
$WalmartConsumerID = 'djdrtudrturdtu';//Your Walmart Comsumer Id;
// CONSTRUCT THE AUTH DATA WE WANT TO SIGN
$AuthData = $WalmartConsumerID."\n";
$AuthData .= $URL."\n";
$AuthData .= $RequestMethod."\n";
$AuthData .= $Timestamp."\n";
// GET AN OPENSSL USABLE PRIVATE KEY FROMM THE WARMART SUPPLIED SECRET
$Pem = _ConvertPkcs8ToPem(base64_decode($WalmartPrivateKey));
$PrivateKey = openssl_pkey_get_private($Pem);
// SIGN THE DATA. USE sha256 HASH
$Hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
if (!openssl_sign($AuthData, $Signature, $PrivateKey, $Hash))
{ // IF ERROR RETURN NULL
var_dump(base64_encode($Signature));
echo "</br> Failed signiture </br>";
return null;
}
//ENCODE THE SIGNATURE AND RETURN
return base64_encode($Signature);
}
//echo _GetWalmartAuthSignature($URL, $RequestMethod, $Timestamp);
function _ConvertPkcs8ToPem($der){
static $BEGIN_MARKER = "-----BEGIN PRIVATE KEY-----";
static $END_MARKER = "-----END PRIVATE KEY-----";
$key = base64_encode($der);
$pem = $BEGIN_MARKER . "\n";
$pem .= chunk_split($key, 64, "\n");
$pem .= $END_MARKER . "\n";
return $pem;
}
function auth($url, $RequestMethod,$Timestamp,$WalmartConsumerID){
$qos = uniqid();
// $headers[] = 'POST /v3/feeds?feedType=item HTTP/1.1';
$headers[] = 'WM_SVC.NAME: Walmart Marketplace';
$headers[]= 'WM_QOS.CORRELATION_ID: '.$qos;
$headers[]= 'WM_SEC.TIMESTAMP: '.$Timestamp;
$headers[]= 'WM_SEC.AUTH_SIGNATURE: '._GetWalmartAuthSignature($url, $RequestMethod, $Timestamp);
$headers[]= 'WM_CONSUMER.CHANNEL.TYPE: 0rduyrdturdrt0e005832524d';
$headers[]= 'WM_CONSUMER.ID: '.$WalmartConsumerID;
$headers[]= 'Content-Type: multipart/form-data; boundary=12345';
$headers[]= 'Accept: application/xml';
// $headers[]= 'Host: https://marketplace.walmartapis.com';
//$headers[]= 'Host: marketplace.walmartapis.com';
//var_dump($headers);
return $headers;
}
$val = file_get_contents('http://ak-websolutions.com/dev/walmart/product.xml');
$eol = "\r\n";
$data = '';
$mime_boundary="12345";
$data .= '--' . $mime_boundary . $eol;
$data .= ' ' . $eol . $eol;
$data .= '<?xml version="1.0 encoding="UTF-8""?>' . $eol;
$data .= '<MPItemFeed xmlns=”http://walmart.com/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://walmart.com/ MPItem.xsd „">' . $eol;
$data .= '<MPItemFeedHeader>' . $eol;
$data .= '<version>3.1</version>' . $eol;
//$data .= '<mart>WALMART_US</mart>' . $eol;
//$data .= '<locale>en_US</locale>' . $eol;
$data .= '</MPItemFeedHeader>' . $eol;
$data .= '<MPItem>' . $eol;
$data .= '<sku>UHP-8224-JH</sku>' . $eol;
$data .= '<processMode>CREATE</processMode>' . $eol;
$data .= '<productIdentifiers>' . $eol;
$data .= '<productIdentifier>' . $eol;
$data .= '<productIdType>UPC</productIdType>' . $eol;
$data .= '<productId>849849004721</productId>' . $eol;
$data .= '</productIdentifier>' . $eol;
$data .= '</productIdentifiers>' . $eol;
$data .= '<MPProduct>' . $eol;
$data .= '<productName>295 30 R 22 103Y ANTARES MAJORIS M5 30 K MILES </productName>' . $eol;
$data .= '<ProductIdUpdate>Yes</ProductIdUpdate>' . $eol;
$data .= '<SkuUpdate>No</SkuUpdate>' . $eol;
$data .= '<category>' . $eol;
$data .= '<Vehicle>' . $eol;
$data .= '<Tires>' . $eol;
$data .= '<shortDescription>295 30 R 22 103Y ANTARES MAJORIS M5 30 K MILES</shortDescription>' . $eol;
$data .= '<brand>ANTARES</brand>' . $eol;
$data .= '<mainImageUrl>https://www.stuff4crafts.com/media/catalog/product/4/3/437764.jpg</mainImageUrl>' . $eol;
$data .= '<tireSize>2953022</tireSize>' . $eol;
$data .= '</Vehicle>' . $eol;
$data .= '</Tires>' . $eol;
$data .= '</category>' . $eol;
$data .= '</MPProduct>' . $eol;
$data .= '</MPItem>' . $eol;
$data .= '</MPItemFeed>' . $eol;
$data .= "--" . $mime_boundary . "--" . $eol . $eol; // finish with two eol's!!
$ch = curl_init( $URL );
//echo $val;
$ch = curl_init(); // Initialize the curl
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
curl_setopt($ch, CURLOPT_URL, $URL); // set the opton for curl
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// set the option to transfer output from script to curl
curl_setopt($ch, CURLOPT_HTTPHEADER, auth($URL,$RequestMethod,$Timestamp,$WalmartConsumerID));
// curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
if($data!="")
{
curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_PUT, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $val);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}else{
curl_setopt($ch, CURLOPT_POSTFIELDS, $val);
echo "Empty";
}
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
//die();
$response = curl_exec($ch);
$getinfo = curl_getinfo($ch);
;
$responsecode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($responsecode != '200'){
var_dump(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
var_dump(curl_getinfo($ch, CURLINFO_HTTP_CODE));
var_dump(curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
var_dump(curl_getinfo($ch, CURLINFO_PRIVATE));
var_dump(curl_getinfo($ch, CURLINFO_RESPONSE_CODE));
var_dump(curl_getinfo($ch, CURLINFO_HTTP_CONNECTCODE));
var_dump(curl_getinfo($ch, CURLINFO_HTTPAUTH_AVAIL));
var_dump(curl_getinfo($ch, CURLOPT_FOLLOWLOCATION));
var_dump(curl_getinfo($ch, CURLINFO_REDIRECT_URL ));
var_dump(curl_getinfo($ch, CURLINFO_SIZE_UPLOAD));
//var_dump(curl_getinfo($ch, CURLINFO_HEADER_OUT));
var_dump($data);
var_dump($getinfo);
}
if(curl_error($ch)){
echo "Curl Error: " . curl_error($ch);
}
curl_close($ch);
echo '<pre> Error: ';
print_r($response);