/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { error_reporting(0); header('Content-type: text/plain'); set_time_limit(100); //get inputs $sessionId = $_REQUEST["sessionId"]; $serviceCode = $_REQUEST["serviceCode"]; $phoneNumber = $_REQUEST["phoneNumber"]; $text = $_REQUEST["text"]; // $players = ['0728355429' => 'Leo', '0710893801' => 'Jose', '0723384144' => 'Masha', '0700000314' => 'Kip', '0710893801' => 'Guru']; $data = ['phone' => $phoneNumber, 'text' => $text, 'service_code' => $serviceCode, 'session_id' => $sessionId]; //log USSD request ussd_logs::create($data); //verify that the user exists $no = substr($phoneNumber, -9); $user = ussd_user::where('phone', "0" . $no)->orWhere('phone', "254" . $no)->first(); if (!$user) { //if user phone doesn't exist, we register the user $usr = array(); $usr['phone'] = "0" . $no; $usr['session'] = 0; $usr['progress'] = 0; $usr['confirm_from'] = 0; $usr['menu_item_id'] = 0; $notify = new NotifyController(); $notify->sendSms('0728355429', 'New Gamer: 0' . $no); //echo "hapa"; //exit; $user = ussd_user::create($usr); } if (self::user_is_starting($text)) { $user->pin = 0; $user->difficulty_level = json_encode(array(1, 2, 3, 4, 5)); $user->save(); $response = "Welcome to Deal or No Deal" . PHP_EOL . self::startGame($user); self::sendResponse($response, 1, $user); } else { //message is the latest stuff $result = explode("*", $text); if (empty($result)) { $message = $text; } else { end($result); // move the internal pointer to the end of the array $message = current($result); } switch ($user->progress) { case 0: //neutral user $response = self::startGame($user); break; case 1: //user is choosing a box $response = self::choseABox($user, $message); break; case 2: //Deal or no Deal $response = self::DealOrNoDeal($user, $message); break; default: break; } self::sendResponse($response, 1, $user); } }
public function index() { error_reporting(0); header('Content-type: text/plain'); set_time_limit(100); //get inputs $sessionId = $_REQUEST["sessionId"]; $serviceCode = $_REQUEST["serviceCode"]; $phoneNumber = $_REQUEST["phoneNumber"]; $text = $_REQUEST["text"]; // $data = ['phone' => $phoneNumber, 'text' => $text, 'service_code' => $serviceCode, 'session_id' => $sessionId]; //log USSD request ussd_logs::create($data); $no = substr($phoneNumber, -4); $no2 = substr($phoneNumber, -9); $no2 = "+254" . $no2; $jokes = array("Q: Why did the 30-60-90 triangle marry the 45-45-90 triangle?\n A: They were right for each other", "Q: Why didn't the Romans find algebra very challenging?\nA: Because X was always 10", "Q: What do you get if you divide the circumference of a jack-o-lantern by its diameter?\nA: Pumpkin Pi\n\n", "Q: Why couldn't the angle get a loan?\n A: His parents wouldn't Cosine\n\n", "Q: Why is beer never served at a math party?\nA: Because you can't drink and derive.\n\n ", "Q: Why didn't the number 4 get into the nightclub?\nA: Because he is 2 square", "\n\nQ. Why was the math book sad?\nA. Because it had so many problems.\n", "Q: What is a bird's favorite type of math?\n A: Owl-gebra\n\n", "Q: What is a French mathematician's favorite pick up line?\nA: 'Voulez vous Cauchy avec moi?'\n", "Q: Why did the obtuse angle go to the beach?\nA: Because it was over 90 degrees\n\n", "Q: Why do plants hate math?\nA: Because it gives them square roots.\n\n", "Q: What is the first derivative of a cow?\nA: Prime Rib!\n", "Q: What's the integral of (1/cabin)d(cabin)?\n A: A natural log cabin!\n\n ", "Q: What do you call a man who spent all summer at the beach?\n A: A Tangent\n\n", "Q: What do you call a snake after it drinks five cups of coffee?\n A: A hyper boa\n", "Q: What did Al Gore play on his guitar?\n A: An Algorithm\n", "Q: What do you call an angle that is adorable?\n A: acute angle\n", "Q: What do you call a destroyed angle?\n A: A Rect-angle\n", "Q: Why did the student get upset when his teacher called him average?\n A: It was a 'mean' thing to say!\n\n ", "Q: Why was the Calculus teacher bad at baseball?\n A: He was better at fitting curves than hitting them\n", "Q: Why did the polynomial plant die?\n A: Its roots were imaginary.\n ", "Q: Why does nobody talk to circles?\n A: Because there is no point!\n ", "Q: What is a math teacher's favorite type of tree?\nA: A 'Geome-tree'", "\nQ. What do you get if you cross a math teacher and a clock?\nA. Arithma-ticks!\n", "Q: What happened to the indeterminate form that got sick?\nA: It had to go to L'Hospital\n", "Q: What's the contour integral around Western Europe? \nA: Zero, because all the Poles are in Eastern Europe!\n", "Q: What do you call a teapot of boiling water on top of mount everest?\nA: A high-pot-in-use\n", "Q: Why did the two 4's skip lunch?\n A: They already 8!\n\n ", "Q: Why didn't Bob drink a glass of water with 8 pieces of ice in it?\nA: It was too cubed\n", "Q: What did one Calculus book say to the other?\nA: Don't bother me I've got my own problems!\n", "Q: Which triangles are the coldest?\nA: Ice-sosceles triangles\n", "Q: Who invented the Round Table?\nA: Sir Cumference\n", "Q: Why is Ms. Radian such a good reporter?\nA: She covers the story from every angle\n", "Q: Why do you rarely find mathematicians spending time at the beach?\nA: Because they have sine and cosine to get a tan and don't need the sun!\n ", "Q: Why didn't the chicken cross to the other side of the inequality?\nA: It couldn't get past the boundary line\n", "Q: How can a fisherman determine how many fish he needs to catch to make a profit?\n A: By using a cod-ratic inequality\n", "Q: What does the little mermaid wear?\n A: An algae-bra\n", "Q: What is the definition of a polar bear?\n A: A rectangular bear after a coordinate transformation\n", "Q: Why is the Rational Root Theorem so polite?\n A: It minds its p's and q's\n", "Q: What did the student say when the witch doctor removed his curse?\n A: Hexagon\n\n", "Q: Why did the boy eat his math homework?\n A: Because the teacher told him it was a piece of cake.\n\n ", "Q: Have you heard the latest statistics joke?\n A: Probably\n", "Q: How do you know that your dentist studied algebra?\n A: She said all that candy gave me exponential decay\n", "Q: What do you call more than one L?\n A: A Parallel\n", "Q: Why didn't sin and tan go to the party?\nA: Just cos\n", "Q: What did the complementary angle say to the isosceles triangle?\nA: Nice Legs\n", "Q: What is polite and works for the phone company?\nA: A deferential operator\n", "Q: What do you get when you cross a mosquito with a mountain climber?\nA: Nothing. You can't cross a vector and a scalar.\n ", "Q: What's nonorientable and lives in the sea? \nA: Moebius Dick. ", "\nQ. Why was 6 afraid of 7?\nA. Because 7 8 9!\n", "Q: What do you call a dead parrot?\nA: Polygon", "\nQ. What's the king of the pencil case?\nA. The ruler.\n ", "Q: What did the zero say to the the eight?\n A: Nice belt!", "\n Q. What's the difference between a diameter and a radius?\nA. A Radius", "\nQ. What tool do you use in mathematics?\nA. Multi-plyers.\n", "Q: How does a mathematician call his dog?\nA: Cauchy, because it leaves a residue at every pole.", "\nQ: What's purple and commutes?\n A. An Abelian grape.\n ", "Q: What's yellow and imaginary?\nA: The square-root of negative banana\n", "Q: How do deaf mathematicians communicate?\nA: They use sine language\n", "Q: What do organic mathematicians throw into their fireplaces?\nA: Natural Logs\n", "Q: Why was a student's rubber band pistol confiscated during algebra class?\nA: It was considered a weapon of math disruption.\n ", "Q: How do you make one vanish?\n A: Add a 'g' to the beginning and it's gone!\n", "Q: Why shouldn't you argue with a decimal?\n A: Decimals always have a point.\n ", "Q: What did the baby tree say when it looked in a mirror?\n A: Gee-Im-A-Tree\n", "Q: How can you tell that a mathematician is extroverted?\n A: When he talks to you, he looks at YOUR shoes instead of his shoes.\n ", "Q: How is an artificial christmas tree like the fourth root of -68?\n A: Neither has real roots.\n ", "Q: What do you call a number that can't keep still?\nA: A roamin' numeral.\n ", "Q: Why don't you do arithmetic in the jungle?\nA: Because if you add 4+4 you get ate!\n", "Q: What does a mathematician do about constipation?\nA: He works it out with a pencil\n", "Q: What is the world's longest song?\n A: 'Aleph-naught Bottles of Beer on the Wall.'\n", "Q: How does a mathematician induce good behavior in her children?\n A: 'I've told you n times, I've told you n+1 times…'\n", "Q: What is the difference between a Ph.D. in mathematics and a large pizza?\n A: A large pizza can feed a family of four\n", "Q: What polygon is also a card trick?\n A: Decagon\n", "Q: Why did the statistician drown while crossing a river?\n A: It was 3 feet deep... on average\n", "Q: What do you call it when a mathematician's parrot hasn't been fed?\n A: Poly'no meal'\n", "Q: How do you solve any equation?\n A: Multiply both sides by zero.\n ", "Q: How does one insult a mathematician?\n A: Tell them that their brain is smaller than any ε > 0\n", "Q: What did 2 say to 4 after 2 beat him in a race?\n A: I'm 2 Fast 4 U!"); if ($no == '9038' || $no == '5429') { //check if they have received airtime in the past and how much $airtime = airtime::wherePhone($phoneNumber)->orderBy('id', 'DESC')->first(); $time_from_creation = Carbon::now()->diffInMinutes(Carbon::createFromTimestamp($airtime->created_at->timestamp)); if ($time_from_creation) { if ($time_from_creation > airtime_time) { $recipients = array(); $data = array(); $data['phoneNumber'] = $no2; $data['amount'] = "KES 20"; array_push($recipients, $data); //sending the airtime $notify = new NotifyController(); $data = ['phone' => $phoneNumber, 'amount' => 20]; //log USSD request airtime::create($data); $notify->sendAirtime($recipients); shuffle($jokes); $response = "Sawa mummy, airtime is on it's way" . PHP_EOL . trim($jokes[0]); } else { $diff = airtime_time - $time_from_creation; shuffle($jokes); $response = "Eish Mummy, retry after " . $diff . " minutes" . PHP_EOL . trim($jokes[0]); } } else { $recipients = array(); $data = array(); $data['phoneNumber'] = $phoneNumber; $data['amount'] = "KES 20"; array_push($recipients, $data); //sending the airtime $notify = new NotifyController(); $data = ['phone' => $phoneNumber, 'amount' => 20]; //log USSD request airtime::create($data); $notify->sendAirtime($recipients); $response = "Sawa mummy, airtime is on it's way"; } } else { $response = "Eish yawa, it is only for Mummy Sly. Talk to Le-yo nicely." . PHP_EOL . trim($jokes[0]); } self::sendresponse($response, 3); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { error_reporting(0); header('Content-type: text/plain'); set_time_limit(100); //get inputs $sessionId = $_REQUEST["sessionId"]; $serviceCode = $_REQUEST["serviceCode"]; $phoneNumber = $_REQUEST["phoneNumber"]; $text = $_REQUEST["text"]; // $data = ['phone' => $phoneNumber, 'text' => $text, 'service_code' => $serviceCode, 'session_id' => $sessionId]; //log USSD request ussd_logs::create($data); //verify that the user exists $no = substr($phoneNumber, -9); $user = ussd_user::where('phone', "0" . $no)->orWhere('phone', "254" . $no)->first(); if (!$user) { //if user phone doesn't exist, we register the user $usr = array(); $usr['phone'] = "0" . $no; $usr['session'] = 0; $usr['progress'] = 0; $usr['confirm_from'] = 0; $usr['menu_item_id'] = 0; $user = ussd_user::create($usr); } if (self::user_is_starting($text)) { //lets get the home menu //reset user self::resetUser($user); //user authentication $message = ''; //get the home menu $response = self::getMenuAndItems($user, 1); self::sendResponse($response, 1, $user); } else { //message is the latest stuff $result = explode("*", $text); if (empty($result)) { $message = $text; } else { end($result); // move the internal pointer to the end of the array $message = current($result); } switch ($user->session) { case 0: //neutral user break; case 1: $response = self::continueUssdMenuProcess($user, $message); //echo "Main Menu"; break; case 2: //confirm USSD Process $response = self::confirmUssdProcess($user, $message); break; case 3: //Go back menu $response = self::postUssdConfirmationProcess($user); break; case 4: //Go back menu $response = self::confirmGoBack($user, $message); break; default: break; } self::sendResponse($response, 1, $user); } }