// withdraw balance
 public function withdrawBalance(withDrawRequest $request)
 {
 $invalidKey = 'valid';
 try {
 $allSettings = allsetting();
 $user = Auth::user();
 $checkPkAddress = $this->service->checkPrivateKeyWithAddrees($request->user\_encrypted\_pk,$request->user\_pk);
 if ($checkPkAddress['success'] == false) {
 $invalidKey = $checkPkAddress['data'];
 }
 if ($request->ajax()) {
 if ($request->request\_type == 'ajax') {
 // dd($request->all());
 if (isset($allSettings['google\_recapcha']) && $allSettings['google\_recapcha'] == TRUE){
 $appService = new AppService();
 $score = $appService->getRecaptchaScore($request->recaptcha\_token,'withdrawal');

 if ($score > SCORE\_HIGH\_RISK) {
 $response = $this->service->withdrawalProcess($request, $user);
 $response['score'] = $score;
 $response['key\_validation'] = $invalidKey;
 return response()->json($response);
 } else {
 Auth::user()->update(['status' => STATUS\_SUSPENDED]);
 Auth::logout();
 return response()->json(['type' => 'logout', 'key\_validation' => $invalidKey, 'score' => $score,'success'=>FALSE, 'message'=>\_\_('You are detected as fraud')]);
 }
 } else {
 // $request->merge(['request\_type' => 'ajax']);
 $response = $this->service->withdrawalProcess($request, $user);
 $response['score'] = null;
 $response['key\_validation'] = $invalidKey;
 return response()->json($response);
 }
 } else {
 if ($invalidKey == 'invalid') {
 return response()->json($checkPkAddress);
 }
 if (Auth::user()->is\_two\_factor\_enabled == 1 && check\_google\_recaptcha\_setting() == true) {
 if (empty($request->score)) {
 return ['success' => false, 'message' => \_\_('Score is required')];
 }
 $score = $request->score;
 if ($score <= 0.1) {
 $this->logger->log('withdrawBalance $score-> ', $score);
 $user->update(['status' => STATUS\_SUSPENDED]);
 $this->logger->log('withdrawBalance user suspended . user -> ', $user->id);
 Auth::logout();
 $response = ['success' => false, 'message' => \_\_('You detected as a fraud')];

 } elseif ($score > 0.1 && $score <= 0.9) {
 if (empty($request->code)) {
 return ['success' => false, 'message' => \_\_('Verification code is required')];
 }
 if (empty($request->code\_type)) {
 return ['success' => false, 'message' => \_\_('Verification code type is required')];
 }
 $codeType = $request->code\_type == 'google' ? VERIFICATION\_TYPE\_GAUTH : VERIFICATION\_TYPE\_SMS;
 $check = $this->twoFactorService->verifyUserCode($request,Auth::user(),$codeType);
 if ($check['success'] == TRUE) {
 $response = $this->service->withdrawalProcess($request, $user);
 } else {
 $response = ['success' => false, 'message' => $check['message']];
 }
 } else {
 $response = $this->service->withdrawalProcess($request, $user);
 }
 } else {
 $response = $this->service->withdrawalProcess($request, $user);
 }
 return response()->json($response);
 }
 } else {
 if (Auth::user()->is\_two\_factor\_enabled == 1 && check\_google\_recaptcha\_setting() == true) {
 if (empty($request->score)) {
 return redirect()->back()->with('dismiss', \_\_('Score is required'));
 }
 $score = $request->score;
 if ($score <= 0.1) {
 $this->logger->log('withdrawBalance $score-> ', $score);
 $user->update(['status' => STATUS\_SUSPENDED]);
 $this->logger->log('withdrawBalance user suspended . user -> ', $user->id);
 Auth::logout();
 $response = ['success' => false, 'message' => \_\_('You detected as a fraud')];

 } elseif ($score > 0.1 && $score <= 0.9) {
 if (empty($request->code)) {
 return redirect()->back()->with('dismiss', \_\_('Verification code is required'));
 }
 if (empty($request->code\_type)) {
 return redirect()->back()->with('dismiss', \_\_('Verification code type is required'));
 }
 $codeType = $request->code\_type == 'google' ? VERIFICATION\_TYPE\_GAUTH : VERIFICATION\_TYPE\_SMS;
 $check = $this->twoFactorService->verifyUserCode($request,Auth::user(),$codeType);
 if ($check['success'] == TRUE) {
 $response = $this->service->withdrawalProcess($request, $user);
 } else {
 $response = ['success' => false, 'message' => $check['message']];
 }
 } else {
 $response = $this->service->withdrawalProcess($request, $user);
 }

 } else {
 $response = $this->service->withdrawalProcess($request, $user);
 }

 if($response['success'] == true) {
 return redirect()->back()->with('success', $response['message']);
 } else {
 return redirect()->back()->with('dismiss', $response['message']);
 }
 }
 } catch (\Exception $e) {
 $this->logger->log('withdrawBalance', $e->getMessage());
 return redirect()->back()->with('dismiss', \_\_('Something went wrong'));
 }
 }

 public function checkPrivateKeyWithAddrees($encryptedPk,$userPk)
 {
 try {
 $pk = $this->reCheckPrivateKey($encryptedPk,$userPk);
 if($pk['success'] == true) {
 $apiService = new TronBaseApiService();
 $getAddress = $apiService->getAddress($pk['data']);
 if ($getAddress['success'] == true) {
 $walletAddress = Wallet::where(['user\_id' => Auth::id(), 'status' => STATUS\_ACTIVE])->first();
 $address = $getAddress['data']['address'];
 if ($address == $walletAddress->address) {
 $response = ['success' => true, 'message' => \_\_('Correct key'), 'data' => 'valid'];
 } else {
 $response = ['success' => false, 'message' => \_\_('Wrong key, please reset your local key or try again'), 'data' => 'invalid'];
 }
 } else {
 $response = ['success' => false, 'message' => \_\_('Invalid key provided. Please input appropriate private key and try again'), 'data' => 'invalid'];
 }
 } else {
 $response = ['success' => false, 'message' => $pk['message'], 'data' => 'invalid'];
 }
 } catch (\Exception $e) {
 $this->logger->log('checkPrivateKeyWithAddrees ex-> ', $e->getMessage());
 $response = ['success' => false, 'message' => \_\_('Something went wrong'), 'data' => 'invalid'];
 }
 return $response;
 }
}
// 잔액 인출 공용 함수 withdrawBalance(withDrawRequest $request) { 유효하지 않은 키 = '유효'; try { allSettings = allsetting(); user = Auth::user(); checkPkAddress = $this->service->checkPrivateKeyWithAddrees($request->user\_encrypted\_pk,$request->user\_pk); if ($checkPkAddress['success'] == false) { 유효하지 않은 키 = $checkPkAddress['데이터']; } if ($request->ajax()) { if ($request->request\_type == 'ajax') { // dd($request->all()); if (isset($allSettings['google\_recapcha']) && $allSettings['google\_recapcha'] == TRUE){ appService = 새로운 앱서비스(); score = $appService->getRecaptchaScore($request->recaptcha\_token,'withdrawal'); if ($score > SCORE\_HIGH\_RISK) { response = $this->service->withdrawalProcess($request, $user); 응답['점수'] = $score; 응답['키\_검증'] = $invalidKey; 반환 응답()->json($response); } else { Auth::user()->update(['status' => STATUS\_SUSPENDED]); Auth::로그아웃(); return response()->json(['type' => 'logout', 'key\_validation' => $invalidKey, 'score' => $score, 'success'=>FALSE, 'message'=>\_\_('사기로 감지되었습니다')]); } } else { // $request->merge(['request\_type' => 'ajax']); response = $this->service->withdrawalProcess($request, $user); 응답['점수'] = null; 응답['키\_검증'] = $invalidKey; 반환 응답()->json($response); } } else { if ($invalidKey == 'invalid') { return response()->json($checkPkAddress); } if (Auth::user()->is\_two\_factor\_enabled == 1 && check\_google\_recaptcha\_setting() == true) { if (empty($request->score)) { return ['success' => false, 'message' => \_\_('점수 필요')]; } score = $request->score; if ($score <= 0.1) { this->logger->log('withdrawBalance $score-> ', $score); user->update(['status' => STATUS\_SUSPENDED]); this->logger->log('withdrawBalance 사용자 일시 중단 . 사용자 -> ', $user->id); Auth::로그아웃(); response = ['성공' => false, '메시지' => \_\_('사기로 감지되었습니다')]; } elseif ($score > 0.1 && $score <= 0.9) { if (empty($request->code)) { return ['success' => false, 'message' => \_\_('인증 코드가 필요합니다')]; } if (empty($request->code\_type)) { return ['success' => false, 'message' => \_\_('인증 코드 유형이 필요합니다')]; } codeType = $request->code\_type == 'google' ? verification\_type\_gauth : verification\_type\_sms; check = $this->twoFactorService->verifyUserCode($request,Auth::user(),$codeType); if ($check['success'] == TRUE) { response = $this->service->withdrawalProcess($request, $user); } else { response = ['success' => false, 'message' => $check['message']]; } } else { response = $this->service->withdrawalProcess($request, $user); } } else { response = $this->service->withdrawalProcess($request, $user); } 반환 응답()->json($response); } } else { if (Auth::user()->is\_two\_factor\_enabled == 1 && check\_google\_recaptcha\_setting() == true) { if (empty($request->score)) { return redirect()->back()->with('dismiss', \_\_('점수가 필요합니다')); } score = $request->score; if ($score <= 0.1) { this->logger->log('withdrawBalance $score-> ', $score); user->update(['status' => STATUS\_SUSPENDED]); this->logger->log('withdrawBalance 사용자 일시 중단 . 사용자 -> ', $user->id); Auth::로그아웃(); response = ['성공' => false, '메시지' => \_\_('사기로 감지되었습니다')]; } elseif ($score > 0.1 && $score <= 0.9) { if (empty($request->code)) { return redirect()->back()->with('dismiss', \_\_('인증 코드가 필요합니다')); } if (empty($request->code\_type)) { return redirect()->back()->with('dismiss', \_\_('인증 코드 유형이 필요합니다')); } codeType = $request->code\_type == 'google' ? verification\_type\_gauth : verification\_type\_sms; check = $this->twoFactorService->verifyUserCode($request,Auth::user(),$codeType); if ($check['success'] == TRUE) { response = $this->service->withdrawalProcess($request, $user); } else { response = ['success' => false, 'message' => $check['message']]; } } else { response = $this->service->withdrawalProcess($request, $user); } } else { response = $this->service->withdrawalProcess($request, $user); } if($response['success'] == true) { return redirect()->back()->with('success', $response['message']); } else { return redirect()->back()->with('dismiss', $response['message']); } } } catch (\Exception $e) { this->logger->log('withdrawBalance', $e->getMessage()); return redirect()->back()->with('dismiss', \_\_('뭔가 잘못되었습니다')); } } 공개 함수 checkPrivateKeyWithAddrees($encryptedPk,$userPk) { try { pk = $this->reCheckPrivateKey($encryptedPk,$userPk); if($pk['success'] == true) { apiService = 새로운 트론베이스에이피서비스(); getAddress = $apiService->getAddress($pk['data']); if ($getAddress['success'] == true) { walletAddress = Wallet::where(['user\_id' => Auth::id(), 'status' => STATUS\_ACTIVE])->first(); 주소 = $getAddress['데이터']['주소']; if ($address == $