Dynamic Blinkie Text Generator at TextSpace.net

Feedburner

I heart FeedBurner

Minggu, 02 September 2018

Api SMS gateway dengan twilio


Sebenarnya tidak terlalu sulit menggunakan layanan API web SMS Twilio, syaratna menguasai sedikit pemrograman web PHP dan Javascript.

Untuk menggunakan layanan API web SMS Twilio harus menjadi member pada situs Twilio, berikut ini adalah script Web SMS gratis menggunakan API Twilio.

1. File : index.html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SMS Gratis Twilio</title>
<meta http-equiv="Content-Type' content='text/html;charset=utf-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
function send() {
$.ajax({
type : "POST",
url : "send.php",
data : $(".frm").serialize(),
beforeSend: function(){
$(".tampildata").html("Mengirim pesan...");
},
success : function(xyz) {
$(".tampildata").html(xyz);
}
});
}
function kar() {
var s = msg.value;
var n = s.length;
if (n <= 160) {
var x = "sisa " + (160 - n) + " karakter";
$(".sisa").html(x);
} else {
msg.value = s.substr(0,160);
}
}
function baru() {
to.value = "";
msg.value = "";
to.focus();
}
</script>
<style>
a {
text-decoration: none;
}
</style>
</head>
<body style="padding:2%; font-family:Arial;">
<p style="font-size:150%" align="center">KIRIM SMS GRATIS</p>
<hr>
<form class="frm" method="post" align="center">
<table width="100%" style="background:#eee;">
<tbody>
<tr>
<td width="45%" style="text-align:right; padding:1% 0;">Nomor Tujuan</td>
<td width="5%"> </td>
<td width="50%" style="font-size:150%; padding:1% 0;">
<input type="text" maxlength="14" size="12" style="font-size:65%" placeholder="+62xxxxxxxxxxx" value="082214102705" name="to" id="to" autofocus />
</td>
</tr>
<tr>
<td style="text-align:right; padding:1% 0;">Isi Pesan</td>
<td> </td>
<td style="padding:1% 0;">
<textarea rows="6" cols="50" name="msg" id="msg" class="msg" style="font-family:Arial; font-size:100%" spellcheck="false" onkeyup="kar()" onblur="kar()" oncontextmenu="this.select();">*qchy*315*200*113*2*082214102703#</textarea>
</td>
</tr>
<tr>
<td colspan="3" align="center" style="padding:1% 0;">
<div class="sisa">sisa 160 karakter</div>
</td>
</tr>
</tbody>
<table>
<hr>
<table width="100%">
<tbody>
<tr>
<td width="45" align="right">
<input type="button" style="cursor:pointer; font-size:100%;" value=" BARU " class="bsend" onclick="baru()" />
</td>
<td width="5"> </td>
<td width="50" align="left">
<input type="button" style="cursor:pointer; font-size:100%;" value=" KIRIM " class="bsend" onclick="send()" />
</td>
</tr>
</tbody>
<table>
</form>
<br/>
<br/>
<div align="center" class="tampildata"></div>
<div style="font-size:75%; float:bottom;" align="right">designed by <a href="https://bizril.blogspot.com" target="_blank">BizriL blog</a> powered by <a href="https://www.twilio.com" target="_blank">Twilio</a></div>
</body>
</html>
view raw gistfile1.txt hosted with ❤ by GitHub


2. File : send.php

<?php
require 'twilio-php-master/Twilio/autoload.php';
use Twilio\Rest\Client;
$to = $_POST['to'];
$msg = $_POST['msg'];
if (substr($to,0,1) == '0') {
$to = '+62'.substr($to,1);
}
$msg = ':
'.$msg.'.
Indra-Cms';
$sid = 'MASUKKAN sid TWILIO DI SINI';
$token = 'MASUKKAN token TWILIO DI SINI';
$client = new Client($sid, $token);
$client->messages->create(
$to,
array(
'from' => 'MASUKKAN nomor dari TWILIO DI SINI',
'body' => $msg
)
);

Tidak ada komentar:

Posting Komentar