I have developed a system which will send SMS to the customer after making insert to the database
but the system which I worked on is public ie. when my client asked me to buy the system he must insert his SMS API configuration to send a message to his customers
when I searched on the internet I found that every API have a differnt way to send SMS message
I have account in click tell API but when I send message by curl there is nothing happen
the code is
$url = 'https://platform.clickatell.com/messages/http/send?' . http_build_query(
[
'apiKey' => 'oGjnzDdSRhqdhhgnjFj3ZmzYA==',
// 'api_secret' => '4c98619ffb9af51585',
'to' => '94233698311783',
'content' => 'Hello from Netcom'
]
);
echo($url);echo('<br/>');
echo'https://platform.clickatell.com/messages/http/send?apiKey=oGkmzDdSRgekvjFjaZnzYA==&to=905373545631&content=Test+message+text"';
$ch = curl_init($url);
echo($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
Where my code is wrong and what is the way to send SMS dynamically depending on the client's API info
For quick fix and testing add this in your curl request and check response.(Because url is https)
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
But it is recomonded to downloading a CA root certificate bundle at the curl website and saving it on your server which protect your site
I am not aware of Clickatell, but Aws SNS is quite simple,
$payload = array(
'Message' => $message,
'PhoneNumber' => $mobile,
'MessageAttributes' => $msgAttributes
);
$result = $sns->publish($payload);
Related
My goal is to be able to use a slash command to open a dialog and process the feedback into a database. I am trying to get the dialog to open but am getting an error regarding the slash command where it says "trigger_id" not found.
My app is set up with an API and the proper OAuth.
I added a slash command to my app with the url of my php page (domain.com/slash.php)
The slash command is set up with the code below.
When I run it from my slack, I get the output of
'{"ok":false,"error":"invalid_arguments","response_metadata":{"messages":["[ERROR] missing required field: trigger_id"]}}'
I have tried some debugging and output the trigger_id to the screen and find that the trigger_id is indeed null. What am I missing to pass this?
I admit that I am new to the slack realm. I have followed (I think) the documentation from the slack site on setting up the app correctly.
Am I missing something with my slack app setup or something in my code that is causing this error message?
Thank you in advance for your time!
<?
$command = $_POST['command'];
$text = $_POST['text'];
$token = $_POST['token'];
$cn = $_POST['channel_id'];
$user_id = $_POST['user_id'];
$triggerid = $_POST['trigger_id'];
// define the dialog for the user (from Slack documentation example)
$dialog = [
'callback_id' => 'validres-3100',
'title' => 'Test',
'submit_label' => 'Submit',
'elements' => [
[
'type' => 'text',
'label' => 'Test Field 1',
'name' => 'field_1'
],
[
'type' => 'text',
'label' => 'Test Field 2',
'name' => 'field_2'
]
]
];
// define POST query parameters
$query = [
'token' => '<my api auth code>',
'dialog' => json_encode($dialog),
'trigger_id' => $triggerid
];
// define the curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://slack.com/api/dialog.open');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// set the POST query parameters
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query));
// execute curl request
$response = curl_exec($ch);
// close
curl_close($ch);
var_export($response);
?>
To open dialog box in slack you can use this api "https://slack.com/api/views.open".
With api you need to send trigger id which is valid only for 3 seconds.
Your url will looks like :
"https://slack.com/api/views.open?trigger_id=" + "xxxx.xxxxxxxxx.xxxxxxxxxxxx" + "&view=your data".
with this request you need to send token with your post request like :-
(URL,"POST", { "token" ,"xoxb-xxxxxx-xxxxx-xxxxxxx"});
Need to add view.open API in your slack app also for this use following step:
Use "Bot User OAuth Access Token" , In "OAuth and permissions Tab" Format is xoxb-xxxxx-xxxxx-xxxx. And then add scope "views:open" and reinstall your app in slack. And then try to get open view dialog.
Hope this will be helpful.
I want to send FCM push notifications in specific android users only using their token saved in mysql database as identification. here's my current progress
PHP Script Snippet Code: Report_Status.php (File 1)
//Gets the token of every user and sends it to Push_User_Notification.php
while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
$User_Token = $User_Row['User_Token'];
include "../Android_Scripts/Notifications/Push_User_Notification.php";
$message = "Your Report has been approved! Please wait for the fire fighters to respond!";
send_notification($User_Token, $message);
}
PHP code for File 2: Push_User_Notification.php
<?php //Send FCM push notifications process
include_once("../../System_Connector.php");
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = API_ACCESS_KEY',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
}
?>
Problem:
The page is always stuck in Report_Status.php every time I ran the
script. It is supposed to go in Push_User_Notification and return to Report_Status once the process is done. Am I wrong in the implementation of calling the
Push_User_Notification.php or the receiving parameters to
Push_User_Notification.php?
P.S.
Here's my full source code of Report_Status.php in case anyone wants to check it: Report_Status.php
I think the problem you may be having is that you are sending a lot of notifications to several devices in short amount of time. I think it might be being picked up as spaming. My suggestion is sending one notification to multiple devices.
Try changing your code in report_status.php to this.
include "../Android_Scripts/Notifications/Push_User_Notification.php";
$message = "Your Report has been approved! Please wait for the fire fighters to respond!";
while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
$User_Token[] = $User_Row['User_Token'];
}
$tokens = implode(",", $User_Token);
send_notification($tokens, $message);
the idea is that you will collect the user tokens in $User_Token[] array. Then you would comma seperate the tokens and send the message once to all the devices that associate to the tokens. FCM allows you to send to multiple tokens in one go.
updated
$User_Token needs to be an array. so remove the implode. That was my mistake.
Secondly the $message needs to be in the following format.
$message = array(
'title' => 'This is a title.',
'body' => 'Here is a message.'
);
Also another thing to note is that there are 2 types of messages you can send using FCM. Notification Messages or Data Messages. Read more here: https://firebase.google.com/docs/cloud-messaging/concept-options
I dont know if your app is handling the receipt of messages (i dont know if you have implemented onMessageRecieve method) so i would probably suggest making a small change to the $fields array in send_notification function. Adding the notification field allows android to handle notifications automatically if your app is in the background. So make sure you app is in the background when testing. https://firebase.google.com/docs/cloud-messaging/android/receive
$fields = array(
'registration_ids' => $tokens,
'data' => $message,
'notification' => $message
);
So try the code below. I have tried and tested. It works for me. If it does not work. In send_notification function echo $result to get the error message. echo $result = curl_exec($ch); Then we can work from there to see what is wrong. You can see what the errors mean here: https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes
include "../Android_Scripts/Notifications/Push_User_Notification.php";
$message = array(
'title' => 'Report Approved',
'body' => 'Your Report has been approved! Please wait for the fire fighters to respond!'
);
while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
$User_Token[] = $User_Row['User_Token'];
}
send_notification($User_Token, $message);
I am woking on my final year project and I would like to send sms to a client via php.
Is there any way in which I can use my cell phone as a GSM modem and send sms via php?
I tried "Ozeki NG - SMS Gateway" but not sure how to send sms via php.
if anyone has used/tried "Ozeki NG - SMS Gateway" then please let me know how to use it properly?
Any suggestions please do let me know.
I have a nokia 701. Can it be used as a gsm modem?.
Thank you
Try out this example code from Twilio, I used it during one of the hackathons.
Just for demo purpose this may help.
Depends on what country though.
http://www.twilio.com/docs/quickstart/php/sms
American Telcos let you send text messages as emails. I haven't played with this is many years, but I remember Verizon being [Phone #]#vtext.com, where [Phone #] is the 10-digit phone number of the cell phone. There are different domains for the different Telcos that you can lookup. Best of all this is free, rather than having to pay per text message.
If your phone is android you could use an app such as SMS Gateway API which will turn your phone into a SMS gateway and would allow you to both send and receive messages via PHP.
$URL = "http://v2.smsgateway.me/API/Send/Single.php";
$postdata = http_build_query(
array(
'Username' => "foo#bar.co.uk",
'Password' => "password",
'Number' => "+447791064782",
'Message' => "Hello World!",
'Device' => 1, //Send from device 1 (optional)
'SendAt' => (time() + (60 * 60)), //Send in 1 hours time (optional)
'ExpireAt' => (time() + (60 * 60 * 2)) //Expire in 2 hours time (optional)
)
);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = stream_context_create($opts);
$result = file_get_contents($URL, false, $context);
echo $result;
Your can try https://www.clickatell.com/ it is easy to use & integrate into your php code you can use http or rest api.
I assume that you already have sms service from msg91 using above setup or you can use any sms service providers like Twilio, Nexmo etc. Now i am creating a common function which you can call anywhere in your PHP code to send any type of text sms.
//send otp message
public static function sendMessage($mobile, $message)
{
$message = urlencode($message);
$url = sprintf("http://api.msg91.com/api/v2/sendsms?authkey=%s&mobiles=%s&message=%s&sender=%s&route=%s",
env('MSG91_AUTH_KEY'), $mobile, $message, env('MSG91_SENDER_ID'), env('MSG91_ROUTE'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
For more details and step by step execution follow below link :
https://www.lelocode.com/posts/sending-sms-like-otp,-welcome-message,mobile-verification-using-php---lelocode
I've been trying to integrate BitBucket to my application for the past 4 hours to no avail.
While reading through BitBucket's RESTful API documentation, I noticed that you need to use OAuth — it's OK, I'm using J.R Conlin's OAuthSimple library, which if fine by me (I tried oauth-php but it was kinda complicated — I didn't need all of those options for such a small integration).
For what I understand, the first step to authenticate with OAuth is to request a new token via POST. When providing the necessary parameters, you should get a response from BitBucket, like this:
oauth_token=Z6eEdO8lOmk394WozF9oJyuAv899l4llqo7hhlSLik&oauth_token_secret=Jd79W4OQfb2oJTV0vzGzeXftVAwglnEJ9lumzYcl&oauth_callback_confirmed=true
To do that, I'm using cURL and OAuthSimple:
$key = 'key_provided_by_bitbucket';
$secret = 'key_provided_by_bitbucket';
$path = 'https://api.bitbucket.org/1.0/oauth/request_token';
$params = array(
'oauth_consumer_key' => $key,
'oauth_nonce' => base_convert(mt_rand(10000, 90000), 10, 32) . 'a',
'oauth_signature' => 'HMAC-SHA1',
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_callback' => base_url('dashboard'),
'oauth_version' => '1.0a'
);
$oauth = new OAuthSimple($key, $secret);
$result = $oauth->sign(array(
'action' => 'POST',
'path' => $path,
'parameters' => $params
));
// load resulting url into a string
$ch = curl_init($result['signed_url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
curl_close($ch);
The thing is that, when I send my request, one of two things happen:
If I send it like posted here, I will get a 401 error (I can see that via curl_getinfo($ch))
If I set curl_setopt($ch, CURLOPT_POST, 1), I get a 400 Bad request
The resulting string (stored in $r) is an empty string. The signed_url is a correctly formed URL AFAIK, which is something like this:
https://api.bitbucket.org/1.0/oauth/request_token?oauth_callback=http%3A%2F%2Flocalhost%2Fidv&oauth_consumer_key=key_provided_by_bitbucket&oauth_nonce=b47a&oauth_signature=3A1R%2FoKxTqh6Q23poaS%2BVNzhwpE%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1347167282&oauth_version=1.0a
If I enter manually that address into my address bar in a browser, I'll get an Authentication Dialog to the BitBucket API, port 443. I can't login with my credentials, though. Then it will just keep saying "Could not verify OAuth request."
I don't know what I'm doing wrong, since it's my first time using OAuth.
Any help's appreciated!
The problem is that Curl will verify the SSL certificate.
To solve the problem you can tell Curl to ignore the verification of the SSL certificates:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
I have a php web site. Here I need to implement air ticket searching and booking functionality. In order to do this, I have used a paid API from ARZOO web site... I got all the documentation from ARZOO. I have read the entire doc. The Doc Says
"Accessing this service requires standard SOAP client. SOAP client should authenticate
itself through user name and password. Client should get their IPs registered with
Arzoo and get a user account created. The Arzoo web service provides a service
point URL. Web service clients should post SOAP request message as an attachment
for the desired response. The XML structure of different web services is discussed in
the respective documents."
You can connect to Arzoo XML services with the following test service point URLs:-
FlightAvailability:http://<url>/DOMFlightAvailability?wsdl
I think need to send the request via soap is it?
But in the air availability contains
Example Request Xml
<Request>
<Origin>BOM</Origin>
.............
.............
</Request>
I have used the following code
$post_string.="<Request>";
$post_string.="<Origin>$from</Origin><Destination>$to</Destination>";
........
......
$post_string.="</Request>";
$path = ":http://<url>/DOMFlightAvailability?wsdl";
$ch = curl_init($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); //Send the data to the file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$val = curl_exec($ch);
$headers = curl_getinfo($ch);
$errr=curl_error($ch);
But it's not giving any result.
The documents says
RESPONSE XML:-
The response will be in <arzoo_response> </arzoo_response>. This contains the Request
also.
I don't know SOAP.
I am totally disappointed. Please Help me.
I think I will get an xml response after posting the request. But how I will post my data?
Please reply
Many thanks, if anyone help me, its great appreciable
i also getting error while using SOAP CLIENT but when i use nusoap then they give me result..using this code if u get error like ip/password mismatch then You will call arzoo to verify your clientid and clientpassword
<?php
ini_set('max_execution_time','180');
include 'lib/nusoap.php';
$location_URL ='http://avail.flight.arzoo.com';
$action_URL ='http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl';
$Request = '<Request>
<Origin>BOM</Origin>
<Destination>DEL</Destination>
<DepartDate>2017-02-02</DepartDate>
<ReturnDate>2017-02-02</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<Clientid>Given by Arzoo.com</Clientid>
<Clientpassword>Given by Arzoo.com</Clientpassword>
<Clienttype>ArzooFWS1.1</Clienttype>
<Preferredclass>E</Preferredclass>
<mode>ONE</mode>
<PreferredAirline>AI</PreferredAirline>
</Request>';
$clientinfo = array('soap_version'=>SOAP_1_1,
'location' =>$location_URL,
'uri' =>$action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
);
$client = new nusoap_client('http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl', $clientinfo);
//print_r($client);
$result = $client->call('getAvailability', array($Request));
echo"<pre>";
print_r($result);
$clientInfo =simplexml_load_string(utf8_encode($result));
$flight = $clientInfo->Response__Depart->OriginDestinationOptions->OriginDestinationOption;
$error =$clientInfo->error__tag;
//echo $error;
var_dump($flight);
//exit;
//echo"<pre>";
//print_r($result);
//ECHO $error;
?>
Since they are mentioned standard SOAP client and you are sending the cURL request to the Server that will never give any response.
$location_URL = "http://xx.xxx.xx.xxx/ArzooWS/services/DOMFlightAvailability";
$action_URL ="http://com.arzoo.flight.avail";
$client = new SoapClient('http://xx.xxx.xx.xxx/ArzooWS/services/DOMFlightAvailability?wsdl', array(
'soap_version' => SOAP_1_1,
'location' => $location_URL,
'uri' => $action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
));
try
{
$result = $client->__call('getAvailability',array($req_int));
$response= htmlentities($result);
}
You can use SOAP1.1 Request.