"wagS3", "act"=>"genCredV2", "view"=>"genCredV2JSON", "affId"=> $affiliateId, "apiKey"=>$apiKey, "devinf"=>"IE,11", "appver"=>"0.01" ); $cred_data=json_encode($cred_data); echo "\nCredential Request = ",$cred_data; $headers = array('Content-type: application/json; charset=utf-8'); $curl = curl_init($apiEndPoint); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, $cred_data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $cred_response = curl_exec($curl); echo "\n\nCredential Response = ",$cred_response,"\n\n"; $cred_response = json_decode($cred_response,TRUE); curl_close($curl); // File Upload Process Starts - *** Repeat For As Many Images as required using the same Credentials obtained above *** $contentMD5 = ""; $contentType = "image/jpg"; $fileName = "Curiosity.jpg"; $fileStream=fopen('/Users/ctsuser1/Desktop/Curiosity.jpg','r'); $flSize=filesize('/Users/ctsuser1/Desktop/Curiosity.jpg'); // echo "\nFile Contents = ",$file,"\n\n"; $accessKey = $cred_response['accessKeyId']; $sessionId = $cred_response['sessionId']; $uploadUrl = $cred_response['uploadUrl']; $bucket = str_replace('http://','',$uploadUrl); $secretKey = $cred_response['secretKey']; echo "Access Key Id = ",$accessKey,"\n\nSecret Key = ",$secretKey,"\n\nSession Id = ",$sessionId,"\n\nUpload URL = ",$uploadUrl,"\n\nFile Size = ",$flSize,"\n\n"; $date= gmdate("D, d M Y H:i:s T") ; echo "Date = ",$date,"\n\n"; $canonicalizedResource = "/".$bucket."/".$fileName; $canonicalizedAmzHeaders = "x-amz-security-token:".$sessionId; //echo "Canonicalized Resource = ",$canonicalizedResource,"\n\n"; $data = "PUT\n".$contentMD5."\n".$contentType."\n".$date."\n".$canonicalizedAmzHeaders."\n".$canonicalizedResource; echo "Data = ",$data,"\n\n"; $signature=base64_encode(hash_hmac('sha1', $data, $secretKey, true)); //echo "Signature = ",$signature,"\n\n"; $authorization="AWS ".$accessKey.":".$signature; echo "authorization = ",$authorization,"\n\n"; $uploadUrlRef = $uploadUrl."/".$fileName; //echo "uploadUrlRef = ",$uploadUrlRef,"\n\n"; $ch = curl_init($uploadUrlRef); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_BINARYTRANSFER, "1"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Date:'.$date,'Content-Type:'.$contentType,'Content-Length:'.$flSize,'x-amz-security-token:'.$sessionId,'Authorization:'.$authorization)); //curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($fileStream)); curl_setopt ($ch, CURLOPT_UPLOAD, true); curl_setopt($ch, CURLOPT_INFILE, $fileStream); curl_setopt($ch, CURLOPT_INFILESIZE, $flSize); $result = curl_exec($ch); echo "Response Code: ",curl_getinfo($ch, CURLINFO_HTTP_CODE),"\n\n"; curl_close($ch); echo "Upload Result = ",$result,"\n\n"; // File Upload Process Ends // Generating File Download URL - Starts $imageExpiryTime = time()+259200000; $contentTypeForDownload = ""; $contentMD5ForDownload = ""; $getData = "GET\n".$contentMD5ForDownload."\n".$contentTypeForDownload."\n".$imageExpiryTime."\n".$canonicalizedAmzHeaders."\n".$canonicalizedResource; $signatureForDownload = base64_encode(hash_hmac('sha1', $getData, $secretKey, true)); $encodedTokenValue = urlencode($sessionId); $encodedSignatureValue = urlencode($signatureForDownload); echo "Encoding Difference = \n\n",$encodedTokenValue,"\n\n",$sessionId,"\n\n"; $fileDownloadURL = $uploadUrlRef."?Expires=".$imageExpiryTime."&AWSAccessKeyId=".$accessKey."&x-amz-security-token=".$encodedTokenValue."&Signature=".$encodedSignatureValue; echo "File Download URL = ",$fileDownloadURL,"\n\n"; // Generating File Download URL - Ends // Generating the Check Out URL - Starts $checkOutData = array( "transaction"=>"photoCheckoutv2", "apiKey"=>$apiKey, "devinf"=>"IE,11", "appver"=> "0.0", "act"=>"mweb5UrlV2", "view"=> "mweb5UrlV2JSON", "affId"=> $affiliateId, "expiryTime"=>"", "images"=>array(), "lat"=>"", "lng"=>"", "customer"=> array( "firstName"=> "", "lastName"=> "", "email"=> "", "phone"=> ""), "channelInfo"=>"web", "callBackLink"=>"http://www.walgreens.com", "publisherId"=>"7356282", "affNotes"=>"" ); array_push($checkOutData['images'], $fileDownloadURL); $checkOutRequestData = json_encode($checkOutData); echo "CheckOut Request = ",$checkOutRequestData,"\n\n"; $ch = curl_init($apiEndPoint); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $checkOutRequestData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $checkOutResponse = curl_exec($ch); echo "CheckOut Response = ",$checkOutResponse,"\n\n"; $checkOutResponse = json_decode($checkOutResponse,TRUE); // Generating the Check Out URL - Ends echo "Access the Checkout @ ",$checkOutResponse['landingUrl'],"&token=",$checkOutResponse['token'],"\n\n"; ?>