$mob_num=$_POST["mobileNumber"];
$sms_mes=$_POST["smsMessage"];
$lin_api = "http://abcd.com/SendSms.aspx?username=demo&password=demo123&to=$mob_num&from=TIWCOM&message=$sms_mes";
$get_mid = file_get_contents($lin_api);
echo " $get_mid ";
In the above code, I collect mobileNumber & smsMessage from a html form page and put it into $lin_api and try to send the $lin_api to abcd.com's server by file_get_contents
If I directly paste:
http://sitename/SendSms.aspx?username=demo&password=demo123&to=9876543210&from=TIWCOM&message=Testing SMS
(with '9876543210' as mobile number and 'Testing SMS' as message) in the link bar, it works. It sends SMS and returns a messageid code. But, if I use above code, I get some peculiar error message like:
Invalid Details (Username, Password, From, To or Message)
or
BAD Request. HTTP Error 400. The request is badly formed
Why? Please help. Thanks in advance.
Try:
$lin_api = "http://abcd.com/SendSms.aspx?" .
http_build_query(array('username' => 'demo',
'password' => 'demo123',
'to' => $mob_num,
'from' => 'TIWCOM',
'message' => "$sms_mes (by tiw.com)"));
Related
I hope you can help me with an issue with phone call dialings using Plivo PHP (new SDK 4.0). First I will indicate what I want to achieve:
- A client on my website wants to talk with an agent of main, so he introduces his telephone number in a form, choose an agent, and finally when submit, the website connect both of them dialing (this works). But then, (here begin my problems), I can't retrieve the call details (status, duration, initial and end dates of the call, etc...) for invoicing the client according to some of these details.
Edited 2018/02/23:
Ramya, the 600 error has dissapeared and everything seems to be ok as I see in the Plivo debug log. Below are my new codes (I think better done thanks to your instructions), and then, I show you the Plivo debud log (perhaps it's better you can see it inside my account, call made Feb 23, 2018 18:33:15), and finally I see my server debug error log is empty!.
The main problem is that dialstatus.php file, although seems to receive the parameters, I don't know how to access them because dialstatus.php does not execute showing the data in my monitor (in my code for example, this line never shows in the monitor screen:)
echo "Status = $estado, Aleg UUID = $aleg, Bleg UUID = $bleg";
So even though it receives the parameters, I can not access them to manipulate them, print them on the screen, do ifs with them, etc. May it be perhaps a permission problem with the files? (These php files have 6,4,4 permissions on my server, the same as the others).
Thank you!
Code 1: makecall.php
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("**********", "**************************");
$telefono_cliente = "34*******";
$telefono_experto = "34*********";
$duracion = 50;
try {
$response = $client->calls->create(
"3491111111",
[$telefono_experto],
"https://www.ejemplo.com/llamar/response.php?telf=$telefono_cliente",
'POST',
[
'time_limit' => $duracion,
]
);
$id = $response->requestUuid;
echo "<br>Este es el requestUuid: " . $id . "<br><br>";
}
catch (PlivoRestException $ex) {
print_r($ex);
}
?>
Code 2: response.php
require 'vendor/autoload.php';
use Plivo\XML\Response;
$resp = new Response();
$params = array(
'callerId' => '3491111111',
'action' => "https://www.ejemplo.com/llamar/dialstatus.php",
'method' => "POST",
'redirect' => "false"
);
$body3 = 'Desde ejemplo un cliente desea hablar con usted.';
$params3 = array(
'language' => "es-ES", # Language used to read out the text.
'voice' => "WOMAN" # The tone to be used for reading out the text.
);
$resp->addSpeak($body3,$params3);
$dial = $resp->addDial($params);
//$number = "34**********";
$number = $_GET['telf'];
$dial->addNumber($number);
Header('Content-type: text/xml');
echo($resp->toXML());
/*
Output:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Speak language="es-ES" voice="WOMAN">Desde ejemplo un cliente desea hablar con usted.</Speak>
<Dial redirect="false" method="POST" action="http://www.ejemplo.com/llamar/dialstatus.php" callerId="3491111111">
<Number>34********</Number>
</Dial>
</Response>
*/
?>
Code 3: dialstatus.php
// Print the Dial Details
$estado = $_REQUEST['DialStatus'];
$aleg = $_REQUEST['DialALegUUID'];
$bleg = $_REQUEST['DialBLegUUID'];
echo "Status = $estado, Aleg UUID = $aleg, Bleg UUID = $bleg";
?>
Plivo Sales Engineer here.
Redirect = true is used only when you want to continue the call by returning another XML in your action URL. For you use case, you don't have to use this parameter. Even if the Redirect is set to false, Plivo will make a request to the action URL with a list of parameters. I looked into your account (here) and I can see this request getting sent with DialStatus, ALegUUID, BLegUUID along with other parameters.
Dial Action URL is the best place to know the DialStatus and DialHangupCause.
You can find the call duration and billing amount in Hangup URL request as well. This Hangup URL can be configured in your first API call (to the expert). By default, hangup URL is set to Answer URL.
Please raise a support ticket with us for further assistance.
I am creating a telegram bot with php. I need to let user insert data step by step when they run the command /order. I do an example:
User: /order
Bot: I will help you to make an order
Bot: Insert the name
User: Ciccio (he has typed the name)
Bot: Ok, now insert your surname
User: Pasticcio (he has typed the surname)
and so on...
I thought I was in the correct way to reach my purpose... but not... something does not work... Here my code:
elseif(strcmp($text, "/order") === 0) <-Here the command
{
$response =
"I will help you.\n"
."\n"
."Insert your name:";
$parameters = ['chat_id' => $chatId, "text" => $response, "parse_mode" => "Markdown"];
$parameters["method"] = "sendMessage";
echo json_encode($parameters);
$action_parameters = ['chat_id' => $chatId, "action" => "typing"];
$action_parameters["method"] = "sendChatAction";
echo json_encode($action_parameters);
$parameters2 = array('chat_id' => $chatId, "text" => "good! Now insert the surname");
$parameters2["method"] = "sendMessage";
echo json_encode($parameters2);
}
the code stop after I visualize the first message... it is like after I do my first echo json_encode($parameters); no code is runned anymore...
How can I reach my purpose?
Thank you
Do you use JSON response when received Webhook updates?
If yes, you need to make a request instead of print it to HTTP Response Body and log user input to your own database.
for any message your bot receives, you check the step of the user in your bot and you will send the right function (so the right question).
to do this you have to store users' steps. Please read my answer to this question.
I would like to use an SMS Gateway PHP API but I don't success to use it. I downloaded on my phone with android the software from SMSGATEWAY.ME and I created an account.I have also a free web server and I uploaded on it two documents :
their PHP API Library "smsGateway.php" that peoples can find here :
https://smsgateway.me/sms-api-libraries/sms-gateway-me-php.zip
my file "test.php" :
<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('my_email_on_their_website', 'my_password_for_this_account');
$deviceID = 111111; //the number of my device, displayed on their website or on the software installed on my phone
$number = '+1234567891'; //the number I want to SMS
$message = 'Hello World!'; //my message
$options = [
'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes
'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent
];
//Please note options is no required and can be left out
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options);
?>
But when I visit with my browser http://mywwebsite.com/test.php, it doesn't send SMS, do you know why please ? Can you help me to fix this problem please ? (the gateway on my phone is still active).
Thank you in advance !
Best regards
Your code is correct. If you want to display the result write the following line after $result variable
echo json_encode($result);
So your code will look like this
<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('my_email_on_their_website', 'my_password_for_this_account');
$deviceID = 111111; //the number of my device, displayed on their website or on the software installed on my phone
$number = '+1234567891'; //the number I want to SMS
$message = 'Hello World!'; //my message
$options = [
'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes
'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent
];
//Please note options is no required and can be left out
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options);
echo json_encode($result);
?>
I used php server side to connect with clickatell messages service , i used the soap api technique to make the connection . it is working .but in my code , i can send just one message at the same time , here is the code :
function actionSendSMS(){
$msgModel = new Messages();
$settModel = new Settings();
$setRows = $settModel->findAll();
$usr=$setRows[0]->clickatell_usr;
$pwdRows = $settModel->findAll();
$pwd=$pwdRows[0]->clickatell_pwd;
$api_idRows = $settModel->findAll();
$api_id=$api_idRows[0]->clickatell_api_id;
$msgModel->findAllBySql("select * from messages where is_sent=0 and
send_date=".date("m/d/Y"));
$client = new SoapClient("http://api.clickatell.com/soap/webservice.php?WSDL");
$params = array('api_id' => $api_id,'user'=> $usr,'password'=> $pwd);
$result = $client->auth($params['api_id'],$params['user'],$params['password']);
$sessionID = substr($result,3);
$callback=6;
// echo $result."<br/>";
// echo $sessionID;
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=>
$usr,'password'=>$pwd,
'to'=>array('962xxxxxxx'), 'from'=>"thetester",'text'=>'this is a sample test
message','callback'=>$callback);
$result2 = $client->sendmsg($params2['session_id'],
$params['api_id'],$params['user'],$params['password'],
$params2['to'],$params2['from'],$params2['text'],$params2['callback']);
print_r( $result2)."<br/>";
$apimsgid= substr($result2[0],4);
$rowsx=Messages::model()->findAllBySql("select * from messages where is_sent=0 and
send_date='".date("m/d/Y")."'");
for($i=0;$i<count($rowsx);$i++)
{
$rowsx[$i]->clickatell_id=$apimsgid;
$rowsx[$i]->save();
}
//echo $apimsgid."<br/>";
if (substr($result2[0], 0,3)==='ERR' && (!(substr($result2[0], 0,2)==='ID'
) ))
{
echo 'Connot Routing Message';
}
.... now you see that this code will send one message at the same time , forget about the id , its for personal purpose , now this service i have to modify it , to send multiple messages at the same time , and i will give every message an unique ID , so now my problem is : is there any one knows if there is a service to send multiple sms at the same time ;
as in my code i fill the information for one message ,but i need a service to send multiple sms , does any body can give me a link to this service , i made many searches but there is no answer i have found
Try startbatch command to send multiple messages at the same time (it also supports personalized). However, it is not based soap, it is based http api.
Have you tried
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx', '962xxxxxxx', '962xxxxxxx'), 'from'=>"thetester",'text'=...
or
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx,962xxxxxxx,962xxxxxxx'), 'from'=>"thetester",'text'=...
I have a form with a host link and the url that i can post to. The method works fine online, i want to use php to enter data automatically, how do i do so without curl
it would be passed like this (Username, Password, Example, Example2)
Example 2 is a string array of data with required parameter names
if there is nothing passed at all the error will state "Login Error"
if Example 2 is empty it will display "Root element is missing."
See also: How to post data in PHP using file_get_contents?
Basically you can use file_get_contents() and stream_context_create() for issuing a POST request. In your case:
$post = http_build_query(array(
"username" => "user",
"password" => "pw",
"example" => "...",
));
$context = stream_context_create(array("http"=>array(
"method" => "POST",
"header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
"Content-Length: ". strlen($post) . "\r\n",
"content" => $post,
)));
$page = file_get_contents("http://example.com/login", false, $context);
Just open up a socket connection to port 80, send the headers (you can use livehttp headers if you want to cheat on creating the headers, just watch while posting from the browser and copy it). Then send the data after the headers.