I purchased a number of messages , and followed all the steps
including
1. access token
2. client id and secret id
but the sms never reach the mobile number
iam using this code based on the api documentation
<?php
require 'Path to Osms ';
use \Osms\Osms;
$config = array(
'token' => 'my token'
);
$osms = new Osms($config);
$senderAddress = "tel:+200000";
$receiverAddress = "tel:+20 my number";
$message = "Hello World!";
$senderName = "Optimus Prime";
$osms->sendSms($senderAddress, $receiverAddress, $message,
$senderName);
what happens is that the number of messages at the website keeps decreasing , but the sms never arrives the mobile
Use this library instead of what you've used !
More explications are here
Related
I have successfully implemented webhook integration using Sandbox in Paypal.
Now I want to make it more secure so that only Paypal signed notification is accepted.
I was trying to verify webhook signature using
https://developer.paypal.com/docs/api/webhooks/v1/#verify-webhook-signature_post
But it always returns FAILURE.
The request is :
{"auth_algo":"SHA256withRSA","transmission_time":"2020-08-17T12:11:08Z","cert_url":"https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-1d93a270","webhook_id":"0JD18557VD498931R","transmission_id":"bbaae190-e082-11ea-aa52-1fdbf2bc8461","webhook_event":{"summary":"Payment completed for $ 5.0 USD","event_type":"PAYMENT.SALE.COMPLETED","create_time":"2020-08-17T12:11:05.015Z","resource":{"billing_agreement_id":"I-DNVD3H9UWYHL","amount":{"total":"5.00","currency":"USD","details":{"subtotal":"5.00"}},"payment_mode":"INSTANT_TRANSFER","update_time":"2020-08-17T12:10:39Z","create_time":"2020-08-17T12:10:39Z","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","transaction_fee":{"currency":"USD","value":"0.45"},"protection_eligibility":"ELIGIBLE","links":[{"method":"GET","rel":"self","href":"https://api.sandbox.paypal.com/v1/payments/sale/8TV124151P468690Y"},{"method":"POST","rel":"refund","href":"https://api.sandbox.paypal.com/v1/payments/sale/8TV124151P468690Y/refund"}],"id":"8TV124151P468690Y","state":"completed","invoice_number":""},"resource_type":"sale","links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2XT265922L1486124-74F09092JL7840709","rel":"self","targetSchema":null,"method":"GET","enctype":null,"schema":null},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2XT265922L1486124-74F09092JL7840709/resend","rel":"resend","targetSchema":null,"method":"POST","enctype":null,"schema":null}],"id":"WH-2XT265922L1486124-74F09092JL7840709"},"transmission_sig":"RYILWohVPkK0hUrMjTSU3+fCgd6NTgqkjrZtsOJiC7FR3U3atOK1k29/Md8DQRReAicdfOpXrS7E4vrvB17HOM39w/D3i4Ohy34HL3CqSsZovL69lhfFmviCGkXjjSbkBhpKGJvQAB4q0E9AWl/SBZc4MUNGezIbk/laJZ6ikQuwGeEHCFaPVrza7kSlZRo03lM9sYSb7q3ixewYmz8voKIyJ2RYjOgsAohNFWgovtKwG+ac66YCp3ZRJLe4fL2Q1UaEDn5BnUhK+5Q2+EqD+BixpqNTuSmYqRwkyDTdrH1EPV5DRU4uYM0gJLXnBovGaqHe8JujpVs+dJu4Mrmgdg=="}
and the result is
{"verification_status":"FAILURE"}
Can someone help, please !!
If you are getting those values from the webhook simulator as they said in their documentation you can't verify mock webhooks.
What I used to do when I need to validate the value because some test need that part it's that using the smart buttons to generate the request and then catch the response in some webhook.
Verify Paypal webhook notification
How to verify the authenticity of the notification in php:
// get request headers
$headers = apache_request_headers();
// get http payload
$body = file_get_contents( 'php://input' );
// compose signature string: The third part is the ID of the webhook ITSELF(!),
// NOT the ID of the webhook event sent. You find the ID of the webhook
// in Paypal's developer backend where you have created the webhook
$data =
$headers['Paypal-Transmission-Id'] . '|' .
$headers['Paypal-Transmission-Time'] . '|' .
'<WEBHOOK ID FROM THE DEVELOPER DASHBOARD>' . '|' . crc32( $body );
// load certificate and extract public key
$pubKey = openssl_pkey_get_public( file_get_contents( $headers['Paypal-Cert-Url'] ) );
$key = openssl_pkey_get_details( $pubKey )['key'];
// verify data against provided signature
$result = openssl_verify(
$data,
base64_decode( $headers['Paypal-Transmission-Sig'] ),
$key, 'sha256WithRSAEncryption'
);
if ( $result == 1 ) {
// webhook notification is verified
} elseif ( $result == 0 ) {
// webhook notification is NOT verified
} else {
// there was an error verifying this
};
The transmission id, the transmission date, the webhook id and a CRC over the HTTP body. The first two can be found in the header of the request, the webhook id in the developer backend (of course, that id will never change), the CRC is calculated like shown below.
The certificate's location is in the header, too, so we load it and extract the private key.
Last thing to watch out for: The name of the algorithm provided by Paypal (again in a header field) is not exactly the same as understood by PHP. Paypal calls it "sha256WithRSA" but openssl_verify will expect "sha256WithRSAEncryption".
I have configured Twilio phone number and given settings as per the documentation. On the callback URL i have written code like this
Route::post('/replyMessages', function(){
Log::info('inside reply messages URL');
$response = new \Twilio\TwiML\MessagingResponse();
Log::info(print_r($response, true));
$message = $response->message("Testing sms from twilio to staffing backbone");
print_r($response);
Log::info('SMS reply URL callback');
});
When user is replied from their mobile nothing is happening. If URL hits the log, then it will print the text given but not working. Kindly help me on this.
As per one of the document in Twilio they are expected to install ngrok is that necessary in order to call our URL? documentation link
ngrok is not explicitly required, it's just recommended as an easy way to make your local development environment accessible from outside of your network.
If the code is running on your local development machine, ensure that you able to query that endpoint from a device outside of your network (eg, from a mobile phone with wifi turned off). If not, ngrok will help with this.
If the code has been deployed to a server that is already publicly accessible, query it and ensure there are no errors being output.
Original answer (related to code snippet):
Try switching out print_r($response); with echo $response;.
print_r will be outputting the structure of the MessagingResponse object, whereas echo will cast your $response to a string and output the XML payload that Twilio is expecting.
Your current payload probably looks something like this:
Twilio\TwiML\MessagingResponse Object
(
[name:protected] => Response
[attributes:protected] => Array
(
)
[children:protected] => Array
(
[0] => Twilio\TwiML\Messaging\Message Object
(
[name:protected] => Message
[attributes:protected] => Array
(
)
[children:protected] => Array
(
[0] => Testing sms from twilio to staffing backbone
)
)
)
)
=> true
But Twilio will be expecting an XML payload as below:
<?xml version="1.0" encoding="UTF-8"?>
<Response><Message>Testing sms from twilio to staffing backbone</Message></Response>
Since it's a POST request, I'm guessing the VerifyCsrfToken middleware is stopping this request.
Add 'replyMessages' to the $except array in app/Http/Middleware/VerifyCsrfToken.php file, so it should end up like this:
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* #var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* #var array
*/
protected $except = [
'replyMessages'
];
}
As per checking my configuration is correct and there is some problem in the Twilio.
The initial mobile which we have tried for sending replies and it is recording log and everything works but it is not triggered the callback URL. Later we have tried to reply from new mobile number it worked. Nothing changed in the configuration. So following up with Twilio on the resolution.
Thanks all for the help.
i want this to be converted into php, anyone please. i am doing marketing application coding to send bulk sms
from flask import Flask, request
from twilio.rest import TwilioRestClient
app = Flask(__name__)
# put your own credentials here
ACCOUNT_SID = 'YOUR_ACCOUNT_SID'
AUTH_TOKEN = 'YOUR_AUTH_TOKEN'
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
#app.route('/sms', methods=['POST'])
def send_sms():
message = client.messages.create(
to=request.form['To'],
from_='YOUR_TWILIO_PHONE_NUMBER',
body=request.form['Body'],
)
return message.sid
if __name__ == '__main__':
app.run()
Twilio developer evangelist here.
There is a whole page of documentation on how to send an SMS using Twilio and PHP right here.
In short though, to replicate the Python, you should download or install the PHP helper library to your project. Then this code should work:
<?php
require_once "vendor/autoload.php";
use Twilio\Rest\Client;
$AccountSid = "YOUR_ACCOUNTS_SID";
$AuthToken = "YOUR_AUTH_TOKEN";
$client = new Client($AccountSid, $AuthToken);
$sms = $client->messages->create(
$_REQUEST['To'],
array(
'from' => "YOUR_TWILIO_NUMBER",
'body' => $_REQUEST['Body']
)
);
echo "Sent message";
I recommend for the full instructions to follow the documentation.
I'd like to have something like what the app.net site has. You click a button and get the option to send a link to your phone via SMS (or email). What are some options for implementing the sms side of things, and are there services or open source packages that provide this?
Here's a random example from app.net . Click the "Get this App" button to see what I mean.
Something like this would even work for me Send link to Phone Where "saasSMS.com" is some service that handles the whole sms side of things. Ideally could either handle that via a link or via a form post (and it would redirect back to your site on success or something).
What I don't want: A drop down that makes you pick your carrier and some php page that tries to email you #vtext.com or similar. That is just not slick enough.
You can use the ViaNett HTTP API to send SMS messages worldwide without specifying the operator.
As long as your backend supports invoking HTTP requests it will work.
Here is an example written in PHP:
<?php
// Register here to get a username and password:
// http://www.vianett.com/en/free-demonstration-account
if (vianett_sendsms('username', 'password', 'example', '+4412345678', 'Hello world', $error)) {
echo 'Success!';
} else {
echo $error;
}
function vianett_sendsms($username, $password, $from, $to, $msg, &$response=null) {
$url = 'https://smsc.vianett.no/v3/send.ashx';
$data = array(
'user' => $username,
'pass' => $password,
'src' => $from,
'dst' => $to,
'msg' => $msg
);
$qs = http_build_query($data);
$response = file_get_contents($url.'?'.$qs);
return $response == '200|OK';
}
We're getting good results from http://www.twilio.com
For direct SMS, you can try contacting a service provider and make a contract with it. If its for small projects and the server is accessible, you could put a GPRS mobile phone or modem and send with it.
My CakePHP should send an email when a button is clicked, however it doesn't. Also, the email will be displayed as a flash message if I run it in debug mode: ($this->Email->delivery = 'debug';).
Note: Email is set up to set up to use PHP mail() function.
Code to call the email function:
$this->_sendUpdateEmail( $this->Auth->user('id'), $about_id );
Email function
function _sendUpdateEmail($from_user_id, $about_id) {
$fromUser = $this->User->read(null, $from_user_id);
$users = $this->User->find('all', array(
'conditions' => array('User.distribution =' => 1)
));
# loop to send email to all users who are marked as on the distribution list
for($i = 0, $size = sizeof($users); $i < $size; ++$i) {
$user = $users[$i]['User'];
$this->Email->from = $fromUser['User']['email'];
$this->Email->replyTo = $fromUser['User']['email'];
$this->Email->to = $user['email'];
$this->Email->subject = 'Test email';
$this->Email->template = 'update';
$this->Email->sendAs = 'both'; // both = html and text
$this->set('user', $user);
$this->set('about', $about_id);
$this->Email->send();
$this->Email->reset();
}
}
Any ideas as to why the emails show in debug mode but won't actually send?
I think the reason why my emails were not sending was because there was no mail server configured on the web server my CakePHP was running on so there was no way to route the emails. However, this meant they would show up in the debug because they were generated successfully, just not sent.
In the end, I ended up using my company's Exchange mail server using the SMTP settings.
Code to use SMTP to send CakePHP emails
$this->Email->smtpOptions = array(
'port'=>'25',
'timeout'=>'30',
'host' => '192.168.0.244',
);
// Other email code here, e.g. from and to etc...
$this->Email->delivery = 'smtp';
I think the issue here is that mail server is not set right Linux comes built in with mail sending functionality but not windows (no idea on mac). look into smtp options as u can easily setup smtp email sender on Windows
Setting up smtp windows - http://publib.boulder.ibm.com/infocenter/cqhelp/v7r1m2/index.jsp?topic=/com.ibm.rational.clearquest.webadmin.doc/topics/c_config_email_smtp_win.htm
and
http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP