I'm having a problem with retrieving the results of a processed feed file using Amazon MWS API with PHP. I'm using the getFeedSubmissionResult class, to be precise. The problem is that when i use the API, as instructed by the documentation, there are no relevant data that is read by the class that i can access (or so it seems). So my question is: how do i retrieve the raw XML file that amazon sends back and store it to a file on my computer?
I've been retracing the code used by MWS and trying to find where they pull in the XML file from amazon and parse it to try and save that into a file with no luck. I'd deeply appreciate it if someone could direct me to a fix to this, and if not, then maybe a work around may be better.
So this is what i've been doing:
I used the getFeedSubmissionResultSample.php provided in the samples of MWS . Supposedly, this should give me the data that tells me how many items were processed and how many processed items were successful. But it doesn't. So I tried to do a print_r of the response variable:
function invokeGetFeedSubmissionResult(MarketplaceWebService_Interface $service,$request) {
try {
$response = $service->getFeedSubmissionResult($request);
echo "<br />Var dump here: <pre>";
print_r($response);
echo ("<pre>Service Response\n");
echo ("=============================================================================\n");
echo(" GetFeedSubmissionResultResponse\n");
if ($response->isSetGetFeedSubmissionResultResult()) {
$getFeedSubmissionResultResult = $response->getGetFeedSubmissionResultResult();
echo (" GetFeedSubmissionResult\n");
if ($getFeedSubmissionResultResult->isSetContentMd5()) {
echo (" ContentMd5\n");
echo (" " . $getFeedSubmissionResultResult->getContentMd5() . "\n");
}
}
if ($response->isSetResponseMetadata()) {
echo(" ResponseMetadata\n");
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
echo(" RequestId\n");
echo(" " . $responseMetadata->getRequestId() . "\n");
}
}
echo(" ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebService_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
And the output gives me this:
Service Response
GetFeedSubmissionResultResponse
GetFeedSubmissionResult
ContentMd5
G5Sw+2ooONEZU1iQoqdEOQ==
ResponseMetadata
RequestId
f9d4be45-6710-42eb-850e-f437224f9938
ResponseHeaderMetadata: RequestId: f9d4be45-6710-42eb-850e-f437224f9938, ResponseContext: EM/RH7RHQhLSc47Tj2a2Uv2CGKEfvxaKOijjcaKeoh8dGISci3yqo9OHZs7dpLDIszJVz4Jt4z8=,9SYUaktMzcOG6UyuyhXu/kJPl0gpLeenslL2rkugDLhDYftMleRx1XIexbVWNxuYl7cO6901Foiv Kp7hvaLeAQ==, Timestamp: 2013-06-18T07:29:37.393Z
I have omitted the var_dump results because i don't know if that may pose a security issue on my part. But in any case, the var_dump didn't give any data that i could access. I have also traced the code to where the classes and their methods to see if i can access it from there but came out empty-handed.
Note that I have the proper parameters for calling in the results (i.e. the FeedSubmissionId) because I've done this with the amazon scratch pad.
Your help would be greatly appreciated! :)
regards,
Caleb
I had the same problem. The issue is that the response returns the result for you to compare the received file against to verify no corruption during transmission. To get xml response with Message you should save it to file not to php://memory. So the next code works for me fine
$filename = __DIR__.'/file.xml';
$handle = fopen($filename, 'w+');
$request = new MarketplaceWebService_Model_GetFeedSubmissionResultRequest();
$request->setMerchant(MERCHANT_ID);
$request->setFeedSubmissionId(ID_TO_CHANGE);
$request->setFeedSubmissionResult($handle);
try {
$response = $service->getFeedSubmissionResult($request);
fclose($handle);
echo ("Service Response\n");
echo ("=============================================================================\n");
echo(" GetFeedSubmissionResultResponse\n");
if ($response->isSetGetFeedSubmissionResultResult()) {
$getFeedSubmissionResultResult = $response->getGetFeedSubmissionResultResult();
echo (" GetFeedSubmissionResult");
if ($getFeedSubmissionResultResult->isSetContentMd5()) {
echo (" ContentMd5");
echo (" " . $getFeedSubmissionResultResult->getContentMd5() . "\n");
}
}
if ($response->isSetResponseMetadata()) {
echo(" ResponseMetadata\n");
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
echo(" RequestId\n");
echo(" " . $responseMetadata->getRequestId() . "\n");
}
}
echo(" ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebService_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
the result you can find in ./file.xml file
this helped me
If you do not want to use a file. Then at the end of your try statement.
$xml = stream_get_contents($request->getFeedSubmissionResult());
That will put the xml data into $xml
Related
Using phpseclib from my PHP application, I am running a perl .pl script which creates a file on the remote server's drive/folder in one of the exec() commands. This works fine and the file exists. The next exec() does an 'ls' command to retrieve the full filename which contains a date/time stamp on the end of the file name that is unknown. When it runs, it doesn't find the file when it is there and I can see it when doing a manual 'ls' on the Linux system. I believe it might be a timing issue, so I also included a sleep 15 in between creation and doing the 'ls' command, but this did not resolve the issue. And if I run the program again, creating a 2nd file, then the 'ls' returns the filename for the first file I generated. I didn't see an fclose in the documentation, but did see it in some other posts here that might lead me to believe this might also be the issue. Has anyone else experienced this issue and how did you resolve? Thanks.
Updated: Code snippet added....
$ssh2->login(LINUX_USER,LINUX_PASS);
$connected = $ssh2->isAuthenticated();
if ($connected) {
//$_SESSION['feedback'] .= "Connection and authentication successful to " . LINUX_SVR . ".<br>";
$cmd_string = "/usr/bin/perl-report.pl " . LINUX_ENV . " " . $parm1 . " " . $parm2;
$error = $ssh2->exec($cmd_string);
if ($error) {
$_SESSION['feedback'] .= "Unable to execute command to create the Report - contact Operations with this error.<br>";
$_SESSION['feedback'] .= $ssh2->getLog();
} else {
$_SESSION['feedback'] .= "Report successfully created for ID " . $parm2 . ".<br>";
//get the full name of the file created
$cmd_string = "sleep 15";
$ssh2->exec($cmd_string);
$cmd_string = "ls /root/Report-" . $parm1 . "-" . $parm2 . "-" . $date . "*";
$error = $ssh2->exec($cmd_string);
if (empty($error)) {
$_SESSION['feedback'] .= "Unable to execute command to obtain report name - contact Operations with this error.<br>";
$_SESSION['feedback'] .= $ssh2->getLog();
} else {
$filename = $ssh2->exec($cmd_string);
$filename = substr($filename, 6, strlen($filename));
$_SESSION['feedback'].= "The file name created is " . $filename . "<br>";
//verify that the filename is valid
if (substr($filename,0,7)=="Report-") {
//mail the attachment to the emailaddr
$cmd_string = "echo 'Requested Report attached.' | mail -s '" . $filename . "' -a '/root/" . $filename . "' " . $emailaddr . "\n";
$error = $ssh2->exec($cmd_string);
if ($error) {
$_SESSION['feedback'] .= "Unable to successfully email the requested report - contact Operations with this error.<br>";
$_SESSION['feedback'] .= $ssh2->getLog();
} else {
$_SESSION['feedback'] .= "Report successfully emailed to " . $emailaddr . ". Process complete.<br>";
$_SESSION['feedback'] .= $ssh2->getLog();
}
} else {
$_SESSION['feedback'] .= "Unable to email attachment as filename is invalid - contact Operations with this error.<br>";
$_SESSION['feedback'] .= $ssh2->getLog();
}
}
}
} else {
$_SESSION['feedback'] .= "Connection and authentication failed to " . LINUX_SVR . ".<br>";
}
//disconnect when done
$ssh2->reset();
$ssh2->disconnect();
}
I am working with an API that has a function called invokeGetMatchingProductForId() and every time the script is run, this error occurs. I am attempting to loop through the script to change one variable but i am not sure if that is the problem. If you guys have any suggestions let me know. Any help would be much appreciated! Thanks in advance!
function invokeGetMatchingProductForId(MarketplaceWebServiceProducts_Interface $service, $request)
{
try {
$response = $service->GetMatchingProductForId($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
global $file_name;
global $i;
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
echo $dom->saveXML();
$dom ->save('xml/' . $file_name . $i . '.xml');
echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebServiceProducts_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex- >getResponseHeaderMetadata() . "\n");
}
}
When I get a response from the server, This error occurs.
Fatal error: Cannot redeclare function()(previously declared in x:\xampp\htdocs\name\src\project0\php\unknown.php:110) in x:\xampp\htdocs\name\src\project0\php\unknown.php on line 136
Line 136 is an empty line.
I am using COM to convert dynamically created word docx to PDFs. Everything is working perfectly, but our c:\windows\temp\ directory is getting extremely large (and we have limited disk space on our C drive). Below is the code I am using to generate the PDF. Is there a way to delete the temp file that gets added to the system's temp directory after the file is closed? In addition, after the word doc is converted to pdf, we no longer need it (so it doesn't matter if deleting the tmp file corrupts the word doc).
/Word Doc to PDF using Com
ini_set("com.allow_dcom","true");
try{
$word = new com('word.application');
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
$word->Visible = 0; //don't open word gui on server
$word->DisplayAlerts = 0; //don't allow any alerts to open
//open doc
try{
$doc = $word->Documents->Open(DOC_LOCATION . "temp_doc/" . $filename . ".docx");
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
try{
$doc->ExportAsFixedFormat(DOC_LOCATION . "temp_pdf/" . $filename . ".pdf", 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
$word->Quit();
$word = null;
Don't say what version, but for XP- you can use a simple batch file to delete the files in \Documents and Settings\USER\Local Settings\temp\. Example:
C:
cd \Documents and Settings\USER\Local Settings\Temp
attrib -R -S -H *.* /S /D
DEL /S /F /Q *.*
Modify accordingly.
I am trying to convert .docx files to pdf using PHP on a Windows server. I tried several of the solutions from other posts, including phpdocx (which does a very poor conversion that doesn't keep any formatting) and php's Com object. I only have Office 2003, so there is no pdf converter available using Com.
I thought of using OpenOffice/LibreOffice, but haven't found any information about installing and using Com for these on a windows server (I know it can be installed, but I can't figure out how to set up Com for it).
Using a webservice is not an option due to the data on the forms (they have to remain on our server). This means that Zend Framework cannot be used.
Any suggestions would be helpful, or information about using Com with Open Office.
I was finally able to get this working. OUr problem was that Word 2003 didn't have a PDF converter in it. We ended up using a trial version of Office 2010 for now (assuming that everything works correctly, we will purchase the full version). Word 2007 would have worked also. Below is the code I used to get this working:
//Word Doc to PDF using Com
ini_set("com.allow_dcom","true");
try{
$word = new com('word.application') or die('MS Word could not be loaded');
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
$word->Visible = 0;
$word->DisplayAlerts = 0;
try{
$doc = $word->Documents->Open(DOC_LOCATION. 'test_image.docx');
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
echo "doc opened";
try{
$doc->ExportAsFixedFormat(DOC_LOCATION . "test_image.pdf", 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
echo "created pdf";
$word->Quit();
$word = null;
Currently I am making a IRC that sends a message onto the IRC main channel. Here is my code:
<?php
$ircServer = "xxxx";
$ircPort = "6667";
$ircChannel = "#bots";
set_time_limit(0);
$msg = $_GET['msg'];
$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);
if ($ircSocket)
{
fwrite($ircSocket, "USER Lost rawr.test lol :code\n");
fwrite($ircSocket, "NICK Rawr" . rand() . "\n");
fwrite($ircSocket, "JOIN " . $ircChannel . "\n");
fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
// Separate all data
$exData = explode(' ', $data);
// Send PONG back to the server
if($exData[0] == "PING")
{
fwrite($ircSocket, "PONG ".$exData[1]."\n");
}
}
echo $eS . ": " . $eN;
}
}
?>
<html><body>
<h4>IRC Bot Tester</h4>
<form action="irc.php" method="post">
Command: <input type="text" name="msg" />
<input type="submit" />
</form>
</body></html>
My problem is the BOT is not sending any messages to the channel, as you see I used post + get data for the message info sent to the channel.
Here is the log what I recieve:
:irc.underworld.no 366 Rawr30517 #bots
:End of /NAMES list.
:irc.underworld.no 411 Rawr30517 :No
recipient given (PRIVMSG) : 0: 0PING
:irc.underworld.no
I do not know which part causes the this:
recipient given (PRIVMSG) : 0: 0PING
Thanks if anyone could help me. I am trying to simply post a message to the bot and the bot delivers the message to the main channel.
Change:
$msg = $_GET['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");
To:
$msg = $_POST['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " :" . $msg . "\n");
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " . $msg = $_GET['msg'] . "\n");
To:
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " .$msg. "\n");