Yii2 Dengan Api Sms Gateway (Infobip)

Langsung aja hemat kouta😀, kali ini saya coba belajar sms gateway menggunakan API, biasanya saya pake gammu/modem, untuk hemat biaya serta waktu config tu modem , kita gunakan Api Sms gateway saya pake InfoBip, dapat dari teman, katanya bagus, dan rupanya si InfoBip ini ada lib menggunakan composer, Yes akhirnya bisa di gunakan pake Yii2, ok

pertama instal dulu , bisa di liat disini https://github.com/infobip/infobip-api-php-client ,

ups sebelum melanjutkan anda harus punya akun infobip terlebih dahulu, krn headernya menggunakan kombinasi username dan password akun anda , silahkan daftar disini http://www.infobip.com/

kedua, kodingnya misalkan kita taruh di SiteController yaa


....

use infobip\api\client\SendSingleTextualSms;
use infobip\api\configuration\BasicAuthConfiguration;
use infobip\api\model\sms\mt\send\textual\SMSTextualRequest;
use infobip\api\client\GetSentSmsDeliveryReports;
use infobip\api\model\sms\mt\reports\GetSentSmsDeliveryReportsExecuteContext;

public function actionRptsms()
{
$client = new GetSentSmsDeliveryReports(new BasicAuthConfiguration('amandit','amandit.'));
// Creating execution context
$context = new GetSentSmsDeliveryReportsExecuteContext();
// Executing request
$response = $client->execute($context);

for ($i = 0; $i < count($response->getResults()); ++$i) {
$result = $response->getResults()[$i];
echo "Message ID: " . $result->getMessageId() . "\n";
echo "Sent at: " . $result->getSentAt()->format('Y-m-d H:i:s P') . "\n";
echo "Receiver: " . $result->getTo() . "\n";
echo "Status: " . $result->getStatus()->getName() . "\n";
echo "Message text: " . $result->getText() . "\n";
echo "Price: " . $result->getPrice()->getPricePerMessage() . " " . $result->getPrice()->getCurrency() . "\n\n";
}
}

public function actionSms()
{
$request=Yii::$app->request;
$from=$request->post('from');
$to=$request->post('to');
$msg =$request->post('msg');
$client = new SendSingleTextualSms(new BasicAuthConfiguration('demo','demo.'));

// Creating request body
$requestBody = new SMSTextualRequest();
$requestBody->setFrom($from);
$requestBody->setTo([$to]);
$requestBody->setText($msg);

// Executing request
$response = $client->execute($requestBody);
}

Ok sudah selesai gitu aja sih🙂 untuk contoh kodingnya saya pake dari example infobin yg kita instal tadi,tinggal copas aja kawan ,

OK selajutnya tambahan aja, krn saya ada client pake foxpro, maka manfaatkan lah Url dari Yii2 itu tadi, kodingnya


#define httpstatus_ok 200
#define httpstatus_created 201
#define httpstatus_accepted 202
#define httpstatus_multistatus 207
#define httpstatus_badrequest 400
#define httpstatus_unauthorized 401
#define httpstatus_forbidden 403
#define httpstatus_notfound 404
#define httpstatus_internalservererror 500
clea
lcurl='http://localhost/advanced/backend/web/index.php?r=site/sms'
ohttp = CreateObject("Microsoft.XMLHTTP")
local lcparam
TEXT TO lcparam NOSHOW TEXTMERGE PRETEXT 7
from=InfoSms&to=6282166912345&msg=pesan dari saya
ENDTEXT
ohttp.open("POST", lcurl, .F.)
ohttp.setrequestheader('Content-Type', 'application/x-www-form-urlencoded;')
ohttp.setrequestheader('Content-length', alltrim(str(len(lcparam))) )
ohttp.setrequestheader('Connection', 'close')
ohttp.send(lcparam)
ohttp.status
if not empty(ohttp.responsetext)
MESSAGEBOX("terkirim")
endi

[edit]
ketinggalan jika gagal/error 60 SSL certifikat send sms itu terjadi krn belum diisi curl.cainfo yang ada di php.ini,
silahakan download filenya http://www.mediafire.com/download/xpvwc8ss6g7iofd/60Certificate.zip , ekstrak, naa isi path curl.cainfo tadi kaya ini

2

OK sekian, moga sukses yaa kawan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: