Updating Pass for Apple Wallet - Could not extract archive - php

Question 1
I am trying to set up server side for Apple passes so they can be updated. I am currently generating signed zipped passes, which also register to update my tables, with device tokens /id Etc.
The passes do not update with the new passes I generate (Same serial, auth token - different message/image)
In console I'm getting this error (fault):
BOM could not extract archive : Couldn't read PKZIP signature
Received invalid pass data (The pass cannot be read because it isn\U2019t valid
I am using https://github.com/tschoffelen/PHP-PKPass
Along with storing data & passes, and the webserviceurl php page on my server.
Any one got an idea on this?
Question 2
I am also getting an error (fault) in console:
Setting display properties with screenSize=(375, 667) scale=2
Not sure why, or if this even matters?

Fixed!
I created my own version of a generator like the github link.
That fixed the issue.

The problem is in the way ZIP (pkpass) files are generated. I've looked at the code and it's using PHP's ZipArchive. Though the ZIP files generated can be extracted both on Windows and Linux without errors, Apple server is more picky.
I've tried PclZip as well, and it has the same problem.
The solution is to use system() call to zip files using the command-line zip command. The ZIP file generated this way is accepted by Apple.

Related

Empty directory when generating Cloud Endpoints PHP client with Google APIs Client Generator

I'm trying to generate a PHP client for my Google Cloud Endpoints API using the Google APIs Client Generator but it just creates an empty directory instead.
The command I'm using looks like:
generate_library --language=php --language_variant=stable --output_dir=/path/php-client --input=/path/myApi-v1.json
It seems to work when I change the language to csharp and java. I turned on the verbose flag and don't see any errors, only tracing messages like:
DEBUG:codegen:Create: myMethod, parent=update
DEBUG:codegen:Schema.Create: updateRequestContent => MyMessage
DEBUG:codegen:DataTypeFromJson: add MyMessage to cache
Searching around I see someone at the AppEngine sub Reddit posted a similar issue with no response.
I used another approach:
downloaded the zip from
https://github.com/google/apis-client-generator
Extracted the zip file in a directory (i named it client-generator)
Executed the generate.sh script available in the extracted files.
/path/client-generator/generate.sh --input=/path/rest.json --language=php --output_dir=/path/output
The APICLassName.php file is generated
I tried again and changed the --language_variant argument from stable to 1.1.4 and it now works fine.

PHP: Save Dynamic URL Image to Disk

Having trouble capturing the following dynamic image on disk, all I get is a 1K size file
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER
I have setup PHP cURL feature to work just fine on static imagery, but does not work for the above link. Similarly, also copy function, file_put_contents (file_get_contents)...they all work fine for static image. Plenty of references in SO for usage of these PHP functions, so I will not get into details here. Just the copy command:
copy('http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER', 'precip5.png');
Behavior is same, getting precip5.png size 760 bytes, on my windows development box and linux staging box, so can rule OS issues out. Again, all PHP functions do exactly the same thing - generate a file - but empty. Command line curl program is also generating that same junk 1K file.
So, the issue seems to be source and the best I can tell is that it is a dynamic (streaming?) image.
Ideally, I would like this be done in PHP or some command line utility like curl. I am trying to avoid adding java (imageio) dependency just for this...until I absolutely have have to go there...
I am trying to understand the nature of the beast (the image) first ;-)...
The URL you are saving produces HTML output, not the image. You are missing the parameter &print=1
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER&print=1

wkhtmltopdf is returning blank pages for some urls

I have installed the wonderful software wkhtmltopdf on our production Debian server to be used for creating PDFs from URLs. We stream (i hope that's the right term) the resulting PDF to the client, we have no interest in storing them server side.
We only generate PDFs from local URLs (on the own server that is). However, the URL is still based on the domain and not the local IP since there are multiple sites on the server.
Our problem is that for some local pages, all we get back is a entirely blank page (not even a PDF). The response code is 200, but the content-type is text/html. For those pages where a PDF is successfully streamed to the client, the content-type is application/pdf.
I thought that maybe something goes wrong in the generation of my PDF, so i ran exactly the same commands that PHP executes, and then a PDF was being generated successfully.
I am using the library found on this page to make PHP connect with wkhtmltopdf.
$pdf = new WkHtmlToPdf(array(
'margin-left'=>0,
'margin-right'=>0,
'margin-top'=>0,
'margin-bottom'=>0,
'print-media-type',
'disable-smart-shrinking'
));
$url = "http://myserver.se/$url";
$pdf->addPage($url);
$pdf->send();
Why do i get blank pages back for some URLs?
It turned out, the problem was in the library i was using. I can't tell exactly what the problem was, but proc_close in the send method of the wkhtmlpdf class was returning 2 instead of the expected 0 when a PDF was succesfuly created. This lead to that the library thought that no PDF was created, and it simply returned false meaning nothing was outputted to the client. I solved it by checking if the file existed instead by using PHP's file_exists function.

Selenium 2 & Firefox profiles do not get applied

So i'm stuck, I'm running my script through a proxy which requires HTTP Authentication, however I can't authenticate with #:.. So I decided to create a profile that has the authentication plugin added for FireFox and make it auto input.
I've made the zip base64 file, as I'm running on OSX I used the following commands,
zip -r profile 3rkomsuo.selenium
openssl base64 -in "profile.zip" -out "profile.zip.b64"
The file is 24MBs tho(edit, disabled firebug and now it's only about 4MB, still no luck)? I only added 2 plugins, firebug and Auth plugin, that's tiny! Now I've put the file into my web directory, I'm running MAMP, and I send the profile as described.
$session = $web_driver->session('firefox', array("firefox_profile" => file_get_contents("profile.zip.b64")));
I've checked the POST, send a correct array, i've increased PHP POST size in php.ini to 64MBs just in case, however nothing works, still loads the basic(nothing set up) profile? If anyone could help you would be my hero as I've spent several hours debugging this without any luck!
Managed to set up the profile, make sure you rename prefs.js to user.js and zip the folder contents for the profile, not the profile folder itself!
If making profile is not working in your case then you can handle Authentication dialog by using Autoit.
Write a few line script in autoit.
Compile it to convert it in exe.
Call that exe before the line which causes the authentication dialog to appear.

can you use curl to post to a local file?

I tried using curl to post to a local file and it fails. Can it be done? my two management systems are on the same server and it seems unnecessary to have it traverse the entire internet system just to go to a file on the same hard drive.
Using localhost didn't do the trick.
I also tried to $_SERVER[DOCUMENT_ROOT].'/dir/to/file.php' using post data. It's for an API that is encrypted, so I'm not sure exactly how it works. It's for a billing system I have and I just realized that it sends data back (API).
It's simply post data and an XML response. I could write an html form tag and input fields and get the same result, but there isn't really anything else to know.
The main question is: Does curl have the ability to post to a local file or not?
it is post data. it's for an API that is encrypted so i'm not sure exactly how it works
Without further details nobody can answer then what you should do.
But if it's indeed a POST receival script on the local server, then you can send a POST request to it using the URL:
$url = "https://$_SERVER[SERVER_NAME]/path/to/api.php";
And then receive its output from the cURL call.
$data = curl($url)->post(1)->postdata(array("billing"=>1234345))
->returntransfer(1)->exec();
// (you would use the cumbersome curl_setopt() calls instead)
So you get a XML or JSON or whatever response.
If they're on the same drive, then use file operations instead:
file_put_contents('/path/to/the/file', $contents);
Using CURL should only be done if you absolutely NEED the http layer to get involved for some reason, or if you're dealing with a remote server. Using HTTP would also mean you need to have the 'target' script be able to handle a file upload plus whatever other data you need to send, and then that script would end up having to do file operations ANYWAYS, so in effect you've gone on a round-the-world flight just so you can move from your living room to the kitchen.
file://locafilespec.ext worked for me. I had 2 files in the same folder on a linux box, in a folder that is not served by my webserver, and I used the file:// wrapper to post to file://test.php and it worked great. it's not pretty, but it'll work for dev until I move it to it's final resting place.
Does curl have the ability to post to a local file or not?
To curl local file, you need to setup HTTP server as file:// won't work, so:
npm install http-server -g
Then run the HTTP server in the folder where is the file:
$ http-server
See: Using node.js as a simple web server.
Then test the curl request from the command-line to localhost like:
curl http://127.0.0.1:8081/file.html
Then you can do the same in PHP.

Categories