Created
February 23, 2018 17:14
-
-
Save FusRoDah061/156743a29d6015661a7841378dd6b776 to your computer and use it in GitHub Desktop.
Envia SMS por PHP utilizando API da DirectCall <http://www.directcall.com.br/api_telefonia_sms_gravacao>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Site do tutorial: http://tutoriais.directcall.com.br/enviar-sms-com-php/ | |
function requisicaoApi($params, $endpoint){ | |
$url = "http://api.directcallsoft.com/{$endpoint}"; | |
$data = http_build_query($params); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$return = curl_exec($ch); | |
curl_close($ch); | |
// Converte os dados de JSON para ARRAY< | |
$dados = json_decode($return, true); | |
return $dados; | |
} | |
// CLIENT_ID que é fornecido pela DirectCall (Seu e-mail) | |
$client_id = "email@email.com.br"; | |
// CLIENT_SECRET que é fornecido pela DirectCall (Código recebido por SMS) | |
$client_secret = "0000000"; | |
// Faz a requisicao do access_token | |
$req = requisicaoApi(array('client_id'=>$client_id, 'client_secret'=>$client_secret), "request_token"); | |
//Seta uma variavel com o access_token | |
$access_token = $req['access_token']; | |
// Enviadas via POST do nosso contato.html | |
$nome = $_POST['nome']; | |
$email = $_POST['email']; | |
$mensagem = $_POST['mensagem']; | |
// Monta a mensagem | |
$SMS = "Contato de: {$nome} - <{$email}> - {$mensagem}"; | |
// Array com os parametros para o envio | |
$data = array( | |
'origem'=>"19999999999", // Seu numero que é origem | |
'destino'=>"19999999999", // E o numero de destino | |
'tipo'=>"texto", | |
'access_token'=>$access_token, | |
'texto'=>$SMS | |
); | |
// realiza o envio | |
$req_sms = requisicaoApi($data, "sms/send"); | |
// FIM | |
?> | |
<br />Fomulario de contato<br /> | |
<form id="form1" action="index.php" method="post" name="form1"> | |
<h1>Fomulário de contato</h1> | |
<label for="nome">Nome</label> | |
<input id="nome" type="text" name="nome" /> | |
<label for="email">E-mail</label> | |
<input id="email" type="text" name="email" /> | |
<label for="mensagem">Mensagem</label> | |
<textarea id="mensagem" cols="45" name="mensagem" rows="5"></textarea> | |
<input id="button" type="submit" name="button" value="Enviar" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment