Php 使用curl将amazon MWS scratchpad submit提要查询转换为API调用

Php 使用curl将amazon MWS scratchpad submit提要查询转换为API调用,php,curl,amazon-web-services,Php,Curl,Amazon Web Services,在过去的两天里,我一直在amazonapi中搜索submitfeed“\u POST\u PRODUCT\u DATA”。我想这是个问题,还是别的什么问题。以下是我的代码 $feed = '<?xml version="1.0" encoding="iso-8859-1"?> <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchem

在过去的两天里,我一直在
amazonapi
中搜索
submitfeed“\u POST\u PRODUCT\u DATA”
。我想这是个问题,还是别的什么问题。以下是我的代码

$feed = '<?xml version="1.0" encoding="iso-8859-1"?>
            <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
            <Header>
            <DocumentVersion>1.02</DocumentVersion>
            <MerchantIdentifier>XXX</MerchantIdentifier>
            </Header>
            <MessageType>Product</MessageType>
            <PurgeAndReplace>false</PurgeAndReplace>
            <Message>
            <MessageID>1</MessageID>
            <OperationType>Update</OperationType>
            <Product>
            <SKU>CX-1003</SKU>
            <StandardProductID>
            <Type>ASIN</Type>
            <Value>B000H3ACGW</Value>
            </StandardProductID>
            <Condition>
            <ConditionType>New</ConditionType>
            </Condition>
            </Product>
            </Message>
            </AmazonEnvelope>';

        $feedHandle = @fopen('php://memory', 'rw+');
        fwrite($feedHandle, $feed);
        rewind($feedHandle);

        $param = array(
            'AWSAccessKeyId'=> aws_access_key_id,
            'Action'=>"SubmitFeed",
            'Merchant'=> seller_id,
            'SignatureMethod' => "HmacSHA256",
            'SignatureVersion'=> "2",
            'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
            'Version' => "2009-01-01",
            'PurgeAndReplace' => "false",
            'FeedType' => "_POST_PRODUCT_DATA_");
            $md5 = base64_encode(md5(stream_get_contents($feedHandle), true));
            $secret = secret_key;

        $url = array();
        foreach ($param as $key => $val) {
            $key = str_replace("%7E", "~", rawurlencode($key));
            $val = str_replace("%7E", "~", rawurlencode($val));
            $url[] = "{$key}={$val}";
        }

        sort($url);

        $arr   = implode('&', $url);

        $sign  = 'POST' . "\n";
        $sign .= 'mws.amazonservices.com' . "\n";
        $sign .= '/' . "\n";
        $sign .= $arr;

        $signature = hash_hmac("sha256", $sign, $secret, true);
        $signature = urlencode(base64_encode($signature));

        $link  = "https://mws.amazonservices.com/?";
        $link .= $arr . "&Signature=" . $signature;

        $ch = curl_init($link);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Content-MD5: '.$md5));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        $response = curl_exec($ch);
        $info = curl_getinfo($ch);
        pr($info);
        $resp = simplexml_load_string($response);
        curl_close($ch);
        pr($resp);die;

您应该尝试官方的Amazon Feeds Api for PHP:


你也可以在packagist上找到一些叉子

您是否有任何示例代码显示我们如何使用Amazon库?
SimpleXMLElement Object
(
[Error] => SimpleXMLElement Object
    (
        [Type] => Sender
        [Code] => SignatureDoesNotMatch
        [Message] => The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
    )
[RequestID] => 0b7e2205-c99a-456d-8e30-715d43e6c115
)