Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Kintanar committed May 23, 2018
0 parents commit ebb4c48
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock

39 changes: 39 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "laravelcebu/iTexMo-php",
"description": "Laravel package for the iTexMo SMS API",
"keywords": [
"laravel",
"laravel-cebu",
"sms-gateway",
"sms"
],
"license": "MIT",
"authors": [
{
"name": "Bertrand Kintanar",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/laravelcebu/iTexMo-php/issues",
"source": "https://github.com/laravelcebu/iTexMo-php"
},
"require": {
"php": "7.*"
},
"require-dev": {
"laravel/laravel": "5.5.*"
},
"autoload": {
"psr-4": {
"LaravelCebu\\Itexmo\\": "src/"
}
},
"extra": {
"laravel": {
"aliases": {
"SMS": "LaravelCebu\\Itexmo\\Facades\\SMSFacade"
}
}
}
}
14 changes: 14 additions & 0 deletions src/Facades/SMSFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace LaravelCebu\Itexmo\Facades;

use Illuminate\Support\Facades\Facade;
use LaravelCebu\Itexmo\Itexmo;

class TenancyFacade extends Facade
{
protected static function getFacadeAccessor()
{
return Itexmo::class;
}
}
162 changes: 162 additions & 0 deletions src/Itexmo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

namespace LaravelCebu\Itexmo;

class Itexmo
{
const SEND_A_MESSAGE = 'api.php';
const SERVER_STATUS = 'serverstatus.php';
const APICODE_STATUS = 'apicode_info.php';
const DISPLAY_OUTGOING = 'display_outgoing.php';
const DELETE_OUTGOING_ALL = 'delete_outgoing_all.php';
const DISPLAY_MESSAGES = 'display_messages.php';

protected $api_code;

protected $api_base_path = 'https://www.itexmo.com/php_api/';

protected $response;

protected $params = [];

public function __construct()
{
$this->params['apicode'] = $this->api_code = config('itexmo.api_code');
}

/**
* Send a Message
*
* "1" = Invalid Number.
* "2" = Number prefix not supported. Please contact us so we can add.
* "3" = Invalid ApiCode.
* "4" = Maximum Message per day reached. This will be reset every 12MN.
* "5" = Maximum allowed characters for message reached.
* "6" = System OFFLINE.
* "7" = Expired ApiCode.
* "8" = iTexMo Error. Please try again later.
* "9" = Invalid Function Parameters.
* "10" = Recipient's number is blocked due to FLOODING, message was ignored.
* "11" = Recipient's number is blocked temporarily due to HARD sending (after 3 retries of sending and message still failed to send) and the message was ignored. Try again after an hour.
* "12" = Invalid request. You can't set message priorities on non corporate apicodes.
* "13" = Invalid or Not Registered Custom Sender ID.
* "0" = Success! Message is now on queue and will be sent soon.
*
* @param $number
* @param $message
*
* @return Itexmo
*/
public function send($number, $message)
{
$this->params = ['1' => $number, '2' => $message, '3' => $this->api_code];

return $this->curl(self::SEND_A_MESSAGE);
}

/**
* Check API Service Status and your SMS Server Status
*
* "INVALID" = Invalid ApiCode OR "[{JSON Format}]" = JSON format of contents
*
* JSON Datas:
* APIStatus: "OFFLINE" or "ONLINE"
* DedicatedServer: "YES" or "NO"
* GatewayNumber: Your Gateway Number
* SMSServerStatus: "FAULTY" or "OPERATIONAL"
*
* @return Itexmo
*/
public function status()
{
return $this->curl(self::SERVER_STATUS);
}

/**
* Check ApiCode Info and Status
*
* "INVALID APICODE" = Invalid ApiCode OR "[{JSON Format}]" = JSON format of contents
*
* @return Itexmo
*/
public function apiCodeStatus()
{
return $this->curl(self::APICODE_STATUS);
}

/**
* Show Pending or Outgoing SMS
*
* "INVALID PARAMETERS" = Invalid sortby
* "EMPTY" = No Outgoing or Pending SMS
* "[{JSON Format}]" = JSON format of contents
*
* @param string $sortOrder
*
* @return Itexmo
*/
public function displayOutgoing($sortOrder = 'desc')
{
$this->params['sortby'] = $sortOrder;

return $this->curl(self::DISPLAY_OUTGOING);
}

/**
* Delete All Pending or Outgoing SMS
*
* "ERROR" OR "SUCCESS"
*
* @return Itexmo
*/
public function deleteOutgoingAll()
{

return $this->curl(self::DELETE_OUTGOING_ALL);
}

/**
* @param $mode
*
* @return $this
*/
private function curl($mode)
{
$ch = curl_init();
$method = CURLOPT_HTTPGET;

$query = '';
if ($mode == self::SEND_A_MESSAGE) {
$method = CURLOPT_POST;
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->params));
} else {
$query = http_build_query($this->params);
}

curl_setopt($ch, CURLOPT_URL, $this->api_base_path . $mode . '?' . $query);
curl_setopt($ch, $method, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$this->response = curl_exec($ch);

curl_close($ch);

return $this;
}

/**
* @return mixed
*/
public function response()
{
return $this->response;
}

/**
* @return mixed
*/
public function __toString()
{
return $this->response();
}
}
5 changes: 5 additions & 0 deletions src/assets/configs/itexmo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'api_code' => env('ITEXMO_API_CODE'),
];

0 comments on commit ebb4c48

Please sign in to comment.