How to send SMS on php Textlocal.in api - php

I have used this code for send OTP on Given number. but can't send SMS. how to solve this....
PHP code
<?php
require_once ('smartysettings.php');
require_once ('class/User.php');
require_once ('class/Sms.php');
require_once ('class/RandomNumber.php');
$number = $_POST['mobnum'];
$result = #User::GetUserIdORMobile($number);
if($result->database->rows = 1)
{
$otp = RandomNumber(10);
$message = "Your OTP(One Time Password) is '$otp'";
$sender = 'Minveedu';
//print_r($otp); exit;
#Sms::SmsSend($number,$message,$sender);
}
?>
major class file for send SMS
PHP code
<?php
require_once ('textlocal.class.php');
class Sms
{
var $sms;
var $textloc;
public function __construct()
{
$this->textloc = new Textlocal('*******************', '****************');
}
public static function SmsSend($number,$message,$sender)
{
$ins = new self();
$numbers = array($number);
return $ins->textloc->sendSms($numbers,$message,$sender);
}
}
?>
how to solve and send SMS. please help for this request.

they themselves provide the code in php to send sms, you can find it by logging into your account then navigate HELP >> All DOCUMENTATION >> here you will find the copy and paste code section. just go through and it will work

Related

Swiftmailer pdf attachment from snappy bundle

I have an function downloadPdf($id, \Knp\Snappy\Pdf $snappy, Request $request).
This function downloads a pdf with information from objects everything works fine.
This is the function:
public function downloadPdf($id, \Knp\Snappy\Pdf $snappy, Request $request): Response
{
//search id
$workOrder = $this->getDoctrine()->getRepository(WorkOrders::class)->find($id);
//data to pdf template
$html = $this->renderView('pdf/pdf.html.twig', array(
'workOrder' => $workOrder,
));
//name file
$filename = $workOrder->getId();
//download pdf
return new PdfResponse(
$snappy->getOutputFromHtml($html),
$filename.'.pdf'
);
}
And then I have an swift mailer function:
//check if signed and if check is true
if ($data_uri) {
//send workOrder to company
if ($check == true) {
$transport = (new \Swift_SmtpTransport('smtp.sendgrid.net', 587))
->setUsername('sendgridUSERNAME')
->setPassword('sendgridPASSWORD')
;
$mailer = new \Swift_Mailer($transport);
$message = (new \Swift_Message('Werkbon '.$workOrder->getTitel()))
->setFrom(['xxx' => 'xxx'])
->setTo('xxx')
->setBody('xxx')
->attach(\Swift_Attachment::fromPath($this->downloadPdf()))
;
$result = $mailer->send($message);
}
The email works fine but I want to attach the pdf from the other function to this email in the code above you can see what I tried but I think I got it totally wrong.
I have no idea where to start.
Can someone give me a little push in the right direction?
Thanks!
here is how it works for me,
$invoicepdf = $this->get('knp_snappy.pdf')->getOutputFromHtml($html);
/* And instead of returning pdf, send it with mailer: */
$message = \Swift_Message::newInstance()
->setSubject('YOUR_TITLE')
->setFrom('foo#from.net')
->setTo('foo#to.net')
->attach(\Swift_Attachment::newInstance($invoicepdf, 'your_file_name','application/pdf'))
->setBody("yyy");
$mailer->send($message);

How to create an "Application Signed Request" with Sinch using PHP

I am trying to use the Sinch Rest API with PHP to mute and unmute specific participants from Conference calls but have not been able to find an example of how to send an application signed request with PHP. I have been trying to work off of this documentation from Sinch here https://www.sinch.com/docs/voice/rest/index.html#muteunmuteconfparticipant
My initial guesses are that this would require the use of CURL and that I would also need to use similar pieces of this example to sign my application but I"m not sure how to combine the two. https://github.com/sinch/php-auth-ticket
Any help appreciated. Thanks!
edit: #cjensen I added this code snippet I've been working on to try and use as the signed request maker. It's very similar to that github link above
<?php
class SinchTicketGenerator
{
private $applicationKey;
private $applicationSecret;
public function __construct($applicationKey, $applicationSecret)
{
$this->applicationKey = $applicationKey;
$this->applicationSecret = $applicationSecret;
}
public function generateTicket()
{
$request = [
'command' => 'mute',
];
$requestJson = preg_replace('/\s+/', '', json_encode($request));
$requestBase64 = $this->base64Encode($requestJson);
$digest = $this->createDigest($requestJson);
$signature = $this->base64Encode($digest);
$requestSigned = $requestBase64.':'.$signature;
return $requestSigned;
}
private function base64Encode($data)
{
return trim(base64_encode($data));
}
private function createDigest($data)
{
return trim(hash_hmac('sha256', $data, base64_decode($this->applicationSecret), true));
}
}
$generator = new SinchTicketGenerator('app-key', 'app-secret');
$signedrequest = $generator->generateTicket();
echo $signedrequest;
?>

how to convert a json response to a text output.?

I am using a platforme call ideamart to create some sms based applications.
They provide a api called subscription api.
deatils about ideamart subscription API
Guid to work with subscription API
I use below first code to request BaseSize details.is that code is correct.?
can I Display response using PHP echo() Function .? or any other way.?
<?php
include_once "definitions.php";
include_once "subscription.php";
$sub = new Subscription();
$AppId = "APP_00001";
$Password = "yuhst345";
$baseSize = $sub->getBaseSize($AppId,$Password);
?>
here is the getBaseSize function that includes in subscription.php
public function getBaseSize($applicationId, $password){
$arrayField = array(
"applicationId" => $applicationId,
"password" => $password);
$jsonObjectFields = json_encode($arrayField);
$resp=$this->sendBaseRequest($jsonObjectFields);
$response = json_decode($resp, true);
$statusDetail = $response['statusDetail'];
$statusCode = $response['statusCode'];
$status =$response['baseSize'];
return $status;
}
So, it looks like your getBaseSize() is returning an simply the base size. So, you should be able to do a
print $baseSize;
OR
echo $baseSize;
And you'll print out the string.

nusoap simple server

Hi i am using this code for nusoap server but when i call the server in web browser it shows message "This service does not provide a Web description" Here is the code
<?
//call library
require_once ('lib/nusoap.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('hello');
// create the function
function hello($name)
{
if(!$name){
return new soap_fault('Client','','Put your name!');
}
$result = "Hello, ".$name;
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
An help ...
Please change your code to,
<?php
//call library
require_once('nusoap.php');
$URL = "www.test.com";
$namespace = $URL . '?wsdl';
//using soap_server to create server object
$server = new soap_server;
$server->configureWSDL('hellotesting', $namespace);
//register a function that works on server
$server->register('hello');
// create the function
function hello($name)
{
if (!$name) {
return new soap_fault('Client', '', 'Put your name!');
}
$result = "Hello, " . $name;
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
You didnt Define namespace..
Please see simple example here :-
http://patelmilap.wordpress.com/2011/09/01/soap-simple-object-access-protocol/
The web browser is not calling the Web service - you could create a PHP client :
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new soapclient('your server url');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'StackOverFlow'));
// Display the result
print_r($result);
This should display Hello, StackOverFlow
Update
To create a WSDL you need to add the following :
$server->configureWSDL(<webservicename>, <namespace>);
You can also use nusoap_client
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('your server url'); // using nosoap_client
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Pingu'));
// Display the result
print_r($result)
?>

Sending an email using a template file

I am trying to figure out the best way to send emails from an external template file, at the moment I have a template file that looks like this:
Thank you, your order has been received, someone will review it and process it. No money has been taken from your account.
<?php
echo date('Y-m-d H:i:s');
?>
<pre>
<?php print_r($this->data); ?>
</pre>
And then my send method looks like this:
public function notify($template) {
// get the template from email folder
$path = $_SERVER['DOCUMENT_ROOT'].'templates/email/'.$template.'.php';
if(file_exists($path)) {
ob_start();
require_once($path);
$body = ob_get_contents();
ob_end_clean();
$subject = 'email send';
foreach($this->emailTo as $email)
new Mail($email,$subject,$body);
}
}
This all works fine when I call it like this:
$notifications = new notifications();
$notifications->setData(array('order' => $order->order));
$notifications->addEmail($order->order->email);
$notifications->notify('orderReceived');
However, if I try to make two calls to the "notify" method then the second email is blank, I know this is because the object buffer, but I cannot think of any other way to do it.
Thanks,
Ian
You are using require_once, so the file will only load once. Try require.
Also consider loading a pure text template and use str_replace to replace the variables in the template like this:
$template = "<pre>%DATA%</pre>";
$text = str_replace('%DATA%', $this->data, $template);
I would do this:
Template file
Thank you, your order has been received, someone will review it and process it. No money has been taken from your account.
%s
<pre>
%s
</pre>
Notify function
public function notify($template) {
// get the template from email folder
$path = $_SERVER['DOCUMENT_ROOT'].'templates/email/'.$template.'.php';
if (!file_exists($path)) {
// Return false if the template is missing
return FALSE;
}
// Create the message body and subject
$body = sprintf(file_get_contents($path), date('Y-m-d H:i:s'), print_r($this->data, TRUE));
$subject = 'email send';
// Send the mail(s)
foreach($this->emailTo as $email) {
new Mail($email, $subject, $body);
}
// Return true for success
return TRUE;
}
This will solve the problem - which could be solved anyway by changing require_once to require.
Using require_once means the template file will only be loaded once (clue's in the function name), so the second call will result in a blank body.

Categories