Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrouh committed Aug 24, 2022
0 parents commit 0a27787
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package For 4jawaly Sms For Laravel
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "mfrouh/4jawaly",
"description": "Package For 4jawaly Sms For Laravel",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Mfrouh\\Sms4jawaly\\": "src/"
}
},
"authors": [
{
"name": "mfrouh",
"email": "[email protected]"
}
],
"extra": {
"laravel": {
"providers": [
"MFrouh\\Sms4jawaly\\Providers\\Sms4JawalyServiceProvider"
]
},
"aliases": {
"Sms4jawaly": "MFrouh\\Sms4jawaly\\Facades\\Sms4jawaly"
}
},
"minimum-stability": "dev",
"require": {}
}
58 changes: 58 additions & 0 deletions src/BaseClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace MFrouh\Sms4jawaly;

use Illuminate\Support\Facades\Http;
use Exception;

class BaseClass
{
const Base_Url = 'https://4jawaly.net/api';

public function getBalance()
{
try {
$data = [
'username' => config('sms4jawaly.username'),
'password' => config('sms4jawaly.password'),
'return' => 'json'
];

$response = Http::get(self::Base_Url . '/getbalance.php', $data);

return ['status' => true, 'response' => $response->currentuserpoints, 'message' => $response->MessageIs];
} catch (Exception $error) {
return ['status' => false, 'response' => $error, 'message' => 'error'];
}
}

public function sendSms($message, $phoneNumber)
{
try {
$data = [
'username' => config('sms4jawaly.username'),
'password' => config('sms4jawaly.password'),
"message" => urlencode($message),
"numbers" => $this->convertArabicNumbers(ltrim($phoneNumber, '0')),
"sender" => config('sms4jawaly.sender_name'),
"unicode" => 'e',
'return' => 'json'
];

$response = Http::get(self::Base_Url . '/sendsms.php', $data);

return $response;
} catch (Exception $error) {
return $error;
}
}

private function convertArabicNumbers($number)
{
$arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];

$english = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

return str_replace($arabic, $english, $number);
}
}
14 changes: 14 additions & 0 deletions src/Facades/4Jawaly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace MFrouh\Sms4jawaly\Facades;

use Illuminate\Support\Facades\Facade;

class Sms4jawaly extends Facade
{
protected static function getFacadeAccessor()
{
return 'Sms4jawaly';
}
}

27 changes: 27 additions & 0 deletions src/Providers/Sms4JawalyServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace MFrouh\Sms4jawaly\Sms4JawalyServiceProvider;

use MFrouh\Sms4jawaly\BaseClass;
use Illuminate\Support\ServiceProvider;

class Sms4JawalyServiceProvider extends ServiceProvider
{

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind('Sms4jawaly', function ($app) {
return new BaseClass();
});
}

public function boot()
{

}
}
7 changes: 7 additions & 0 deletions src/config/sms4jawaly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
'username' => env('4JAWALY_USERNAME'),
'password' => env('4JAWALY_PASSWORD'),
'sender_name' => env('4JAWALY_SENDER_NAME')
];

0 comments on commit 0a27787

Please sign in to comment.