sms_hook_bulkvs.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. //includes files
  3. require_once dirname(__DIR__, 3) . "/resources/require.php";
  4. require_once "../sms_hook_common.php";
  5. //if (check_acl()) {
  6. //Make sure that it is a POST request.
  7. if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
  8. throw new Exception('Request method must be POST!');
  9. }
  10. //Make sure that the content type of the POST request has been set to application/json
  11. $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
  12. if(strcasecmp($contentType, 'application/json') != 0){
  13. throw new Exception('Content type must be: application/json');
  14. }
  15. //Receive the RAW post data.
  16. $content = trim(file_get_contents("php://input"));
  17. //$mail_body.="RAW post data: ".$content."\n";
  18. //Attempt to decode the incoming RAW post data from JSON.
  19. $decoded = json_decode($content, true);
  20. $mail_body.="decoded data: \n";
  21. $sms_from=$decoded['From'];
  22. $sms_text=$decoded['Message'];
  23. //$sms_media_url=print_r($decoded['MediaURLs'], TRUE);
  24. foreach($decoded['To'] as $key=>$value){
  25. $sms_to_did_no=$value;
  26. }
  27. foreach($decoded['MediaURLs'] as $media_url){
  28. $sms_media_url=$media_url." ".$sms_media_url;
  29. }
  30. route_and_send_sms($sms_from, $sms_to_did_no,$sms_text.$sms_media_url);
  31. // } else {
  32. die("no");
  33. // }
  34. //} else {
  35. error_log('ACCESS DENIED [SMS]: ' . print_r($_SERVER['REMOTE_ADDR'], true));
  36. die("access denied");
  37. //}
  38. ?>