Very weird Date behaviour by PHP/MySQL and iOS - php

I'm porting my Android app to iOS and I'm at the chat stage.
Each message has its own date, and my server API (in PHP) has a method that fetches all messages since a date (so I can send a request with my lastMessageDate and get any new messages that are not on the device whenever needed)
My database is MySQL and the server's timezone is GMT+2. The DB saves all dates as GMT+2, and PHP sends them as string back to the client.
In Android, and in my REST client for testing, calling the following request gives the "No new messages" message, as it should:
In iOS, since the OS translates all Dates to UTC, before sending the date, I turn in into a GMT+2 string. I've been testing and debugging this date string, and it is indeed in GMT+2, as my server expects it to be.
Printing with the debugger the POST params before sending the request, shows that the time is indeed in GMT+2:
Params: ["since": "2017-03-15 21:16:04", "chat_id": "86", "username": "testuser"]
However, sending the exact same request, as in my REST client, returns chat messages that have been posted the past 2 hours, like if the iOS app is sending the UTC date instead of my GMT+2 string.
The response in the iOS emulator is the following:
Received data is:
{
"message" : "Messages in this chat:",
"messages" : [
{
"message" : "This is a message",
"chat_id" : "86",
"who" : "1",
"date" : "2017-03-15 21:16:04"
}
],
"error" : false
}
I've been trying to debug this for the past 4 hours with no luck. I don't know if it's the server's fault or iOS' fault, so if anyone can point me to the right direction, it would be very much appreciated. Thank you

Turns out I need to encode the request with Alamofire.URLEncoding.httpBody instead of Alamofire.JSONEncoding.default in order for PHP to be able to check for parameters using isset($_POST["since"]). I didn't face this problem before, in the other 40 API calls that my app encodes with Alamofire.JSONEncoding.default.
If anyone can explain when it's best to encode using URLEncoding and when JSONEncoding, let me know.
Thanks to everyone who tried to help!

Related

Invalid Drm Argument Exception Validating App Store Receipt

let url = Bundle.main.appStoreReceiptURL!
let receipt = NSData(contentsOf: url)?.base64EncodedString(options: [])
The receipt string works well when I send it to Apple servers, but when my server sends it i get this error:
"status":21002, "exception":"com.apple.its.drm.InvalidDrmArgumentException"
I have no clue why, especially since it was working yesterday.
Turns out the HTTP POST function variables were all being sent to APPLE.
I had thought the receipt=XXX&key=1234 were separated in the PHP Server side code.
But the '&' wasn't there so the receipt sent to Apple was XXXkey=1234
so com.apple.its.drm.InvalidDrmArgumentException means that the receipt data has an error/ extra data.

How to receive uplink data on my webpage from Sigfox server?

I am a new bee to sigfox. I want to receive sensors' data from sigfox server to my webpage. I defined a callback function as in the pic below in sigfox. I want to know how to receive the JSON data in my webpage. My web page is running on a personal apache web server with a public ip.
I am using php. Like normally use a curl call to receive json from any server using its URL. Here in sigfox case, what source i.e. url I specify in curl to retrieve json data from it. OR what mechanism to use. I searched web & forum but didn't find any answer. Sigfox has a nice description about how to receiver data to an email but not for a custom url.
The body of the callback should be something like this
{
"deviceId": "{device}",
"time": {time},
"seqNumber": {seqNumber},
"data": "{data}",
"reception": [{ "id": "{station}", "RSSI": {rssi}, "SNR": {snr} }],
"duplicate": {duplicate},
"ack": {ack},
}
Other parts in your config seem ok, just write your endpoint in sigfoxdata.php to handle the data (eg. parse it).

Weird response from Exact Online API using Auth 2.0

I was able to download some PHP code from exact online to connect to their API. Using this, I get logged in and get all the data such as my access token.
Now, when I do a simple http get on start.exactonline.nl/api (exactly as stated on their website), I get a 755 character string back with no meaning to me at all. Below a part of this string, just as an example, the original string I get back is way longer.
¶¨ÿ}6^¾œïvt6ù’Ì>L!3EOï>%àJ¿÷J'ó ü¸ßßAèðh”H ¥ÓÏx™1ëˆÒÝnçïú~©Vtþ•îèÍ”è ãsýëvkäÎa_äRÿÇÃ#ãTaàôþÞˆíØKiP2?¬Ñƒ´^=ƒ{CBiÆ”F3º$WWƒ! =ꨌ09^!x’lc²R‰?È#¸ISÔ„ŽR ¾A0%Q/­Q¢­\äÀ¢^.ËxÁÒ+Un$:ÓjÄÏíÖR`ÎmØãšq.ä* ¬÷îagñ3´[Yx|ÕïùÖÀ‹±´ÌKuf³™
I should actually get an Json package back I suppose, or an error message, but I get this back.
Has anybody have a clue as to what is going on here or what I could check?
Make sure you add CURLOPT_ENCODING => '' to your cURL call, what you're receiving is a raw gzipped file.

PHP back-end to output a JSON response

I'm new to back end development and i'm trying to learn back end development. What i want is to create a backend using PHP which should output a json response.
For example if there's a field called First Name in my backend,and when i update that field, I want the updated name in a json response so i can display the outputs in my android app.
Sorry for being a noob.
Just point me some tutorials to learn and any further tips would be appreciated.
Outputting JSON is quite simple, you first set an HTTP Response Header and then print the JSON content. The response header is to tell the receiving application (client) what type of data to expect.
A simple example:
header('Content-Type: application/json');
echo json_encode(array(
'name' => "Your Name"
));
You didn't mention if you were using a framework or not, but frameworks like Laravel or Lumen make this kind of thing easy.
Here's a tutorial that might be of use to you.

Getting 500 error in PayPal REST API

I'm using "paypal/rest-api-sdk-php" in my PHP application, been testing perfectly in the sandbox for past month. Moved to LIVE tonight to finish pre-prod testing and now getting this response.
[03-12-2014 01:46:32] PayPal\Core\PPHttpConnection: FINE: Response : {"name":"INTERNAL_SERVICE_ERROR","message":"An internal service error has occurred","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"9a4e0771d4d79"}
Any suggestions as I have searched and not found a suitable answer.
Here is the payload I'm sending (removed URL returns for safety)
PayPal\Core\PPHttpConnection: FINE: Payload :
{"intent":"sale","payer":{"payment_method":"paypal"},"redirect_urls":
{"return_url":"XXX","cancel_url":"XXX"},"transactions":
[{"amount":{"currency":"USD","total":"37.50","details":
{"shipping":"0.00","handling_fee":"2.50","tax":"0.00","subtotal":"35.00"}},"item_list":
{"items":[{"name":"Full Event","description":"This is a full event membership","sku":"547e5ff327a7c","currency":"USD","quantity":1,"price":"35.00"}]},"description":
"Purchase from Site","invoice_number":"547e69aad333b"}]}
Looks like the item description from your request exceeds the maximum number of characters, can you post your complete API request.
This is the error from the logs for this transaction
value too large for column ITEM_DESCRIPTION (actual: 142, maximum: 100),
Strangely, I was able to run the samples with a very long text, and it worked just fine on sandbox.

Categories