Advertisement
achunk17

EnvayaSMS (Android App) Sending SMS From WEB

Nov 29th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-Type: application/json; charset=utf-8');
  4.  
  5. function compute_signature($url, $data, $password)
  6. {
  7.     ksort($data);
  8.  
  9.     $input = $url;
  10.     foreach ($data as $key => $value)
  11.         $input .= ",$key=$value";
  12.     $input .= ",$password";
  13.  
  14.     return base64_encode(sha1($input, true));
  15. }
  16.  
  17. function is_validated($correct_password)
  18. {
  19.     $signature = @$_SERVER['HTTP_X_REQUEST_SIGNATURE'];
  20.     if (!$signature)
  21.     {
  22.         return false;
  23.     }
  24.  
  25.     $is_secure = (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'],
  26.         FILTER_VALIDATE_BOOLEAN));
  27.     $protocol = $is_secure ? 'https' : 'http';
  28.     $full_url = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  29.  
  30.     $correct_signature = compute_signature($full_url, $_POST, $correct_password);
  31.     return $signature === $correct_signature;
  32. }
  33.  
  34. $envayaPass = '1234';
  35. if (!is_validated($envayaPass))
  36. {
  37.     header('HTTP/1.1 401 Unauthorized', true, 401);
  38.     echo '{"error":{"message:"Password Salah"}}';
  39.     exit();
  40. }
  41.  
  42. $pesan_keluar = array();
  43. $pesan_keluar[] = array('to' => '+6285729112015', 'message' => 'Pesan keluar 1');
  44. $pesan_keluar[] = array('to' => '+6285729112015', 'message' => 'Pesan keluar 2');
  45. $pesan_keluar[] = array('to' => '+6285729112015', 'message' => 'Pesan keluar 3');
  46. $pesan_keluar[] = array('to' => '+6285729112015', 'message' => 'Pesan keluar 4');
  47. $pesan_keluar[] = array('to' => '+6285729112015', 'message' => 'Pesan keluar 5');
  48.  
  49. $payload = array('events' => array(array(
  50.             'event' => 'send',
  51.             'messages' => $pesan_keluar,
  52.             )));
  53. echo json_encode($payload);
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement