. * * @package phpservermon * @author Alexis Urien * @author Tim Zandbergen * @author Ward Pieters * @author Marc Farré * @copyright Copyright (c) 2016 Alexis Urien * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @version Release: v3.5.2 * @link http://www.phpservermonitor.org/ * @since phpservermon 2.1 **/ namespace psm\Txtmsg; class Octopush extends Core { /** * Send sms using the Octopush API * @var string $message * @var string $this->username * @var string $this->password * @var array $this->recipients * @var array $this->originator * * @var resource $ch * @var SimpleXMLElement $xmlResults * @var string $err * @var string $recipient * @var string $smsType * @var mixed $result * * @return bool|string */ public function sendSMS($message) { $smsType = "sms_premium"; // Or "sms_low_cost" $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.octopush.com/v1/public/sms-campaign/send'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'api-login: '.$this->username, 'api-key: '.$this->password, 'cache-control: no-cache', ]); $recipients = []; foreach ($this->recipients as $recipient) { $recipients[] = ['phone_number' => ((substr($recipient, 0, 1) != '+') ? '+' : '').(string)$recipient]; } curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'recipients' => $recipients, 'text' => $message.(($smsType === "sms_premium") ? ' STOP au XXXXX' : ''), 'type' => $smsType, 'purpose' => 'alert', 'with_replies' => false, 'sender' => substr($this->originator, 0, 15), ])); $response = curl_exec($ch); $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 && $httpcode != 200)) { return $result['code'] . " - " . $result['message']; } return 1; } }