Guest User

Untitled

a guest
Dec 27th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2. require 'vendor/autoload.php';
  3.  
  4. use AfricasTalking\SDK\AfricasTalking;
  5.  
  6. $username = "sandbox";
  7. $apiKey = "6e415c0bd1b320e053ab8d9131118185dd16d6d397438dc6ad0d859f6ab084ac";
  8.  
  9. $AT = new AfricasTalking($username, $apiKey);
  10.  
  11. $message = "VR-12345";
  12.  
  13.  
  14.  
  15. // Router
  16. $router = new AltoRouter();
  17.  
  18. $router->map( 'GET', '/', function() {
  19. require __DIR__ . '/views/login.php';
  20. });
  21.  
  22. $router->map( 'GET|POST', '/login/[*:password]', function ($password) {
  23.  
  24.  
  25. if($_GET["username"] == "user1" && $password =="pass1"){
  26.  
  27. global $AT;
  28. $sms = $AT->sms();
  29. $response = $sms->send(array(
  30. "to" => "+254705336634",
  31. "message" => "VR-12345"
  32. ));
  33.  
  34. header("Content-Type: application/json; charset=UTF-8");
  35. echo json_encode($response);
  36.  
  37.  
  38. }
  39.  
  40. else{
  41. echo json_encode($response);
  42. }
  43.  
  44.  
  45. });
  46.  
  47. $router->map( 'GET|POST', '/verify/[*:verify]', function ($verify) {
  48.  
  49.  
  50. if($verify == $message){
  51. echo json_encode($response);
  52.  
  53. // require __DIR__ . '/views/verify.php';
  54.  
  55. }
  56.  
  57.  
  58.  
  59. });
  60.  
  61.  
  62. $match = $router->match();
  63. if( $match && is_callable( $match['target'] ) ) {
  64. call_user_func_array( $match['target'], $match['params'] );
  65. } else {
  66. header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
  67. }
Add Comment
Please, Sign In to add comment