iPhone Feedback Service with PHP - php

HI All,
Has anybody been able to extract the device tokens from the binary data that iPhone APNS feedback service returns using PHP? I am looking for something similar to what is been implementented using python here
http://www.google.com/codesearch/p?hl=en&sa=N&cd=2&ct=rc#m5eOMDWiKUs/APNSWrapper/init.py&q=feedback.push.apple.com
As per the Apple documentation, I know that the first 4 bytes are timestamp, next 2 bytes is the length of the token and rest of the bytes are the actual token in binary format. (http://developer.apple.com/IPhone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3)
I am successfully able to extract the timestamp from the data feedback service returns, but the device token that I get after i convert to hexadecimal using the PHP's built in method bin2hex() is actually different than original device token. I am doing something silly in the conversion. Can anybody help me out if they have already implemented APNS feedback service using PHP?
TIA,
-Anish

PHP technique to query the APNs Feedback Server

The best place to go for this is actually the Apple developer forums in internal to the iPhone portal - the have a bunch of examples in different languages for working with these push requests.
I'm also currently at an 360iDev push session, and they noted an open source PHP server can be found at:
http://code.google.com/p/php-apns/

Once you have your binary stream, you can process it like this:
while ($data = fread($stream, 38)) {
$feedback = unpack("N1timestamp/n1length/H*devtoken", $data);
// Do something
}
$feedback will be an associative array containing elements "timestamp", "length" and "devtoken".

Related

How to pass field values from database hosted on a server to android app using php?

I have a database hosted on server whose field values have to be passed to my app. I would like to do with PHP. But people suggest me to use JSON too. Is JSON required? Please guide me how to pass the field values to android app.
JSON means JavaScript Object Notation and it's just a way of formatting your output in a standard way.
So, if you'd like to pass data from a database to an application, you'd need to implement a small API. This can be done using PHP. At this point, you can access data from your database using a browser and parametrizing your queries using url parameters.
PHP can render the data in a simple HTML table for example, but this is just a way of presenting your data. You can also use JSON.
This means that if you need the badges a user has earned, you'll use something like this:
<link_to_your_api>/index.php?method=getBadges&user=<user>
This in turn, will make a request to the database
<?php
// 1. connect to database
// 2. query for the information
// 3. get the result as array
$result = $db->getData();
echo json_encode($result);
?>
This is just an example, hope it helps.
link to json documentation: http://www.json.org/
You pass the data to your app, when it makes a request to your PHP script. JSON is handy because you can package your data in a format, that is both well readable by humans and machines. You can use the gson library then, to process the JSON data in your app.
Create REST api using any server side script PHP,nodejs or any you like which returns JSON response
call the rest api using http request which returns JSOn text
decode the JSON string to JSON object and use with your android code

PHP url - Is this a viable hack?

Following on from this question, i realised you can only use $POST when using a form...d'oh.
Using jQuery or cURL when there's no form still wouldn't address the problem that i need to post a long string in the url.
Problem
I need to send data to my database from a desktop app, so figured the best way is to use the following url format and append the data to the end, so it becomes:
www.mysite.com/myscript.php?testdata=somedata,moredata,123,xyz,etc,etc,thisgetslong
With my previous script, I was using $GET to read the [testdata=] string and my web host told me $GET can only read 512 chars, so that was the problem.
Hack
Using the script below, I'm now able to write thousands of characters; my question, is this viable or is there a better way?
<?
include("connect.php"); //Connect to the database
//hack - read the url directly and search the string for the data i need
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$findme = '=';
$pos = strpos($actual_link, $findme) + 1; //find start of data to write
$data = substr($actual_link, $pos); //grab data from url
$result = mysql_query("INSERT INTO test (testdata) VALUES ('$data')");
// Check result
if ($result) {echo $data;}
else echo "Error ".$mysqli->error;
mysql_close(); ?>
Edit:
Replaced image with PHP code.
I've learned how not to ask a question - don't use the word hack as it riles peoples feathers and don't use an image for code.
I just don't get how to pass a long string to a formless PHP page and whilst i appreciate people's responses, the answers about cURL don't make sense to me. From this page, it's not clear to me how you'd pass a string from a .NET app for example. I clearly need to do lots of research and apologise for my asinine question(s).
The URL has a practical fixed limit of ~2000 chars, so you should not be passing thousands of chars into the URL. The query portion of the URL is only meant to be used for a relatively short set of parameters.
Instead, you can build up a request body to send via cURL/jQuery/etc for POSTing. This is how a browser will submit form data, and you should probably do the same.
In your scenario, there are two important elements that you need to examine.
First, what is the client that is performing the http operation? I can't tell from your text if the client is going to be a browser, or an application. The client is whatever you have in your solution that is going to be invoking a GET or POST operation.
This is important. When you read about query string length limitations online, it's usually within the context of someone using a browser with a long URL. There is no standard across browsers for maximum URL length. But if you think about it in practical fashion, you'd never want to share an immensely large URL by posting it somewhere or sending it in an e-mail; having to do the cut-and-paste into a client browser would frustrate someone pretty quickly. On the other hand, if the client is an application, then it's just two machines exchanging data and there's really no human factor involved.
The second point to examine is the web server. The web server implementation may pose limitations on URL length, or maybe not. Again, there is no standard.
In any event, if you use a GET operation, your constraint will be the minimum of what both your client AND server allow (i.e. if both have no limit, you have no limit; if either has a limit of 200 bytes, your limit is 200 bytes; if one has a 200 byte limit and the other has a 400 byte limit, your limit is 200 bytes)
Taking a look back, you mentioned "desktop app" but have failed to tell us what language you're developing in, and what operating system. It matters -- that's your CLIENT.
Best of luck.

Amazon MWS (PHP) - How does the request work

I am trying to pull a report in PHP for active listings.
I've made progress, however, I cannot understand how this works and there is nothing out there that can explain it.
For example, in the Samples provided from the PHP library, I see quite a few XML files. When you run the RequestReportResponse sample, does that generate the XML file, or does the XML file tell the RequestReportResponse what to do based on values and functions?
I am asking because, with the MWS Scratchpad - I select all the necessary fields, submit it then refresh the Amazon Reports page of my seller central section and it shows a pending report.
I'm just asking how the XML content affects the report or how the report can affect the XML.
The answer to your question comes in two parts.
Part 1 - Calling the Amazon API
Most MWS requests do not require any file (be it plain text or XML) to be sent to Amazon. For example, all parameters needed to do send RequestReport can (and must) be sent as regular parameters. I'm not sure what Amazon would do if you did submit a file along with it as I've never tried. But then again... why would you?
One of the calls that does require a file to be send is the SubmitFeed call where that file is the actual feed to be submitted. It depends on the type of feed you're submitting if Amazon expects it to be plain text or XML.
Part 2 - Handling Amazon's API responses
When you get information back from Amazon's API, it usually is in XML format (there are a few calls that may return plaintext instead). You will need to decode this data to get your information out.
To make it a bit clearer, I'll outline a typical process for you:
The process of getting all your listings from Amazon:
Do a RequestReport call to Amazon. No XML attached
Decode the XML that you're getting back (it is a RequestReportResponse). If all went well, you'll get a RequestReportId as part of the response, and Amazon will start processing your request.
Amazon may need a few minutes to actually create the report, in cases of very complex or large requests or during high activity hours it may actually take up to an hour or more. So we need to find out when the request we made is actually done.
Poke Amazon API with a GetReportRequestList call asking for the status of your request with ReportRequestIdList.Id.1={YourRequestIdHere}. This also does not need a XML attachment.
Decode the XML that you're getting back. (it is a GetReportRequestListResponse)
If its ReportProcessingStatus is not _DONE_, wait for at least 45 seconds, then repeat from step 3. If the report is actually done, you'll see a valid GeneratedReportId in the response. If it is missing, you'll need to do an extra GetReportList call to find its ID.
Call GetReport to finally fetch your report with ReportId={YourGeneratedReportIdHere}
Decode whatever you're getting back. Depending on the type of report you requested, the response may be XML or plain text.
This process is explained in detail (and with a pretty flow chart) in Amazon Marketplace Web Service Reports API Section Reference (Version 2009-01-01)
To finally answer your question with respect to getting active listings from Amazon MWS:
None of the three calls require you to send XML to Amazon. The data you receive from Amazon will be in XML format (with the possible exception step 6 if you requested a plain text report).

iphone apns sending push notification in different languages with voice

i have studied and implemented Ray wenderlich's awesome tutorials on apns, and i am using this php script on server side
https://github.com/sebastianborggrewe/PHP-Apple-Push-Notification-Server
every thing is going well, but i just want to know that how can i send push notification in a language other than english, like arabic, urdu, hindi or french...???(i am sending notifications from php server using a web form) this is first part of question, the other part is that can i send a voice message with push notification, i know that there is a property for sound in apns but dont know its max. length (max length of push notification is 256 bytes). plz. guide me thanx and Regards Saad.
Sound support is limited to playing audio files of the app (you include PushSound.aiff in your app and send "PushSound.aiff" in your apns-message.. that's all you can do!)
For localization, you [need to include localized strings in your app and then include the String-Key(ID) in the push message.
You should read the guide apple provides for all questions regarding push notifications
To add localized strings, you can add a strings file (file->new, select iOS/Resource->Stringsfile; name it Localizable.strings). You can add format strings ("%# has sent you a new message") and supply the format string's arguments in the push notification (see guide).
Again there is a internationalization guide

JSON Encoding - Get MySQL data to an iPhone

Im new to JSON and have whats probably a basic question. I have some MySQL rows I want grab with Php, and then JSON encode for a response to an iphone request.
so the questions are:
1) Whats the format for the array to encode this info?
2) Where the does the response code (200) fit into it?
Try this tutorial. http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/
Basically on the PHP side, write a script that fetches the MySQL data and then echo back the output of json_encode. The iPhone side will call to the URL of this script using the method above.
I would suggest you take a look at json.org and familiarize yourself with the JSON format.
1) On the Obj-c side of things, have you heard of Stig's JSON framework? https://github.com/stig/json-framework
I use it in my iPhone apps and it works very well for encoding and decoding JSON. Are you interested in the the format for the array to encode the information on the iPhone side or server side? You should create the array in the way that makes the most sense and then make sure the iPhone side is reading the array the same way the PHP side sends it.
2) The HTTP 200 response code simply means your request has succeeded. As opposed to like a 404 or something where the webpage doesn't exist.

Categories