mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-20 02:10:50 +02:00
Initial commit
Functional, without SSO
This commit is contained in:
83
sources/lib/Message/Adapter/SmsFreeMobile.php
Normal file
83
sources/lib/Message/Adapter/SmsFreeMobile.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Message\Adapter;
|
||||
|
||||
class SmsFreeMobile extends AdapterAbstract
|
||||
{
|
||||
protected $notify_url = "https://smsapi.free-mobile.fr/sendmsg";
|
||||
protected $user;
|
||||
protected $key;
|
||||
|
||||
protected $curl_options = array(
|
||||
CURLOPT_SSL_VERIFYPEER => false
|
||||
);
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send($message, array $options = array())
|
||||
{
|
||||
$this->setOptions($options);
|
||||
if (!$this->user || !$this->key) {
|
||||
throw new \Exception("Un des paramètres obligatoires est manquant", 400);
|
||||
}
|
||||
$message = trim($message);
|
||||
if ($url = $this->getUrl()) {
|
||||
$message .= ": ".$url;
|
||||
}
|
||||
$curl = $this->getCurl(array(
|
||||
CURLOPT_URL => $this->notify_url."?user=".$this->user.
|
||||
"&pass=".$this->key.
|
||||
"&msg=".urlencode($message)
|
||||
));
|
||||
curl_exec($curl);
|
||||
if (200 != $code = curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
|
||||
switch ($code) {
|
||||
case 400: $message = "Un des paramètres obligatoires est manquant."; break;
|
||||
case 402: $message = "Trop de SMS ont été envoyés en trop peu de temps."; break;
|
||||
case 403: $message = "Vous n'avez pas activé la notification SMS dans votre espace abonné Free Mobile ou votre identifiant/clé est incorrect."; break;
|
||||
case 500: $message = "erreur sur serveur Free Mobile."; break;
|
||||
default: $message = "erreur inconnue.";
|
||||
}
|
||||
throw new \Exception($message, $code);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @return \Message\SMS\FreeMobile
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return \Message\SMS\FreeMobile
|
||||
*/
|
||||
public function setKey($key)
|
||||
{
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user