how to get the status of twillio sending sms - php

i m trying to send a SMS from my trail Twilio account. so please help to get sms response/status
$client = new Client(TWILIO_SID, TWILIO_TOKEN);
$client->messages->create(
$mobile,
array(
'from' => TWILIO_FROM_NUMBER,
'body' => $mobile_message,
//'statusCallback' => "https://requestb.in/v9uqy6v9"
'statusCallback' => base_url()."sms_status.php"
)
);
//$status = file_get_contents('https://requestb.in/v9uqy6v9');
$status = file_get_contents(base_url()."sms_status.php");
when i run the above code i got error:
Message: file_get_contents(http://.../sms_status.php): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
while i manually browse the sms_status.php file url than it's not got any error
i also follow this link How to get notified when SMS Status changes from 'Queued' to 'Sent'?
so please help me to resolve above problem and also define what will be format of output like json/text/array.....

Twilio developer evangelist here.
When you set a statusCallback URL for an SMS message that you send, the URL needs to point to an application that can handle an incoming HTTP request.
When the status of the SMS message changes through queued, failed, sent, delivered, or undelivered Twilio will make an HTTP POST request to your URL, sending all the standard request parameters as well as two extra parameters; MessageStatus and ErrorCode. The parameters will be sent as URL encoded form parameters, so you should be able to read them using PHP's $_REQUEST[] syntax.
So, make sure your application can receive HTTP requests at the statusCallback URL and you can log the data out from there however you want to.
Let me know if that helps.

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.

php webhook not responding to Stripe test event

I've setup a basic webhook php page as modeled on the stripe documentation and listed below. When I send a test event from the Stripe webhooks dashboard, stripe responds "Test webhook sent successfully" with a blankk reponse. However, the output log file is not written to, no email is sent and there is nothing logged to the http server error log or the php error log. My php version is 5.3.3. What am I doing wrong?
<?php
error_reporting(15);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("secret_test_key");
$handle = fopen("webhook.log","a");
// Retrieve the request's body and parse it as JSON
$input = file_get_contents("php://input");
$event_json = json_decode($input);
// Do something with $event_json
if (fwrite($handle, $event_json) === FALSE) {
mail("mike#example.com","Cannot write to webhook.log","");
echo "Cannot write to webhook.log";
exit;
}
mail('mike#example.com','Webhook Event',$event_json);
header(':', true, 200);
//http_response_code(200); // PHP 5.4 or greater
?>
You have a few potential problems. As a quick rule of thumb, the best way to debug this is to start by triggering the event yourself, which you can do simply by loading up your webhook url in a browser yourself. Then you can test it directly and make sure it is doing what you expect it to be doing. There are obviously two possibilities:
Stripe is not triggering your webhook handler for some reason
Your handler is not properly logging itself
The latter first: it could be that Stripe is triggering your handler but it isn't logging that fact successfully. This would mean that both your email logging and file logging are failing. That is actually quite possible. Email logging with the mail function is actually very unreliable, unless you know for a fact that it works. Mail sent with the mail function is dropped silently by most modern email systems (gmail, etc) unless you have your DNS records properly configured, which most people don't. So unless you know for sure that your mail attempt is working properly, it probably isn't. If you also happen to have a permission issue in your attempt to write to a log file (which is not uncommon for a newly setup server), your logs could simply be failing. The easiest way to check that is to load up the webhook URL in a browser yourself. That way you know it is being triggered, and can know for sure if the issue is improper logging or Stripe not calling your webhook.
If you determine for sure that stripe isn't calling your webhook, the most likely culprit would be an invalid HTTPS certificate. Is your webhook connected via HTTPS (it should be)? If so, is it a valid certificate? You can tell your browser to ignore an invalid certificate when you browse your own site, but stripe will simply refuse to send the request if it encounters an invalid certificate.
If none of the above fixes it then it will be time for more digging, but I would start with those: they are probably the most likely problems.
The solution is that $event_json is an object and the fwrite failed because it expects a string not an object. By converting to an array and then serializing I was able to both write to the log and send the email.
$event_json = (array)json_decode($input);
$event = serialize($event_json);

php http post response for web hook

I'm trying to create a web hook notification. The documentation of the service i want to use requires that i specify a URL where POST requests can be performed. This URL will receive the following object, in json format, and must respond with a Status Code between 200-299.
{
"type": "ping"
}
I don't know how to proceed making my server on localhost respond with a 200 status code. http_response_code(200) works well on live server but nothing seem to be happening on localhost.
Is there any way i can make it work with localhost?
I've included the link to the documentation here (i hope it's not against the rule).
I am thinking that you wouldn't have to send them the response. The webhook would know about the response. If it reached your URL successfully, it would be a 200 OK right off the bat. If the API is requesting a response back then I imagine that you would have to call it back somehow. Is this a well-known API? Any documentation?
The response code is in the response header, not in the content.
PHP defaults to a response code of 200, so if you don't mess with it at all, you should be good.
If you want to set a different response code (202 for example), just call:
http_response_code(202);
Or set the full header yourself:
header('HTTP/1.1 202 Accepted');
Proper way to explicitly set 200 (or any other) status code with http_response_code function is just as following (don't echo or json_encode it):
http_response_code(200);
It should force webserver to use 200 status code in it's response. However, webserver could possibly ignore it. To check what response code your webserver sends, use telnet or any REST tool like Postman

How to create a Webhook server like Telegram Webhook

I need to create a Webhook server like Telegram Webhook server.
I googled it but didn't find any resources!
I'm not talking about receiving Webhook requests. I'm talking about creating a complete Webhook server to send HTTP POST requests to specific URLs. And our clients could receive the requests in their URLs by :
$response = file_get_contents('php://input');
Any helps would be great appreciated.
P.S:
Sorry for my bad English.
you can try Captain Hook laravel package, which provides you to add webhook to your laravel application
What a webhook actually does is nothing more than sending a request. The most easy way to set this up is by using Guzzle (https://packagist.org/packages/guzzlehttp/guzzle).
What you need to set up is on your side a script which decides what url to call, when that happens, just create the post request via guzzle.
$postData = [];
$client = new GuzzleHttp\Client();
$response = $client->request('POST', $url, $postData);

Guzzle asynch request not working

I'm using Guzzle that I installed via composer and failing to do something relatively straightforward.
I might be misunderstanding the documentation but essentially what I'm wanting to do is run a POST request to a server and continue executing code without waiting for a response. Here's what I have :
$client = new \GuzzleHttp\Client(/*baseUrl, and auth credentials here*/);
$client->post('runtime/process-instances', [
'future'=>true,
'json'=> $data // is an array
]);
die("I'm done with the call");
Now lets say the runtime/process-instances runs for about 5mn, I will not get the die message before those 5mn are up... When instead I want it right after the message is sent to the server.
Now I don't have access to the server so I can't have the server respond before running the execution. I just need to ignore the response.
Any help is appreciated.
Things I've tried:
$client->post(/*blabla*/)->then(function ($response) {});
It is not possible in Guzzle to send a request and immediately exit. Asynchronous requests require that you wait for them to complete. If you do not, the request will not get sent.
Also note that you are using post instead of postAsync, the former is a synchronous (blocking) request. To asynchronously send a post request, use the latter. In your code example, by changing post to postAsync the process will exit before the request is complete, but the target will not receive that request.
Have you tried setting a low timeout?

Categories