Last active
December 17, 2015 00:49
-
-
Save John-Henrique/5523454 to your computer and use it in GitHub Desktop.
Exemplo de como enviar SMS em PHP utilizando XML e cURL na API REST do SMSdeck
This file contains hidden or 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 | |
/** | |
* Envio de SMS utilizando PHP, XML e cURL. | |
* | |
* @author John-Henrique | |
* @copyright 2013 | |
* @version 1.0 | |
* @link http://smsdeck.com.br/documentacao/enviar-sms-php.html | |
* | |
*/ | |
// dados do SMS | |
$numero_destino = "550011112222"; | |
$numero_origem = "550011112222"; | |
$mensagem = "sua mensagem 160 digitos"; | |
$agendar = ''; // este SMS será enviado imediatamente | |
$token = 'a54d54ae7r84gfg1fh4g78h1mj4k7u'; | |
$key = '8qw4er8w4sdfg21hd2jf65u6uk8k9j89'; | |
// estrutura XML | |
$xml = '<?xml version="1.0" encoding="iso-8859-1"?> | |
<sms> | |
<contato> | |
<numero_destino>'. $numero_destino .'</numero_destino> | |
<numero_origem>'. $numero_origem .'</numero_origem> | |
</contato> | |
<mensagem>'. $mensagem .'</mensagem> | |
<agendar>'. $agendar .'</agendar> | |
<token>'. $token .'</token> | |
<key>'. $key .'</key> | |
</sms>'; | |
// API alvo da ação | |
$acao = "sms"; | |
// cria uma conexão CURL | |
$curl = curl_init( "http://smsdeck.com.br/api/". $acao ); | |
// define que o envio deve ser via POST | |
curl_setopt($curl, CURLOPT_POST, 1); | |
// define o conteúdo da mensagem | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml ); | |
// ignora cabeçalhos | |
curl_setopt($curl, CURLOPT_HEADER, 0); | |
// retorna o resultado como texto | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
// saida do conteudo na variavel $resultado | |
$resposta = curl_exec($curl); | |
// fecha a conexão CURL | |
curl_close($curl); | |
// exibe na tela o retorno do servidor | |
print_r( $resposta, true ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment