diff --git a/app/Http/Controllers/TacController.php b/app/Http/Controllers/TacController.php new file mode 100644 index 0000000..5cdb8c8 --- /dev/null +++ b/app/Http/Controllers/TacController.php @@ -0,0 +1,128 @@ +icno],['tac_no',$request->tac]])->get()->toArray(); + + if($tac){ + $CustomerInfo = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/customers/' . $request->icno)->json(); + $daerah = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/daerah/' . $CustomerInfo['koddaerah'])->json(); + $negeri =Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/negeri/' . $CustomerInfo['kodnegeri'])->json(); + + return response(['status' => 1, 'customerinfo' => $CustomerInfo,'namadaerah' => $daerah['namadaerah'],'namanegeri' => $negeri['negeri']]); + }else{ + return response(['status' => 0]); + } + } + + + public function requestKadPengenalan(Request $request){ + + $currentDateTime = Carbon::now(); + $expiretac = tacportal::where('icno',$request->icno) + ->whereDate('created_at','>=',$currentDateTime) + ->whereDate('expired_at','<=',$currentDateTime) + ->where('created_at','>=',$currentDateTime->toDateTimeString()) + // ->whereTime('expired_at','<=',$currentDateTime) + // ->orderBy('tac_id','desc') + // ->latest() + ->first(); + dd($expiretac); + if($expiretac){ + return response(['notexpired' => true]); + } + + $tac = User::where('icno',$request->icno)->get()->toArray(); + + if($tac){ + return response(['message' => true]); + } + + $CustomerInfo = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/customers/' . $request->icno)->json(); + + if($CustomerInfo) + { + $generatestatus = $this->generateTAC($CustomerInfo); + + if($generatestatus){ + $backphone = substr($CustomerInfo['telefon'],-4); + return response(['notelefon' => $backphone,'status' => 1]); + }else{ + + } + }else{ + return response(['status' => 0],200); + } + } + + private function generateTAC($customer){ + + + $currentDateTime = Carbon::now(); + $expired_at = Carbon::now()->addMinutes(15); + + $tac_token = $this->randum_number(6,2,false); + + $tac = new tacportal; + + $tac->icno = ($customer['kpbaru']) ? $customer['kpbaru'] : $customer['kplama']; + $tac->notel = $customer['telefon']; + $tac->tac_no = $tac_token; + $tac->created_at = $currentDateTime->toDateTimeString(); + $tac->expired_at = $expired_at; + $tac->save(); + + + // $mobileno = '6' . $customer['notelefon']; + $mobileno = '601114884900'; + $messages = 'AR-RAHN PKB PORTAL : TAC: ' . $tac_token . ' ' . $currentDateTime . '. AR-RAHN CARELINE CENTRE 1300-22-4343'; + + // $status = Http::get('http://gateway.onewaysms.com.my:10001/api.aspx',[ + // 'apiusername' => 'APIUK330HDAFO', + // 'apipassword' => 'APIUK330HDAFOUK330', + // 'senderid' => 'INFO', + // 'mobileno' => $mobileno, + // 'message'=> $messages, + // 'languagetype'=> 1 + // ]); + + // return response($status); + return response(1); + } + + private function randum_number($len = 6,$dup = 1, $sort = false){ + if($dup < 1) + throw new InvalidArgumentException('Second argument is < 1'); + + $num = range(0,9); + shuffle($num); + + $num = array_slice($num, 0, ($len-$dup) + 1); + + if($dup > 0){ + $k = array_rand($num, 1); + for($i=0;$i<($dup-1);$i++) + { + $num[] = $num[$k]; + } + } + + if($sort){ + sort($num); + } + + return implode('',$num); + } + + +} diff --git a/app/Models/tacportal.php b/app/Models/tacportal.php new file mode 100644 index 0000000..fd726cf --- /dev/null +++ b/app/Models/tacportal.php @@ -0,0 +1,31 @@ +
Sila isi nombor OTP yang telah di hantar ke nombor telefon bimbit anda.
+ {{--Sila isi nomborxz OTP yang telah di hantar ke nombor telefon bimbit anda.
--}} +Sila isi Nombor Kad Pengenalan anda di dalam kotak yang disediakan.
@csrf -