Merge 1038a52690
into 8ca259d524
commit
53bd8c72ef
|
@ -578,6 +578,9 @@ function psm_build_sms() {
|
||||||
case 'twilio':
|
case 'twilio':
|
||||||
$sms = new \psm\Txtmsg\Twilio();
|
$sms = new \psm\Txtmsg\Twilio();
|
||||||
break;
|
break;
|
||||||
|
case 'gatewayapi':
|
||||||
|
$sms = new \psm\Txtmsg\GatewayAPI();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy login information from the config file
|
// copy login information from the config file
|
||||||
|
|
|
@ -254,6 +254,7 @@ $sm_lang = array(
|
||||||
'sms_gateway_nexmo' => 'Nexmo',
|
'sms_gateway_nexmo' => 'Nexmo',
|
||||||
'sms_gateway_smsgw' => 'SMSgw',
|
'sms_gateway_smsgw' => 'SMSgw',
|
||||||
'sms_gateway_twilio' => 'Twilio',
|
'sms_gateway_twilio' => 'Twilio',
|
||||||
|
'sms_gateway_gatewayapi' => 'GatewayAPI',
|
||||||
'sms_gateway_username' => 'Gateway username',
|
'sms_gateway_username' => 'Gateway username',
|
||||||
'sms_gateway_password' => 'Gateway password',
|
'sms_gateway_password' => 'Gateway password',
|
||||||
'sms_from' => 'Sender\'s phone number',
|
'sms_from' => 'Sender\'s phone number',
|
||||||
|
|
|
@ -378,6 +378,7 @@ class ConfigController extends AbstractController {
|
||||||
'label_sms_gateway_freemobilesms' => psm_get_lang('config', 'sms_gateway_freemobilesms'),
|
'label_sms_gateway_freemobilesms' => psm_get_lang('config', 'sms_gateway_freemobilesms'),
|
||||||
'label_sms_gateway_clicksend' => psm_get_lang('config', 'sms_gateway_clicksend'),
|
'label_sms_gateway_clicksend' => psm_get_lang('config', 'sms_gateway_clicksend'),
|
||||||
'label_sms_gateway_twilio' => psm_get_lang('config', 'sms_gateway_twilio'),
|
'label_sms_gateway_twilio' => psm_get_lang('config', 'sms_gateway_twilio'),
|
||||||
|
'label_sms_gateway_gatewayapi' => psm_get_lang('config', 'sms_gateway_gatewayapi'),
|
||||||
'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'),
|
'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'),
|
||||||
'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'),
|
'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'),
|
||||||
'label_sms_from' => psm_get_lang('config', 'sms_from'),
|
'label_sms_from' => psm_get_lang('config', 'sms_from'),
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHP Server Monitor
|
||||||
|
* Monitor your servers and websites.
|
||||||
|
*
|
||||||
|
* This file is part of PHP Server Monitor.
|
||||||
|
* PHP Server Monitor is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PHP Server Monitor is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* @package phpservermon
|
||||||
|
* @author Ward Pieters <ward@wardpieters.nl>
|
||||||
|
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
|
||||||
|
* @version Release: @package_version@
|
||||||
|
* @link http://www.phpservermonitor.org/
|
||||||
|
**/
|
||||||
|
|
||||||
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
class GatewayAPI extends Core {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send sms using GatewayAPI
|
||||||
|
* @var string $message
|
||||||
|
* @var array $this->recipients
|
||||||
|
* @var string $recipient
|
||||||
|
* @var string $this->password
|
||||||
|
* @var string $this->originator
|
||||||
|
* @var int $success
|
||||||
|
* @var string $error
|
||||||
|
* @return int or string
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function sendSMS($message) {
|
||||||
|
$sender = $this->originator;
|
||||||
|
$apikey = $this->password;
|
||||||
|
$userref = $this->userref;
|
||||||
|
$destaddr = $this->destaddr;
|
||||||
|
$recipients = $this->recipients;
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if(is_null($destaddr)) $destaddr = 'MOBILE';
|
||||||
|
if(is_null($userref)) $userref = '';
|
||||||
|
|
||||||
|
|
||||||
|
foreach($recipients as $recipient) {
|
||||||
|
$json = [
|
||||||
|
'sender' => $sender,
|
||||||
|
'message' => $message,
|
||||||
|
'recipients' => [],
|
||||||
|
'destaddr' => $destaddr,
|
||||||
|
'userref' => $userref,
|
||||||
|
];
|
||||||
|
|
||||||
|
$json['recipients'][] = ['msisdn' => $recipient];
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch,CURLOPT_URL, "https://gatewayapi.com/rest/mtsms");
|
||||||
|
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
||||||
|
curl_setopt($ch,CURLOPT_USERPWD, $apikey.":");
|
||||||
|
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($json));
|
||||||
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$result = json_decode($result,true);
|
||||||
|
$addidtional_information = array();
|
||||||
|
foreach($result as $key => $value) { if($key != 'ids') $addidtional_information[$key] = $value; }
|
||||||
|
|
||||||
|
if($httpcode == 200) {
|
||||||
|
// SMS is gelukt
|
||||||
|
$output = array('success' => true, 'ids' => $result['ids'], 'addidtional_information' => $addidtional_information);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// SMS is niet gelukt
|
||||||
|
$output = array('success' => false, 'code' => $result['code'], 'message' => $result['message'], 'variables' => $result['variables']);
|
||||||
|
array_push($errors, $output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($errors)) return false;
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -203,6 +203,7 @@
|
||||||
<option value="smsgw" {{ sms_selected_smsgw|raw }}>{{ label_sms_gateway_smsgw }}</option>
|
<option value="smsgw" {{ sms_selected_smsgw|raw }}>{{ label_sms_gateway_smsgw }}</option>
|
||||||
<option value="nexmo" {{ sms_selected_nexmo|raw }}>{{ label_sms_gateway_nexmo }}</option>
|
<option value="nexmo" {{ sms_selected_nexmo|raw }}>{{ label_sms_gateway_nexmo }}</option>
|
||||||
<option value="twilio" {{ sms_selected_twilio|raw }}>{{ label_sms_gateway_twilio }}</option>
|
<option value="twilio" {{ sms_selected_twilio|raw }}>{{ label_sms_gateway_twilio }}</option>
|
||||||
|
<option value="gatewayapi" {{ sms_selected_gatewayapi|raw }}>{{ label_sms_gateway_gatewayapi }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue