SMS Gateway adalah sebuah sistem aplikasi yang digunakan untuk mengirim dan menerima SMS sangat mudah, karena SMS Gateway
akan melakukan semua proses koneksi dengan Telco.
Telco SMSC akan menghantar pesan (SMS) tersebut kepada perusahaan SMS Gateway
(sesuai dengan nomor yang telah disewa) dengan menggunakan protokol yang khusus. Dan berdasarkan keyword yang telah dituliskan pada SMS, maka sistem SMS Gateway akan menghantar SMS tersebut ke URL yang telah ditentukan.
UEA dapat menghantar SMS reply
kepada pelanggan melalui SMS Gateway
tersebut. Dan UEA dapat menentukan besarnya biaya yang akan dikenakan kepada pelanggan. Biasanya telah ditentukan regulasi biayanya, contoh Rp 0 (gratis); Rp 500, Rp 1000, Rp2000, dst
.
SMS Gateway
biasanya digunakan pada aplikasi bisnis, baik untuk kepentingan broadcast promosi, penyedia content produk atau jasa dan lainnya.
Kali ini kita membahas, bagaimana membuat SMS Gateway
dengan menggunakan android menggunakan penyedia API SMS Gateway
dari Zenziva
Daftar Zenziva
Untuk melakukan pendaftaran disini , jika sudah melakukan pendaftaran masuk ke bagian menu setting->API Setting
seperti gambar dibawah, dibagian paskey
masukan terserah anda lalu klik button update
, setelah itu simpan userkey
dan passkey
dan letakkan pada source code androidnya untuk lebih jelasnya lihat vidio.
Penyiapan Proyek
Bagian dependencies
masukan dibagian file build gradle
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
Bagian file manifest
tambahkan user permission
berikut
<uses-permission android:name="android.permission.INTERNET"/>
Langkah Membuat Proyek
Buat design dan masukan kode xml berikut
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.codetr.tanwir.actionsend.MainActivity">
<TextView
android:text="NO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp"
android:layout_marginTop="81dp"
android:id="@+id/textView" />
<TextView
android:text="Pesan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"
android:layout_marginTop="41dp"
android:id="@+id/textView2" />
<Button
android:text="Send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:onClick="btnSend"
android:layout_below="@+id/editText2"
android:layout_alignRight="@+id/editText2"
android:layout_alignEnd="@+id/editText2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Input message"
android:ems="10"
android:id="@+id/editText2"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText" />
<TextView
android:text="SMS GATEWAY API"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:textStyle="bold"
android:textSize="30dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:hint="Input phone number"
android:id="@+id/editText"
android:layout_alignBaseline="@+id/textView"
android:layout_alignBottom="@+id/textView"
android:layout_alignRight="@+id/textView3"
android:layout_alignEnd="@+id/textView3" />
</RelativeLayout>
Struktur dari package seperti gambar dibawah
Buat model seperti gambar diatas dengan nama class ActionSMS
/*
* Copyright (c) 2016. Tanwir. All Rights Reserver.
* <p>
* Save to the extent permitted by law, you may not use,copy,modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of Tanwir.
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
package com.codetr.tanwir.actionsend.model;
/**
* Created by tanwir on 26/05/2019.
*/
public class ActionSMS {
private String userkey;
private String passkey;
private String nohp;
private String pesan;
public String getUserkey() {
return userkey;
}
public void setUserkey(String userkey) {
this.userkey = userkey;
}
public String getPasskey() {
return passkey;
}
public void setPasskey(String passkey) {
this.passkey = passkey;
}
public String getNohp() {
return nohp;
}
public void setNohp(String nohp) {
this.nohp = nohp;
}
public String getPesan() {
return pesan;
}
public void setPesan(String pesan) {
this.pesan = pesan;
}
}
Selanjutnya buat class penampungan base url API
dari penyedia SMS Gateway Zenziva
.
/*
* Copyright (c) 2016. Tanwir. All Rights Reserver.
* <p>
* Save to the extent permitted by law, you may not use,copy,modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of Tanwir.
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
package com.codetr.tanwir.actionsend.network;
/**
* Created by tanwir on 26/05/2019.
*/
public class Config {
public static final String BASE_URL = "https://reguler.zenziva.net/apps/";
}
Buat class Data Provider
dimana melakukan parsing dari Base URL API
menggunakan library Retrofit
dengan memanggil base url dari class config.
/*
* Copyright (c) 2016. Tanwir. All Rights Reserver.
* <p>
* Save to the extent permitted by law, you may not use,copy,modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of Tanwir.
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
package com.codetr.tanwir.actionsend.network;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by tanwir on 26/05/2019.
*/
public class DataProvider {
private DataService nService;
private Retrofit mRetrofitClient;
/**
* config Retrofit in initialization
*/
public DataProvider() {
OkHttpClient httpClient = new OkHttpClient();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Config.BASE_URL)
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
nService = retrofit.create(DataService.class);
}
public DataService getTService() {
return nService;
}
public Retrofit getRetrofitClient() {
return mRetrofitClient;
}
}
Selanjutnya membuat Data Service
untuk mengambil data dari api dengan aksi GET
dengan mengirimkan aksi dalam bentuk data Quary
.
/*
* Copyright (c) 2016. Tanwir. All Rights Reserver.
* <p>
* Save to the extent permitted by law, you may not use,copy,modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of Tanwir.
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
package com.codetr.tanwir.actionsend.network;
import com.codetr.tanwir.actionsend.model.ActionSMS;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
/**
* Created by tanwir on 25/05/2019.
*/
public interface DataService {
@GET("smsapi.php")
Call<List<ActionSMS>> SendAction(
@Query("userkey") String userkey,
@Query("passkey") String passkey,
@Query("nohp") String nohp,
@Query("pesan") String pesan
);
}
selanjutnya dibagian class MainActivity
untuk melakukan tindakan mengirim sms dengan memasukan parameter sesuai dengan api tersebut, dimana data yang dikirim berupa no dan pesan.
Call<List<ActionSMS>> call = nService.SendAction("user key", "pass key", "you no", "message");
call.enqueue(new Callback<List<ActionSMS>>() {
@Override
public void onResponse(Call<List<ActionSMS>> call, Response<List<ActionSMS>> response) {
}
@Override
public void onFailure(Call<List<ActionSMS>> call, Throwable t) {
}
}
);
Jika langkah diatas sudah di ikuti dengan benar, langkah terakhir anda bisa memasukan kode lengkapnya dibagian class MainActivity
.
/*
* Copyright (c) 2016. Tanwir. All Rights Reserver.
* <p>
* Save to the extent permitted by law, you may not use,copy,modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of Tanwir.
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
package com.codetr.tanwir.actionsend;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.codetr.tanwir.actionsend.model.ActionSMS;
import com.codetr.tanwir.actionsend.network.DataProvider;
import com.codetr.tanwir.actionsend.network.DataService;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by tanwir on 27/07/2017.
*/
public class MainActivity extends AppCompatActivity {
public static DataService nService;
private ActionSMS number;
private EditText message, numberphone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DataProvider provider = new DataProvider();
nService = provider.getTService();
}
public void btnSend(View v) {
Toast.makeText(MainActivity.this, "Send message", Toast.LENGTH_SHORT).show();
numberphone = (EditText) findViewById(R.id.editText);
message = (EditText) findViewById(R.id.editText2);
Call<List<ActionSMS>> call = nService.SendAction("qtz9e2", "mataramlembar",
numberphone.getText().toString(), message.getText().toString());
call.enqueue(new Callback<List<ActionSMS>>() {
@Override
public void onResponse(Call<List<ActionSMS>> call, Response<List<ActionSMS>> response) {
}
@Override
public void onFailure(Call<List<ActionSMS>> call, Throwable t) {
}
}
);
}
}
Jika anda jalankan maka outputnya seperti gambar dibawah
Anda juga bisa melihat tutorial menggunakan Nexmo
pada halaman berikut ini
Akhir Kata…
Dengan menggunakan penyedia API SMS Gateway
seperti salah satunya zenziva
, Nexmo
dan masih banyak lagi penyedia SMS Gateway, anda juga lebih mudah membuat SMS Gateway hanya dengan membayar untuk SMS ke pihak penyedia dan anda tinggal menggunakannya saja, tidak perlu ribet membuat menggunaka Gammu
, mungkin itu saja yang dapat saya sampaikan dari artikel ini semoga bermanfaat, jika ada yang ditanyakan silahkan di kolom komentar dibawah, selamat mencoba.