Skip to content

Instantly share code, notes, and snippets.

@nsorosac
Last active September 1, 2015 08:28
Show Gist options
  • Save nsorosac/9245908b564ca45820e1 to your computer and use it in GitHub Desktop.
Save nsorosac/9245908b564ca45820e1 to your computer and use it in GitHub Desktop.
<?php
class SMS_OVH
{
const SMS_SOAPI_VERSION = '1.63';
const SMS_LOGIN = 'xxxxxxxxxx';
const SMS_PASS = 'xxxxxxxxxx';
const SMS_ACCOUNT = 'xxxxxxxxxx';
const SMS_FROM = 'xxxxxxxxxx';
const SMS_NO_STOP = true;
/**
* @param string $to
* @param string $message
* @return bool
* @throws SoapFault
* @see http://guides.ovh.com/TelSmsSend
* @see http://www.ovh.com/soapi/fr/?method=telephonySmsSend
*/
public static function send($to, $message)
{
# Numéro de téléphone de l'internaute
$sms_to = self::formatPhoneNumber($to);
# Validation du numéro de téléphone
if ($sms_to !== false) {
# API SOAP d'OVH
$sms_soap = new SoapClient('https://www.ovh.com/soapi/soapi-re-' . self::SMS_SOAPI_VERSION . '.wsdl');
$sms_session = $sms_soap->login(self::SMS_LOGIN, self::SMS_PASS, 'fr', false);
$sms_message = $message;
# Envoi du message
$sms_result = $sms_soap->telephonySmsSend($sms_session, self::SMS_ACCOUNT, self::SMS_FROM, $sms_to, $sms_message, '', 1, '', '', '', '', self::SMS_NO_STOP);
$sms_soap->logout($sms_session);
return $sms_result;
}
return false;
}
public static function formatPhoneNumber($phone)
{
# Ne garder que les chiffres
$phone = preg_replace('/[^0-9]/', '', $phone);
# Il reste au moins 9 chiffres
if (strlen($phone < 9)) return false;
# Ne garder que les parties intéressantes (enlever le 0 ou le 33 avant)
$phone = substr($phone, -9);
# Pas de 06 ou de 07 ?
if (!preg_match('/[67]{1}[0-9]{8}/', $phone)) return false;
# Validation OK
return '+33' . $phone;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment