Stap 5: SMS/MMS setup
Dus eigenlijk wanneer op voor het verzenden van mijn buren een SMS-bericht met de volgende werkzaamheden "zeggen [uw naam] de Mogreet server contact opgenomen met mijn callbackurl (halloween.php) die op zijn beurt pakte een momentopname van het front geconfronteerd met Dropcam en stuur het terug naar de afzender.
Een andere keurige eigenschap die ik heb toegevoegd was een "godslastering filter". Ik net nieuw zou te verleidelijk voor sommige tieners te verzenden aantal onbetamelijke woorden.
Halloween.php
<?php $xml = file_get_contents("php://input"); $mo = new SimpleXMLElement($xml , 0, false); $mobile = $mo->msisdn; $msg = $mo->message; $strArray = explode(' ',$msg); $name = trim($strArray[1]); $tmpdate = date ("mdy-His"); $filename = $name."-".$tmpdate.".jpeg"; downloadDropcam($filename); $geturl = 'http://www.wdyl.com/profanity?q='.urlencode($name); $json_output = json_decode(httpGet($geturl)); $response = $json_output->{'response'}; if ($response == 'false'){ $message = "Hello ". $name . ". I am the magic mirror and I have some candy for you. Happy Halloween!"; httpPost("http://[Server running on Mac Mini/speak.php", $message); echo "Message sent: ".$msg; }else{ echo "Sorry. Profanity not allowed!"; } $url = "http://[hosted server].com/halloween/".$filename; $params = "client_id=XXXX&token=XXXXX&campaign_id=XXXXX&to=".$mobile."&message=".urlencode("Happy Halloween")."&content_url=".$url; $smsResponse = httpGet("https://api.mogreet.com/moms/transaction.send?".$params); function downloadDropcam($file){ $url = "https://nexusapi.dropcam.com/get_image?width=800&uuid=XXXXXXX"; $path = "halloween/".$file; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); file_put_contents($path, $data); } function httpGet($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); return $output; } function httpPost($url,$data){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_TIMEOUT, 1); $output = curl_exec($ch); curl_close($ch); return $output; } ?>