avr/101
Integration de Google Voice pour envoyer vos SMS depuis votre site web (PHP / CURL)
![]()
L’api Google Voice n’étant pas encore publié publiquement , plusieurs webmasters et webdéveloppeurs cherchent une manière pour utiliser le service Google Voice afin de profiter de la fonction SMS sur leurs sites web ou application web.
Plusieurs utilisations sont possibles, comme par exemple la réception de SMS après réception de mail sur un formulaire de contact ou bien encore tout un site dédié a l’envoi d’SMS Gratuit (ou payant).
Voici donc une solution pour l’intégration de votre compte Google Voice a votre site web ou votre application web qui nécessite PHP 4 ou + ainsi que cURL (Client URL Request Library) qui comme son nom l’indique permet la manipulation d’URL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <?php define('COMPTEGOOGLE','compte-google@gmail.com'); define('PASSWORDGOOGLE','password'); function query($data=array(),$fields=array()){ foreach($data as $k=>$v) $fields[]=$k.'='.urlencode(stripslashes($v)); return implode('&',$fields); } function googleapi($url,$post=null,$headers=null){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); if(is_array($post)){ curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,query($post)); } if(is_array($headers)) curl_setopt($ch,CURLOPT_HTTPHEADER,$headers); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); $data=curl_exec($ch) or curl_error($ch); curl_close($ch); return $data; } $auth=googleapi('https://www.google.com/accounts/ClientLogin',array( 'accountType'=>'GOOGLE', 'Email'=>COMPTEGOOGLE, 'Passwd'=>PASSWORDGOOGLE, 'service'=>'grandcentral', 'source'=>;'googlevoice.php')); if(preg_match('/Error=([A-z]+)/',$auth,$error)) die($error[1]); if(preg_match('/Auth=([A-z0-9_-]+)/',$auth,$auth)); $auth=$auth[1]; preg_match("/'_rnr_se'\: '([^']+)'/",googleapi('https://www.google.com/voice/?auth='.$auth),$rnr); $rnr=$rnr[1]; function sendsms($them,$text){ global $auth,$rnr; return googleapi('https://www.google.com/voice/sms/send/?auth='.$auth,array( 'id'=>'', 'phoneNumber'=>$them, 'text'=>$text, '_rnr_se'=>$rnr) ); } ?> |
Enfin pour envoyer votre SMS il suffit d’utiliser la fonction sendsms() avec le numéro en forme internationale en premier argument et votre SMS en deuxième argument.
Exemple :
sendsms(2126xxxxxxxx,'Votre Message a envoyer');












