From cb7bee429ec5cc557a83df6271ecd7178359bad4 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 22 Nov 2023 08:14:25 +0300 Subject: [PATCH] sms receiver merged --- app/Http/Controllers/ReceiverController.php | 76 +++++++++++++++++++++ app/Models/UshauriInbox.php | 18 +++++ app/Models/UshauriOutbox.php | 18 +++++ routes/api.php | 6 +- 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/ReceiverController.php create mode 100644 app/Models/UshauriInbox.php create mode 100644 app/Models/UshauriOutbox.php diff --git a/app/Http/Controllers/ReceiverController.php b/app/Http/Controllers/ReceiverController.php new file mode 100644 index 0000000..a67baf9 --- /dev/null +++ b/app/Http/Controllers/ReceiverController.php @@ -0,0 +1,76 @@ +to == '40149') { + + // dd($request->all()); + + $inbox = new UshauriInbox; + + $inbox->destination = $request->to; + $inbox->source = $request->from; + $inbox->msg = $request->text; + $inbox->receivedtime = $request->date; + $inbox->reference = $request->id; + $inbox->LinkId = $request->linkId; + + $inbox->save(); + + $lastID1 = $inbox->id; + $task = 1; + $this->task($task, $lastID1); + } + } + + function task($task, $LastInsertId) + { + Log::info("ID: " . $LastInsertId . ", TASK: " . $task); + switch ($task) { + case 1: + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, "http://ushaurinode.localhost/receiver/$LastInsertId"); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_exec($ch); + + curl_close($ch); + echo 'Done task 1'; + break; + default: + break; + } + } + + public function ushauri_callback(Request $request) + { + + //check incoming id and update single sms with telco status + + $updateDetails = [ + 'callback_status' => $request->get('status'), + 'failure_reason' => $request->get('failureReason') + ]; + + // return $request; + + $sms = UshauriOutbox::where('message_id', $request->id)->first(); + if ($sms) { + $sms = UshauriOutbox::where('message_id', $request->id) + ->update($updateDetails); + } + } +} diff --git a/app/Models/UshauriInbox.php b/app/Models/UshauriInbox.php new file mode 100644 index 0000000..cf4cdfa --- /dev/null +++ b/app/Models/UshauriInbox.php @@ -0,0 +1,18 @@ +get('/user', function (Request $request) { - return $request->user(); + return $request->user(); }); + + +Route::post('/sms/receiver', 'App\Http\Controllers\ReceiverController@index'); +Route::post('/sms/callback/ushauri', 'App\Http\Controllers\ReceiverController@ushauri_callback');