Update Octopush.php (#1147)

* Update Octopush.php

Now works with the new API V1 : https://octopush.com/en/sms-gateway-api-documentation/

* Update Octopush.php

* Updated send check

Co-authored-by: Tim Zandbergen <TimZ99@users.noreply.github.com>
This commit is contained in:
Marc Farré 2021-12-11 01:36:08 +01:00 committed by GitHub
parent 74dfeea08b
commit 8dcf5c2666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 40 deletions

View File

@ -20,11 +20,12 @@
* *
* @package phpservermon * @package phpservermon
* @author Alexis Urien <Alexis.urien@free.fr> * @author Alexis Urien <Alexis.urien@free.fr>
* @Author Tim Zandbergen <Tim@Xervion.nl> * @author Tim Zandbergen <Tim@Xervion.nl>
* @author Ward Pieters <ward@wardpieters.nl> * @author Ward Pieters <ward@wardpieters.nl>
* @author Marc Farré <contact@marc.fun>
* @copyright Copyright (c) 2016 Alexis Urien <alexis.urien@free.fr> * @copyright Copyright (c) 2016 Alexis Urien <alexis.urien@free.fr>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: v3.5.2
* @link http://www.phpservermonitor.org/ * @link http://www.phpservermonitor.org/
* @since phpservermon 2.1 * @since phpservermon 2.1
**/ **/
@ -42,58 +43,57 @@ class Octopush extends Core
* @var array $this->recipients * @var array $this->recipients
* @var array $this->originator * @var array $this->originator
* *
* @var resource $curl * @var resource $ch
* @var SimpleXMLElement $xmlResults * @var SimpleXMLElement $xmlResults
* @var string $err * @var string $err
* @var string $recipient * @var string $recipient
* @var string $smsType * @var string $smsType
* @var mixed $result * @var mixed $result
* *
* @var int $success
* @var string $error
*
* @return bool|string * @return bool|string
*/ */
public function sendSMS($message) public function sendSMS($message)
{ {
$error = ""; $smsType = "sms_premium"; // Or "sms_low_cost"
$success = 1;
$smsType = "FR"; //FR = premium, WWW = world, XXX = Low cost
$recipients = join(',', $this->recipients);
$message = ($smsType == "FR") ? rawurlencode($message . " STOP au XXXXX") : rawurlencode($message);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.octopush-dm.com/api/sms/?" . http_build_query(
array(
"user_login" => $this->username,
"api_key" => $this->password,
"sms_recipients" => $recipients,
"sms_type" => $smsType,
"sms_sender" => substr($this->originator, 0, 15),
"sms_text" => $message,
)
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$xmlResults = simplexml_load_string($result);
$err = curl_errno($curl);
if ($err != 0 || $httpcode != 200 || $xmlResults === false || $xmlResults->error_code != '000') { $ch = curl_init();
$success = 0;
$error = "HTTP_code: " . $httpcode . ".\ncURL error (" . $err . "): " . curl_strerror($err) . curl_setopt($ch, CURLOPT_URL, 'https://api.octopush.com/v1/public/sms-campaign/send');
". \nResult: " . $xmlResults->error_code . curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
". Look at http://www.octopush-dm.com/en/errors for the error description."; curl_setopt($ch, CURLOPT_POST, 1);
$recipients = [];
foreach ($this->recipients as $recipient) {
$recipients[] = ['phone_number' => ((substr($recipient, 0, 1) != '+') ? '+' : '').(string)$recipient];
} }
curl_close($curl);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
if ($success) { 'recipients' => $recipients,
return 1; 'text' => $message.(($smsType === "sms_premium") ? ' STOP au XXXXX' : ''),
'type' => $smsType,
'purpose' => 'alert',
'with_replies' => false,
'sender' => substr($this->originator, 0, 15),
]));
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Api-Key: '.$this->password;
$headers[] = 'Api-Login: '.$this->username;
$headers[] = 'Cache-Control: no-cache';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = json_decode(curl_exec($ch), true);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_errno($ch);
curl_close($ch);
if ($err != 0 || $httpcode != 201) {
return $result['code'] . " - " . $result['message'];
} }
return $error;
return 1;
} }
} }