Skip to content

Commit

Permalink
Removing guzzlehttp
Browse files Browse the repository at this point in the history
  • Loading branch information
aimedidierm committed Jul 19, 2023
1 parent 8bb8798 commit c35b047
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
/vendor/
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aimedidierm/fdisms",
"description": "This is a php library to help developers include sms service, with FDI SMS gateway from RWANDA.",
"description": "This is a PHP library to help developers include SMS service with FDI SMS gateway from Rwanda.",
"type": "library",
"license": "MIT",
"autoload": {
Expand All @@ -14,5 +14,5 @@
"email": "aimedidiermugisha@gmail.com"
}
],
"minimum-stability": "dev"
"minimum-stability": "stable"
}
12 changes: 7 additions & 5 deletions examples/send_sms.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

namespace Aimedidierm\FdiSms;
require_once __DIR__ . '/../vendor/autoload.php';

$sms = new SendSms;
use Aimedidierm\FdiSms\SendSms;

$sms = new SendSms();
$sms->SingleSms(
$username = "", // Your API Username provided by FDI
$password = "", // Your API Password provided by FDI
$sender_id = "", // Your User ID provided by FDI
$phone = "", // Receiver phone number
$message = "", // Text message to be send
$message = "", // Text message to be sent
$ref = "", // Your unique message reference ID
$callBackURL = "" //Optional Delivery Report destination
$callBackURL = "" // Optional Delivery Report destination
);
echo $sms;
var_dump($sms);
54 changes: 40 additions & 14 deletions src/SendSms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

namespace Aimedidierm\FdiSms;

use Exception;

class SendSms
{
private function authFDISMS($SMSSECRET, $SMSID)
{
if (empty($SMSSECRET)) {
throw new Exception("SMSSECRET is required.");
}
if (empty($SMSID)) {
throw new Exception("SMSID is required.");
}

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://messaging.fdibiz.com/api/v1/auth/");
Expand All @@ -14,10 +23,10 @@ private function authFDISMS($SMSSECRET, $SMSID)

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"api_username\": $SMSID,
\"api_password\": $SMSSECRET
}");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"api_username" => $SMSID,
"api_password" => $SMSSECRET
]));

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
Expand All @@ -26,14 +35,31 @@ private function authFDISMS($SMSSECRET, $SMSID)

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);
$decodedResponse = json_decode($response, true);
return $decodedResponse;
}

public function SingleSms($username, $password, $sender_id, $phone, $message, $ref, $callBackURL)
{
if (empty($username)) {
throw new Exception("Username is required.");
}
if (empty($password)) {
throw new Exception("Password is required.");
}
if (empty($phone)) {
throw new Exception("Phone number is required.");
}
if (empty($message)) {
throw new Exception("Message is required.");
}
if (empty($ref)) {
throw new Exception("Reference is required.");
}

$auth = $this->authFDISMS($password, $username);
$token = $auth['access_token'];
$token = $auth["access_token"];
var_dump($token);
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://messaging.fdibiz.com/api/v1/mt/single");
Expand All @@ -42,13 +68,13 @@ public function SingleSms($username, $password, $sender_id, $phone, $message, $r

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"msisdn\": $phone,
\"message\": $message,
\"msgRef\": $ref,
\"dlr\": $callBackURL,
\"sender_id\": $sender_id
}");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"msisdn" => $phone,
"message" => $message,
"msgRef" => $ref,
"dlr" => $callBackURL,
"sender_id" => $sender_id
]));

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
Expand Down

0 comments on commit c35b047

Please sign in to comment.