Compare commits
6 Commits
017c7fee53
...
eeba3104e2
Author | SHA1 | Date |
---|---|---|
osaajani | eeba3104e2 | |
osaajani | e1c617c3b7 | |
osaajani | 4e03ce55bd | |
osaajani | 05d488490a | |
osaajani | 0e2908cb83 | |
osaajani | 88ebc8042c |
|
@ -16,10 +16,8 @@ namespace adapters;
|
||||||
*/
|
*/
|
||||||
class OctopushShortcodeAdapter implements AdapterInterface
|
class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
{
|
{
|
||||||
const ERROR_CODE_OK = '000';
|
const SMS_TYPE_LOWCOST = 'sms_low_cost';
|
||||||
const SMS_TYPE_LOWCOST = 'XXX';
|
const SMS_TYPE_PREMIUM = 'sms_premium';
|
||||||
const SMS_TYPE_PREMIUM = 'FR';
|
|
||||||
const SMS_TYPE_INTERNATIONAL = 'WWW';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
|
* Data used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
|
||||||
|
@ -40,11 +38,17 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
* Sender name to use instead of shortcode.
|
* Sender name to use instead of shortcode.
|
||||||
*/
|
*/
|
||||||
private $sender;
|
private $sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Octopush SMS type
|
||||||
|
*/
|
||||||
|
private $sms_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Octopush api baseurl.
|
* Octopush api baseurl.
|
||||||
*/
|
*/
|
||||||
private $api_url = 'https://www.octopush-dm.com/api';
|
private $api_url = 'https://api.octopush.com/v1/public';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||||
|
@ -58,6 +62,13 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
|
|
||||||
$this->login = $this->data['login'];
|
$this->login = $this->data['login'];
|
||||||
$this->api_key = $this->data['api_key'];
|
$this->api_key = $this->data['api_key'];
|
||||||
|
|
||||||
|
$this->sms_type = self::SMS_TYPE_LOWCOST;
|
||||||
|
if (($this->data['sms_type'] ?? false) && $this->data['sms_type'] === 'premium')
|
||||||
|
{
|
||||||
|
$this->sms_type = self::SMS_TYPE_PREMIUM;
|
||||||
|
}
|
||||||
|
|
||||||
$this->sender = $this->data['sender'] ?? null;
|
$this->sender = $this->data['sender'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +141,12 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
'description' => 'Clef API octopush. Trouvable sur la page des identifiants API Octopush.',
|
'description' => 'Clef API octopush. Trouvable sur la page des identifiants API Octopush.',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => 'sms_type',
|
||||||
|
'title' => 'Type de SMS à employer',
|
||||||
|
'description' => 'Type de SMS à employer coté Octopush, rentrez "low cost" ou "premium" selon le type de SMS que vous souhaitez employer. Laissez vide pour utiliser par défaut des SMS low cost.',
|
||||||
|
'required' => false,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'name' => 'sender',
|
'name' => 'sender',
|
||||||
'title' => 'Nom de l\'expéditeur',
|
'title' => 'Nom de l\'expéditeur',
|
||||||
|
@ -209,21 +226,32 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$data = [
|
$headers = [
|
||||||
'user_login' => $this->login,
|
'api-login: ' . $this->login,
|
||||||
'api_key' => $this->api_key,
|
'api-key: ' . $this->api_key,
|
||||||
'sms_text' => $text,
|
'Content-Type: application/json',
|
||||||
'sms_recipients' => str_replace('+', '00', $destination), //Must use 00 instead of + notation
|
|
||||||
'sms_sender' => '12345',
|
|
||||||
'sms_type' => self::SMS_TYPE_LOWCOST,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (null !== $this->sender)
|
$data = [
|
||||||
|
'text' => $text,
|
||||||
|
'recipients' => [['phone_number' => $destination]],
|
||||||
|
'sms_type' => $this->sms_type,
|
||||||
|
'purpose' => 'alert',
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($this->sender)
|
||||||
{
|
{
|
||||||
$data['sms_sender'] = $this->sender;
|
$data['sender'] = $this->sender;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data['with_replies'] = "True";
|
||||||
}
|
}
|
||||||
|
|
||||||
$endpoint = $this->api_url . '/sms/json';
|
$data = json_encode($data);
|
||||||
|
|
||||||
|
|
||||||
|
$endpoint = $this->api_url . '/sms-campaign/send';
|
||||||
|
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
||||||
|
@ -231,10 +259,13 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||||
curl_setopt($curl, CURLOPT_POST, true);
|
curl_setopt($curl, CURLOPT_POST, true);
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||||
$response = curl_exec($curl);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
$curl_response = curl_exec($curl);
|
||||||
|
$http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
if (false === $response)
|
if (false === $curl_response)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
$response['error_message'] = 'HTTP query failed.';
|
$response['error_message'] = 'HTTP query failed.';
|
||||||
|
@ -242,7 +273,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$response_decode = json_decode($response, true);
|
$response_decode = json_decode($curl_response, true);
|
||||||
if (null === $response_decode)
|
if (null === $response_decode)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
|
@ -251,15 +282,15 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
if (200 !== $http_code)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
|
$response['error_message'] = 'Response indicate error code : ' . $response_decode['code'] . ' -> """' . $response_decode['message'] . '""" AND HTTP CODE -> ' . $http_code;
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = $response_decode['ticket'] ?? false;
|
$uid = $response_decode['sms_ticket'] ?? false;
|
||||||
if (!$uid)
|
if (!$uid)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
|
@ -297,34 +328,29 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
if (!empty($this->data['sms_type']) && !in_array($this->data['sms_type'], ['premium', 'low cost']))
|
||||||
'user_login' => $this->login,
|
{
|
||||||
'api_key' => $this->api_key,
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'api-login: ' . $this->login,
|
||||||
|
'api-key: ' . $this->api_key,
|
||||||
|
'Content-Type: application/json',
|
||||||
];
|
];
|
||||||
|
|
||||||
//Check service name
|
//Check service name
|
||||||
$endpoint = $this->api_url . '/balance/json';
|
$endpoint = $this->api_url . '/wallet/check-balance';
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||||
curl_setopt($curl, CURLOPT_POST, true);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
|
$http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
if (false === $response)
|
if ($http_code !== 200)
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response_decode = json_decode($response, true);
|
|
||||||
if (null === $response_decode)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -343,14 +369,23 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
header('Content-Encoding: none');
|
header('Content-Encoding: none');
|
||||||
header('Content-Length: 0');
|
header('Content-Length: 0');
|
||||||
|
|
||||||
$uid = $_POST['message_id'] ?? false;
|
|
||||||
$status = $_POST['status'] ?? false;
|
$input = file_get_contents('php://input');
|
||||||
|
$content = json_decode($input, true);
|
||||||
|
if (null === $content)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uid = $content['message_id'] ?? false;
|
||||||
|
$status = $content['status'] ?? false;
|
||||||
|
|
||||||
if (false === $uid || false === $status)
|
if (false === $uid || false === $status)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch ($status)
|
switch ($status)
|
||||||
{
|
{
|
||||||
case 'DELIVERED':
|
case 'DELIVERED':
|
||||||
|
@ -358,10 +393,8 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'NOT_DELIVERED':
|
||||||
case 'NOT_ALLOWED':
|
case 'NOT_ALLOWED':
|
||||||
case 'INVALID_DESTINATION_ADDRESS':
|
|
||||||
case 'OUT_OF_DATE':
|
|
||||||
case 'EXPIRED':
|
|
||||||
case 'BLACKLISTED_NUMBER':
|
case 'BLACKLISTED_NUMBER':
|
||||||
$status = \models\Sended::STATUS_FAILED;
|
$status = \models\Sended::STATUS_FAILED;
|
||||||
|
|
||||||
|
@ -387,10 +420,20 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
header('Connection: close');
|
header('Connection: close');
|
||||||
header('Content-Encoding: none');
|
header('Content-Encoding: none');
|
||||||
header('Content-Length: 0');
|
header('Content-Length: 0');
|
||||||
|
|
||||||
|
$input = file_get_contents('php://input');
|
||||||
|
$content = json_decode($input, true);
|
||||||
|
if (null === $content)
|
||||||
|
{
|
||||||
|
$response['error'] = true;
|
||||||
|
$response['error_message'] = 'Cannot read input data from callback request.';
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
$number = $_POST['number'] ?? false;
|
$number = $content['number'] ?? false;
|
||||||
$text = $_POST['text'] ?? false;
|
$text = $content['text'] ?? false;
|
||||||
$at = $_POST['reception_date'] ?? false;
|
$at = $content['reception_date'] ?? false;
|
||||||
|
|
||||||
if (!$number || !$text || !$at)
|
if (!$number || !$text || !$at)
|
||||||
{
|
{
|
||||||
|
@ -400,11 +443,11 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$origin = \controllers\internals\Tool::parse_phone('+' . mb_substr($number, 2));
|
$origin = \controllers\internals\Tool::parse_phone($number);
|
||||||
if (!$origin)
|
if (!$origin)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
|
$response['error_message'] = 'Invalid origin number : ' . $number;
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,8 @@ namespace adapters;
|
||||||
*/
|
*/
|
||||||
class OctopushVirtualNumberAdapter implements AdapterInterface
|
class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
{
|
{
|
||||||
const ERROR_CODE_OK = '000';
|
const SMS_TYPE_LOWCOST = 'sms_low_cost';
|
||||||
const SMS_TYPE_LOWCOST = 'XXX';
|
const SMS_TYPE_PREMIUM = 'sms_premium';
|
||||||
const SMS_TYPE_PREMIUM = 'FR';
|
|
||||||
const SMS_TYPE_INTERNATIONAL = 'WWW';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
|
* Data used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
|
||||||
|
@ -37,19 +35,15 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
private $api_key;
|
private $api_key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number phone to use.
|
* Octopush SMS type
|
||||||
*/
|
*/
|
||||||
private $number;
|
private $sms_type;
|
||||||
|
|
||||||
/**
|
|
||||||
* Number phone to use formated for octopush compatibility.
|
|
||||||
*/
|
|
||||||
private $formatted_number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Octopush api baseurl.
|
* Octopush api baseurl.
|
||||||
*/
|
*/
|
||||||
private $api_url = 'https://www.octopush-dm.com/api';
|
private $api_url = 'https://api.octopush.com/v1/public';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||||
|
@ -64,7 +58,12 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
$this->login = $this->data['login'];
|
$this->login = $this->data['login'];
|
||||||
$this->api_key = $this->data['api_key'];
|
$this->api_key = $this->data['api_key'];
|
||||||
$this->number = $this->data['number'];
|
$this->number = $this->data['number'];
|
||||||
$this->formatted_number = '+' . mb_substr($this->data['number'], 2);
|
|
||||||
|
$this->sms_type = self::SMS_TYPE_LOWCOST;
|
||||||
|
if (($this->data['sms_type'] ?? false) && $this->data['sms_type'] === 'premium')
|
||||||
|
{
|
||||||
|
$this->sms_type = self::SMS_TYPE_PREMIUM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,6 +113,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
Envoi de SMS avec un numéro virtuel en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a><br/>
|
Envoi de SMS avec un numéro virtuel en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a><br/>
|
||||||
Pour plus d\'information sur l\'utilisation de ce téléphone, reportez-vous à <a href="https://documentation.raspisms.fr/users/adapters/octopush_virtual_number.html" target="_blank">la documentation sur les téléphones "Octopush Numéro Virtuel".</a>
|
Pour plus d\'information sur l\'utilisation de ce téléphone, reportez-vous à <a href="https://documentation.raspisms.fr/users/adapters/octopush_virtual_number.html" target="_blank">la documentation sur les téléphones "Octopush Numéro Virtuel".</a>
|
||||||
';
|
';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,7 +143,13 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'number' => true,
|
'number' => true,
|
||||||
],
|
],
|
||||||
];
|
[
|
||||||
|
'name' => 'sms_type',
|
||||||
|
'title' => 'Type de SMS à employer',
|
||||||
|
'description' => 'Type de SMS à employer coté Octopush, rentrez "low cost" ou "premium" selon le type de SMS que vous souhaitez employer. Laissez vide pour utiliser par défaut des SMS low cost.',
|
||||||
|
'required' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,16 +220,25 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$data = [
|
$headers = [
|
||||||
'user_login' => $this->login,
|
'api-login: ' . $this->login,
|
||||||
'api_key' => $this->api_key,
|
'api-key: ' . $this->api_key,
|
||||||
'sms_text' => $text,
|
'Content-Type: application/json',
|
||||||
'sms_recipients' => str_replace('+', '00', $destination), //Must use 00 instead of + notation
|
|
||||||
'sms_sender' => $this->formatted_number,
|
|
||||||
'sms_type' => self::SMS_TYPE_LOWCOST,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$endpoint = $this->api_url . '/sms/json';
|
$data = [
|
||||||
|
'text' => $text,
|
||||||
|
'recipients' => [['phone_number' => $destination]],
|
||||||
|
'sms_type' => $this->sms_type,
|
||||||
|
'purpose' => 'alert',
|
||||||
|
'sender' => $this->number,
|
||||||
|
'with_replies' => "True",
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = json_encode($data);
|
||||||
|
|
||||||
|
|
||||||
|
$endpoint = $this->api_url . '/sms-campaign/send';
|
||||||
|
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
||||||
|
@ -231,10 +246,13 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||||
curl_setopt($curl, CURLOPT_POST, true);
|
curl_setopt($curl, CURLOPT_POST, true);
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||||
$response = curl_exec($curl);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
$curl_response = curl_exec($curl);
|
||||||
|
$http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
if (false === $response)
|
if (false === $curl_response)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
$response['error_message'] = 'HTTP query failed.';
|
$response['error_message'] = 'HTTP query failed.';
|
||||||
|
@ -242,7 +260,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$response_decode = json_decode($response, true);
|
$response_decode = json_decode($curl_response, true);
|
||||||
if (null === $response_decode)
|
if (null === $response_decode)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
|
@ -251,15 +269,15 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
if (200 !== $http_code)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
|
$response['error_message'] = 'Response indicate error code : ' . $response_decode['code'] . ' -> """' . $response_decode['message'] . '""" AND HTTP CODE -> ' . $http_code;
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = $response_decode['ticket'] ?? false;
|
$uid = $response_decode['sms_ticket'] ?? false;
|
||||||
if (!$uid)
|
if (!$uid)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
|
@ -292,39 +310,35 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
{
|
{
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
||||||
if ($this->data['sender'] && (mb_strlen($this->data['sender']) < 3 || mb_strlen($this->data['sender'] > 11)))
|
if (!empty($this->data['sms_type']) && !in_array($this->data['sms_type'], ['premium', 'low cost']))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
$origin = \controllers\internals\Tool::parse_phone($this->data['number']);
|
||||||
'user_login' => $this->login,
|
if (!$origin)
|
||||||
'api_key' => $this->api_key,
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'api-login: ' . $this->login,
|
||||||
|
'api-key: ' . $this->api_key,
|
||||||
|
'Content-Type: application/json',
|
||||||
];
|
];
|
||||||
|
|
||||||
//Check service name
|
//Check service name
|
||||||
$endpoint = $this->api_url . '/balance/json';
|
$endpoint = $this->api_url . '/wallet/check-balance';
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
curl_setopt($curl, CURLOPT_URL, $endpoint);
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||||
curl_setopt($curl, CURLOPT_POST, true);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
|
$http_code = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
if (false === $response)
|
if ($http_code !== 200)
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response_decode = json_decode($response, true);
|
|
||||||
if (null === $response_decode)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -343,14 +357,23 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
header('Content-Encoding: none');
|
header('Content-Encoding: none');
|
||||||
header('Content-Length: 0');
|
header('Content-Length: 0');
|
||||||
|
|
||||||
$uid = $_POST['message_id'] ?? false;
|
|
||||||
$status = $_POST['status'] ?? false;
|
$input = file_get_contents('php://input');
|
||||||
|
$content = json_decode($input, true);
|
||||||
|
if (null === $content)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uid = $content['message_id'] ?? false;
|
||||||
|
$status = $content['status'] ?? false;
|
||||||
|
|
||||||
if (false === $uid || false === $status)
|
if (false === $uid || false === $status)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch ($status)
|
switch ($status)
|
||||||
{
|
{
|
||||||
case 'DELIVERED':
|
case 'DELIVERED':
|
||||||
|
@ -358,10 +381,8 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'NOT_DELIVERED':
|
||||||
case 'NOT_ALLOWED':
|
case 'NOT_ALLOWED':
|
||||||
case 'INVALID_DESTINATION_ADDRESS':
|
|
||||||
case 'OUT_OF_DATE':
|
|
||||||
case 'EXPIRED':
|
|
||||||
case 'BLACKLISTED_NUMBER':
|
case 'BLACKLISTED_NUMBER':
|
||||||
$status = \models\Sended::STATUS_FAILED;
|
$status = \models\Sended::STATUS_FAILED;
|
||||||
|
|
||||||
|
@ -381,16 +402,26 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
$response = [
|
$response = [
|
||||||
'error' => false,
|
'error' => false,
|
||||||
'error_message' => null,
|
'error_message' => null,
|
||||||
'uid' => null,
|
'sms' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
header('Connection: close');
|
header('Connection: close');
|
||||||
header('Content-Encoding: none');
|
header('Content-Encoding: none');
|
||||||
header('Content-Length: 0');
|
header('Content-Length: 0');
|
||||||
|
|
||||||
|
$input = file_get_contents('php://input');
|
||||||
|
$content = json_decode($input, true);
|
||||||
|
if (null === $content)
|
||||||
|
{
|
||||||
|
$response['error'] = true;
|
||||||
|
$response['error_message'] = 'Cannot read input data from callback request.';
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
$number = $_POST['number'] ?? false;
|
$number = $content['number'] ?? false;
|
||||||
$text = $_POST['text'] ?? false;
|
$text = $content['text'] ?? false;
|
||||||
$at = $_POST['reception_date'] ?? false;
|
$at = $content['reception_date'] ?? false;
|
||||||
|
|
||||||
if (!$number || !$text || !$at)
|
if (!$number || !$text || !$at)
|
||||||
{
|
{
|
||||||
|
@ -400,11 +431,11 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$origin = \controllers\internals\Tool::parse_phone('+' . mb_substr($number, 2));
|
$origin = \controllers\internals\Tool::parse_phone($number);
|
||||||
if (!$origin)
|
if (!$origin)
|
||||||
{
|
{
|
||||||
$response['error'] = true;
|
$response['error'] = true;
|
||||||
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
|
$response['error_message'] = 'Invalid origin number : ' . $number;
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,4 +139,15 @@ jQuery(document).ready(function()
|
||||||
form.trigger("reset");
|
form.trigger("reset");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jQuery('body').on('change', '.datatable #check-all', function (e) {
|
||||||
|
if (jQuery(e.target).is(':checked'))
|
||||||
|
{
|
||||||
|
jQuery(e.target).parents('.datatable').find('input[type="checkbox"]').prop('checked', true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jQuery(e.target).parents('.datatable').find('input[type="checkbox"]').prop('checked', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -191,7 +191,7 @@ use Monolog\Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sms = $response['sms'];
|
$sms = $response['sms'];
|
||||||
$mms = (bool) $sms['mms'] ?? false;
|
$mms = (bool) ($sms['mms'] ?? false);
|
||||||
$medias = empty($sms['medias']) ? [] : $sms['medias'];
|
$medias = empty($sms['medias']) ? [] : $sms['medias'];
|
||||||
|
|
||||||
$response = $this->internal_received->receive($this->user['id'], $id_phone, $sms['text'], $sms['origin'], $sms['at'], \models\Received::STATUS_UNREAD, $mms, $medias);
|
$response = $this->internal_received->receive($this->user['id'], $id_phone, $sms['text'], $sms['origin'], $sms['at'], \models\Received::STATUS_UNREAD, $mms, $medias);
|
||||||
|
|
|
@ -77,11 +77,11 @@ namespace controllers\publics;
|
||||||
$stats_start_date_formated = $stats_start_date->format('Y-m-d');
|
$stats_start_date_formated = $stats_start_date->format('Y-m-d');
|
||||||
|
|
||||||
//If user have a quota and the quota start before today, use quota start date instead
|
//If user have a quota and the quota start before today, use quota start date instead
|
||||||
$quota_limit = false;
|
$quota_unused = false;
|
||||||
$quota = $this->internal_quota->get_user_quota($id_user);
|
$quota = $this->internal_quota->get_user_quota($id_user);
|
||||||
if ($quota && (new \DateTime($quota['start_date']) <= $now) && (new \DateTime($quota['expiration_date']) > $now))
|
if ($quota && (new \DateTime($quota['start_date']) <= $now) && (new \DateTime($quota['expiration_date']) > $now))
|
||||||
{
|
{
|
||||||
$quota_limit = $quota['credit'] + $quota['additional'];
|
$quota_unused = $quota['credit'] + $quota['additional'] - $quota['consumed'];
|
||||||
|
|
||||||
$stats_start_date = new \DateTime($quota['start_date']);
|
$stats_start_date = new \DateTime($quota['start_date']);
|
||||||
$stats_start_date_formated = $stats_start_date->format('Y-m-d');
|
$stats_start_date_formated = $stats_start_date->format('Y-m-d');
|
||||||
|
@ -141,7 +141,7 @@ namespace controllers\publics;
|
||||||
'nb_unreads' => $nb_unreads,
|
'nb_unreads' => $nb_unreads,
|
||||||
'avg_sendeds' => $avg_sendeds,
|
'avg_sendeds' => $avg_sendeds,
|
||||||
'avg_receiveds' => $avg_receiveds,
|
'avg_receiveds' => $avg_receiveds,
|
||||||
'quota_limit' => $quota_limit,
|
'quota_unused' => $quota_unused,
|
||||||
'sendeds' => $sendeds,
|
'sendeds' => $sendeds,
|
||||||
'receiveds' => $receiveds,
|
'receiveds' => $receiveds,
|
||||||
'events' => $events,
|
'events' => $events,
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
<th>Début de l'appel</th>
|
<th>Début de l'appel</th>
|
||||||
<th>Fin de l'appel</th>
|
<th>Fin de l'appel</th>
|
||||||
<th>Direction</th>
|
<th>Direction</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
<th>Nom</th>
|
<th>Nom</th>
|
||||||
<th>Script</th>
|
<th>Script</th>
|
||||||
<th>Admin obligatoire</th>
|
<th>Admin obligatoire</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<th>Condition</th>
|
<th>Condition</th>
|
||||||
<th>Date de création</th>
|
<th>Date de création</th>
|
||||||
<th>Dernière modification</th>
|
<th>Dernière modification</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
<th>Numéro</th>
|
<th>Numéro</th>
|
||||||
<th>Date de création</th>
|
<th>Date de création</th>
|
||||||
<th>Dernière modification</th>
|
<th>Dernière modification</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -123,9 +123,9 @@
|
||||||
<h3 class="panel-title"><i class="fa fa-area-chart fa-fw"></i> Activité de la semaine : </h3>
|
<h3 class="panel-title"><i class="fa fa-area-chart fa-fw"></i> Activité de la semaine : </h3>
|
||||||
<span style="color: #5CB85C;">SMS envoyés (moyenne = <?php echo $avg_sendeds; ?> par jour).</span><br/>
|
<span style="color: #5CB85C;">SMS envoyés (moyenne = <?php echo $avg_sendeds; ?> par jour).</span><br/>
|
||||||
<span style="color: #EDAB4D">SMS reçus (moyenne = <?php echo $avg_receiveds; ?> par jour).</span>
|
<span style="color: #EDAB4D">SMS reçus (moyenne = <?php echo $avg_receiveds; ?> par jour).</span>
|
||||||
<?php if ($quota_limit) { ?>
|
<?php if ($quota_unused) { ?>
|
||||||
<br/>
|
<br/>
|
||||||
<span style="color: #d9534f">Limite max de SMS sur la période (<?= $quota_limit; ?>).</span>
|
<span style="color: #d9534f">Crédits restants : <?= $quota_unused; ?>.</span>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
@ -254,8 +254,8 @@
|
||||||
ykeys: ['sendeds', 'receiveds'],
|
ykeys: ['sendeds', 'receiveds'],
|
||||||
labels: ['SMS envoyés', 'SMS reçus'],
|
labels: ['SMS envoyés', 'SMS reçus'],
|
||||||
lineColors: ['#5CB85C', '#EDAB4D'],
|
lineColors: ['#5CB85C', '#EDAB4D'],
|
||||||
goals: [<?php echo $avg_sendeds; ?>, <?php echo $avg_receiveds; ?><?= $quota_limit ? ',' . $quota_limit : ''; ?>],
|
goals: [<?php echo $avg_sendeds; ?>, <?php echo $avg_receiveds; ?>],
|
||||||
goalLineColors: ['#5CB85C', '#EDAB4D', '#d9534f'],
|
goalLineColors: ['#5CB85C', '#EDAB4D'],
|
||||||
goalStrokeWidth: 2,
|
goalStrokeWidth: 2,
|
||||||
pointSize: 4,
|
pointSize: 4,
|
||||||
hideHover: 'auto',
|
hideHover: 'auto',
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Texte</th>
|
<th>Texte</th>
|
||||||
<?php if ($_SESSION['user']['admin']) { ?>
|
<?php if ($_SESSION['user']['admin']) { ?>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<th>Nombre de contacts</th>
|
<th>Nombre de contacts</th>
|
||||||
<th>Date de création</th>
|
<th>Date de création</th>
|
||||||
<th>Dernière modification</th>
|
<th>Dernière modification</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<?php if (!in_array('log', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
|
<?php if (!in_array('logs', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:;" data-toggle="collapse" data-target="#logs"><i class="fa fa-fw fa-file-text"></i> Logs <i class="fa fa-fw fa-caret-down"></i></a>
|
<a href="javascript:;" data-toggle="collapse" data-target="#logs"><i class="fa fa-fw fa-file-text"></i> Logs <i class="fa fa-fw fa-caret-down"></i></a>
|
||||||
<ul id="logs" class="collapse <?php echo in_array($page, array('events', 'smsstop', 'calls')) ? 'in' : ''; ?>">
|
<ul id="logs" class="collapse <?php echo in_array($page, array('events', 'smsstop', 'calls')) ? 'in' : ''; ?>">
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<th>Nom</th>
|
<th>Nom</th>
|
||||||
<th>Type de téléphone</th>
|
<th>Type de téléphone</th>
|
||||||
<th>Callbacks</th>
|
<th>Callbacks</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Commande</th>
|
<th>Commande</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Contenu</th>
|
<th>Contenu</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
<th>Message</th>
|
<th>Message</th>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Statut</th>
|
<th>Statut</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Numéro</th>
|
<th>Numéro</th>
|
||||||
<?php if ($_SESSION['user']['admin']) { ?>
|
<?php if ($_SESSION['user']['admin']) { ?>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<th>Admin</th>
|
<th>Admin</th>
|
||||||
<th>Statut</th>
|
<th>Statut</th>
|
||||||
<th>Crédit utilisé</th>
|
<th>Crédit utilisé</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Url</th>
|
<th>Url</th>
|
||||||
<th>Type de webhook</th>
|
<th>Type de webhook</th>
|
||||||
<th class="checkcolumn">✓</th>
|
<th class="checkcolumn"><input type="checkbox" id="check-all"/></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
Loading…
Reference in New Issue