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.
Related
I'm developing a telegram bot using php and a web hook. All it's fine but sometimes I would like to "wait for a reply" from the user. For example:
If the client write /info without any parameters I would like to show a "usage" message and ask&wait for a ID parameter.
I know there is a property "ForceReply" to force for a reply, but when I set it up nothing happens, and I don't know how to know if the client message its a reply for my question.
Do I have to put my php server on hold? (I think it would be a bad practice) Do I have to whait for a type of message?
Thanks
When you use getUpdates or receive updates via a webhook, the update message will contain a field like reply_to_message field. You can use this to compare it to the message you sent.
If you are running your script via webhooks I would assume that it only executes when it receives a message. If so, I would suggest you use something like memcache/redis to store the message you are expecting a reply for and then when the reply comes, you can compare it to the value stored:
<?php
// This script triggers as a webhook
$message = file_get_contents('php://input');
$message = json_decode($message, true);
$cache = new RedisClient('localhost');
if ($message->reply_to_message == $cache->get('original.message.id'))
{
var_dump('message reply received');
}
The example above is some "pseudo" code that you can use in a webhook to check for a reply to a specific message.
i have question about sending and getting data from server, i just want to know is it doable what i want to achieve. So here is the thing:
i have some data that i want to send to server, like some id, name, surname
and i have server with ip 256.257.258.259, server waits for request with values encoded in url, so i can send data to server somehow like this:
$data = array(
'id'=>'c456ki98765',
'name'=>'john',
'surname'=>'smith');
$urlstring = http_build_query($data);
$url = 'http://256.257.258.259/folder/automatic?'.($urlstring);
i have a question there, should i use GET request to send this kind of data?
and would it look something like this?
$request = new HttpRequest('url', HttpRequest::METH_GET);
and when server gets my data it sends back response - for example json data - 'number' string or 'error' string if id is wrong. And i have another question there, how can i get data that server sends me after i have sent request?
how can i get that 'number'or 'error'? i hope i have made my question clear
You can use either a POST or a GET request depending on your requirements
Your $request is fine for setting up the request but then you need to send it:
$request->send();
and will need to do something with the response code:
$request->getResponseCode()
Hopefully the below links will come in handy (especially the bottom on in this case):
http://www.php.net/manual/en/function.http-get.php
http://www.php.net/manual/en/function.http-post-data.php
http://www.php.net/manual/en/httprequest.send.php
I am trying to handle Mandrill's webhook data when I get a bounce I want Mandrill to tell my app which email it was and save various data in a MySql Database.
I am working with PHP here, according to Mandrill they send a URL I give them a $_POST request with JSON data.
Normally I would json_decode() this request, but when I do so, it appears to be blank. To me the JSON looks malformed, but perhaps I need to do something else with it first?
This is what I receive in my script:
[mandrill_events] =>
[{\"event\":\"hard_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook#mandrillapp.com\",\"sender\":\"example.sender#mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"bad_mailbox\",\"bgtools_code\":10,\"diag\":\"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces.\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"ts\":1390483382},{\"event\":\"soft_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook#mandrillapp.com\",\"sender\":\"example.sender#mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"soft-bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"mailbox_full\",\"bgtools_code\":22,\"diag\":\"smtp;552 5.2.2 Over Quota\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"ts\":1390483382}]
You have the magic_quotes option set in your server.
You can disable it, or simply remove the trailing slashes from the response and then do the json_decode:
$response = json_decode(stripslashes($_RESPONSE['mandrill_events']), true);
More information about stripslashes: http://php.net/manual/en/function.stripslashes.php
I have been struggling with the following problem for few days. I am expected to receive POST data from a third party company for certain real time events. I have been in contact with them as to why my script isn't seeing anything. Unfortunately, they are less then helpful and just tell me "it works for everybody else".
I setup a simple PHP script after doing some research on the web but it always shows no post data. This isn't my area of expertise so I may be missing something obvious.
Here is the only documentation they give:
This API will send a real-time http request upon every successful event with all of the conversion data. The data is sent via an http POST method, and the data is JSON formatted.
This is my script which for now is trying to just log it to a file. The file is created and I see the IP address of the request but the output is empty in terms of post data.
ob_start();
echo "Request from :" . $_SERVER[REMOTE_ADDR];
echo "print_r:".print_r($_POST,true);
if(array_key_exists('app_id', $_POST))// me attempting to access a specific key they claim is in the post data
{
echo "app id = " . $_POST['app_id'];
}
//I also tried both of these and neither output anything
//foreach ($_POST as $key => $value) //idea 1
foreach($_POST as $item) //idea 2
{
//echo "key=".$key." value=".$value; //idea 1 log
echo "next=";//idea 2 log
echo $item;
}
$contents = ob_get_flush();
file_put_contents("log.txt",$contents,FILE_APPEND);
There's not a lot to go on here -- who knows what the client is actually sending -- but here's a thought:
POST is just an HTTP command. It's traditional for the body of a POST to be a series of key-value pairs from a form, but it is not actually necessary. It's possible that the remote client is issuing a POST request to your server and then just delivering a JSON blob in the request body, which would not be successfully parsed into the $_POST array.
I recommend exploring the answer at How to get body of a POST in php? to see if that helps shed light on this problem.
I've got a problem when checking for a response error after sending a Push Notification. This is my setup:
From my PHP server, I'm sending Push Notifications. These notifications are send in the enhanced format, so I can get an error response from the Apple server. For example: Error #7 "Invalid payload size".
The way I check for errors is reading the socket response:
const ERROR_RESPONSE_SIZE = 6;
$errorResponse = #fread($this->_apnsSocket, self::ERROR_RESPONSE_SIZE);
This works fine when there is an actual error. By my problem is: when there's no error, the "fread" call doesn't return anything and keeps loading forever.
Can anyone help me with this? Thanks for your help!
You need to set stream_set_blocking($this->_apnsSocket, 0); to 0 which is non-blocking mode, because on success Apple doesn't send back anything, but the fread is waiting for data in blocking mode.