2012-12-12 74 views
1
POST /Orders/2011-01-01?AWSAccessKeyId=MyAccessKey 
&Action=ListOrders 
&SellerId=SellerId 
&SignatureVersion=2 
&Timestamp=2012-12-12T08%3A31%3A19Z 
&Version=2011-01-01 
&Signature=MySignature 
&SignatureMethod=HmacSHA256 
&CreatedAfter=2012-12-06T19%3A00%3A00Z 
&MarketplaceId.Id.1=MyMarketID HTTP/1.1 
Host: mws.amazonservices.co.uk 
x-amazon-user-agent: AmazonJavascriptScratchpad/1.0 (Language=Javascript) 
Content-Type: text/xml 

我試圖將這些亞馬遜便箋式請求細節轉換爲php curl,但都是徒勞的。任何人都知道如何轉換這些。如何將此ScratchPad請求詳細信息轉換爲PHP

下面是代碼片段,不是所有的,而是一部分代碼。 沒有什麼是顯示

$params = array(
     'AWSAccessKeyId' => AWS_ACCESS_KEY_ID, 
     'Action' => "ListOrders", 
       'SellerId' => MERCHANT_ID, 
     'SignatureMethod' => "HmacSHA256", 
     'SignatureVersion' => "2", 
    'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()), 
    'Version'=> "2011-10-01", 
    'MarketplaceId' => MARKETPLACE_ID, 
    ); 



// Sort the URL parameters 
$url_parts = array(); 
    foreach(array_keys($params) as $key) 
    $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key])); 
sort($url_parts); 

// Construct the string to sign 
$url_string = implode("&", $url_parts); 

$string_to_sign = "POST\nmws.amazonservices.co.uk\n/Orders/2011-10-01\n" . $url_string; 

// Sign the request 
$signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE); 

//Base64 encode the signature and make it URL safe 
    $signature = urlencode(base64_encode($signature)); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
$response = curl_exec($ch); 
var_dump($response); 

捲曲的GetInfo

[content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array () [primary_ip] => [primary_port] => 0 [local_ip] => [local_port] => 0 [redirect_url] =>) 

URL

https://mws.amazonservices.co.uk/Orders/2011-01-01?AWSAccessKeyId=myaccesskey&Action=ListOrders&CreatedAfter=2012-12-06T19%253A00%253A00Z&MarketplaceId.Id.1=marketplaceiddumy&SellerId=selleriddummy&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-12-12T13%3A16%3A56.000Z&Version=2011-10-01&Signature=lXaoVq1n4b0gAmoMg69jnSCqHWC6C6hlbEfTtrHX2i0%3D 
+1

你面臨什麼困難?向我們展示您的實施代碼。 – Manish

+0

@Manish代碼已更新。 –

+1

'curl_getinfo($ ch)的打印是什麼;'?設置'CURLOPT_HEADER,TRUE'並顯示響應頭。 – Ranty

回答

1

我有更改時間戳和其他一些增值經銷商,它的作品。

$params = array(
    'AWSAccessKeyId' => AWS_ACCESS_KEY_ID, 
    'Action' => 'ListOrders', 
    'SellerId' => MERCHANT_ID, 
    'SignatureVersion' => '2', 
    'Version'=> '2011-01-01', 
    'OrderStatus.Status.1'=> 'Unshipped', 
    'OrderStatus.Status.2'=> 'PartiallyShipped', 
    'SignatureMethod' => 'HmacSHA256', 
    'CreatedAfter'=>'2012-12-06T19:00:00Z', 
    'MarketplaceId.Id.1' => MARKETPLACE_ID, 
    ); 
$params['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z"); 
// Sort the URL parameters 
$url_parts = array(); 
foreach(array_keys($params) as $key) 
    $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key])); 
sort($url_parts); 

// Construct the string to sign 
$url_string = implode("&", $url_parts); 
$url_string = trim($url_string, '&'); 
$string_to_sign = "POST" . "\n" ."mws.amazonservices.co.uk"."\n"."/Orders/2011-01-01"."\n" . $url_string; 

// Sign the request 
$signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE); 

// Base64 encode the signature and make it URL safe 
////echo AWS_SECRET_ACCESS_KEY; 
     $signature = base64_encode(hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, True)); 
     $signature = str_replace("%7E", "~", rawurlencode($signature)); 

$url = 'https://mws.amazonservices.co.uk/Orders/2011-01-01?' . $url_string . '&Signature=' . $signature; 

$headers = array("Content-Type: text/xml"); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 


//echo $url_string; 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $headers); 

$response = curl_exec($ch); 
curl_close($ch); 
//$parsed_xml = simplexml_load_string($response); 
//return ($parsed_xml); 
return $response; 
相關問題