Created
June 22, 2022 11:47
-
-
Save blisssan/68a98a0ae86507d840663293011bd430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function start(Request $request) | |
{ | |
$request->validate([ | |
'phone' => 'required', | |
'password' => 'required', | |
'ap_mac_id' => 'required', | |
'device_mac_id' => 'required' | |
]); | |
$user = User::query()->where('phone', '9003300303')->first(); | |
if (!$user) { | |
abort(422, 'User not found!'); | |
} | |
$ver = '1.0'; | |
$timestamp = Carbon::now()->format('YmdHis'); | |
$username = $request->phone; | |
$password = $request->password; | |
$apMacId = $request->ap_mac_id; | |
$deviceMacId = $request->device_mac_id; | |
$appId = config('services.wani.app.id'); | |
$appVer = config('services.wani.app.version'); | |
$otpObj = Totp::generate($username); | |
$totp = $otpObj->otp; | |
$custData = ['user_id' => $user->id]; | |
$tokenData = compact( | |
'ver', | |
'timestamp', | |
'username', | |
'password', | |
'apMacId', | |
// 'deviceMacId', | |
// 'appId', | |
// 'appVer', | |
'totp', | |
// 'custData' | |
); | |
$tokenString = json_encode($tokenData); | |
// Fetch my keys | |
$appProviderKey = ProviderKey::where('type', 'app_provider')->first(); | |
if (!$appProviderKey || !$appProviderKey->private_key || !$appProviderKey->public_key) { | |
abort(500, 'Keys not set!'); | |
} | |
$rsaCipher = CryptService::encrypt($tokenString, $appProviderKey->private_key); | |
$base64Cipher = base64_encode($rsaCipher); | |
$waniapptoken = $appProviderKey->uid . '|' . $base64Cipher; | |
$response = Http::get(config('services.wani.captive.portal') . '?waniapptoken=' . $waniapptoken); | |
if (!$response->successful()) { | |
abort($response->status(), $response->reason()); | |
Log::error($response->body()); | |
} | |
return $response->body(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment