Skip to content

Instantly share code, notes, and snippets.

@cypres
Last active April 7, 2017 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cypres/ec3f5782edcc76f0f7f36d636be6e765 to your computer and use it in GitHub Desktop.
Save cypres/ec3f5782edcc76f0f7f36d636be6e765 to your computer and use it in GitHub Desktop.
WHMCSnow integration with GatewayAPI.com
<?php
// This is untested code
class smsGateway_gatewayapi {
public $apifields = array(
'apitoken' => array("FriendlyName" => "API Token", "Type" => "text", "Size" => "64", ),
'senderid' => array("FriendlyName" => "Sender ID", "Type" => "text", "Size" => "15", ),
);
function sendSMSMessage() {
$recipients = array_combine(explode(',',$this->mobile),explode(',',$this->clientlist));
// $apifields settings above can be access via $this->settingname
// $this->apiid $this->apiusers etc..
// Other variables passed on from the SMS addon
// $this->smsmethod to be used in the SMS log
// $this->sms_body is the SMS body
// $this->mobile is a comma separated list of mobile numbers
// $this->clientlist is a comma separated list of client ID's (in the same order as $this->mobile
// $this->unicode is set to true if a unicode message is trying to be sent
foreach($recipients as $client_mobile => $client_id) {
// Code to send SMS messages here
$request = array(
'recipients.0.msisdn' => $client_mobile,
'sender' => $this->senderid,
'message' => $this->sms_body,
'token' => $this->apitoken,
'userref' => $this->apiref,
);
if ($this->unicode) {
$request['encoding'] = 'UCS2';
}
$response = sms_addon_curl("https://gatewayapi.com/rest/mtsms", $request);
// apiresponse: response from SMS API (eg. The message was successfully accepted for delivery.)
// apiref: A way to indentfy the SMS log entry, used for callbacks
// smsstatus: 0 = Message did not send 1 = Message sent successfully 2 = Message in queue (for callbacks)
try {
$ids = json_decode($response, true);
// Log result using the following query
$log = array('clientid' => $client_id,
'mobilenumber' => $client_mobile,
'smsbody' => $this->sms_body,
'smsmethod' => $this->smsmethod,
'apiresponse' => $response,
'apiref' => implode(',', $ids['ids']),
'smsstatus' => '1'
);
sms_addon_smslogger($log, $this);
return true;
} catch (Exception $e) {
// Log result using the following query
$log = array('clientid' => $client_id,
'mobilenumber' => $client_mobile,
'smsbody' => $this->sms_body,
'smsmethod' => $this->smsmethod,
'apiresponse' => $response,
'apiref' => '',
'smsstatus' => '0'
);
sms_addon_smslogger($log, $this);
return $e;
}
}
}
function smsBalance() { // Remove this function if balance isn't supported by SMS Gateway API
// Code to get balance from API
try {
$response = sms_addon_curl("https://gatewayapi.com/rest/me",array('apitoken' => $this->apitoken));
$data = json_decode($response, true);
return $data['credit'];
} catch (Exception $e) {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment