Sms.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Define a sms.
  4. * @author Valentin CARRUESCO
  5. * @category API
  6. * @license MIT
  7. * pour ajouter des api : https://api.ovh.com/console/#/sms
  8. */
  9. class Sms {
  10. const ENDPOINT = "ovh-eu";
  11. public $consumer,$key,$secret,$service,$phone,$message,$token;
  12. public function send(){
  13. if(empty($this->key)) throw new Exception("Merci de renseigner le champ API key");
  14. if(empty($this->secret)) throw new Exception("Merci de renseigner le champ API secret");
  15. if(empty($this->consumer)) throw new Exception("Merci de renseigner le champ API Consumer");
  16. if(empty($this->phone)) throw new Exception("Merci de renseigner le champ n°téléphone ");
  17. if(empty($this->message)) throw new Exception("Merci de renseigner le champ message");
  18. if(substr($this->phone, 0,1)=='0') $this->phone = '+33'.substr($this->phone, 1);
  19. require __DIR__ . '/vendor/autoload.php';
  20. $ovh = new \Ovh\Api( $this->key ,
  21. $this->secret,
  22. self::ENDPOINT,
  23. $this->consumer);
  24. $content = (object) array(
  25. "charset"=> "UTF-8",
  26. "class"=> "phoneDisplay",
  27. "coding"=> "7bit",
  28. "message"=> $this->message,
  29. "noStopClause"=> false,
  30. "priority"=> "high",
  31. "receivers"=> array( $this->phone ),
  32. "senderForResponse"=> true,
  33. "validityPeriod"=> 2880
  34. );
  35. $response = $ovh->post('/sms/'. $this->service . '/jobs', $content);
  36. if(isset($response['invalidReceivers']) && count($response['invalidReceivers'])>0) throw new Exception("Les numéros suivants sont invalides : ".implode(', ',$response['invalidReceivers']));
  37. }
  38. public function info($service){
  39. require __DIR__ . '/vendor/autoload.php';
  40. $ovh = new \Ovh\Api( $this->key ,
  41. $this->secret,
  42. self::ENDPOINT,
  43. $this->consumer);
  44. return $ovh->get('/sms/'.$service);
  45. }
  46. public function services(){
  47. require __DIR__ . '/vendor/autoload.php';
  48. $ovh = new \Ovh\Api( $this->key ,
  49. $this->secret,
  50. self::ENDPOINT,
  51. $this->consumer);
  52. return $ovh->get('/sms/');
  53. }
  54. }
  55. ?>