From d40b29881f24bdb391532e8725884b7dd87e6c57 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sun, 15 Jan 2023 07:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Helpers/ApiResponse.php | 10 ++-- .../Controllers/Web/RealNameController.php | 10 ++-- app/Models/User.php | 20 ++++---- app/Notifications/WebNotification.php | 1 + app/Support/RealNameSupport.php | 48 +++++++++---------- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/app/Helpers/ApiResponse.php b/app/Helpers/ApiResponse.php index 3d50793..ebb5543 100644 --- a/app/Helpers/ApiResponse.php +++ b/app/Helpers/ApiResponse.php @@ -62,11 +62,6 @@ public function error($message = '', $code = 400): JsonResponse return $this->apiResponse($message, $code); } - public function failed($message = 'Failed', $code = 400): JsonResponse - { - return $this->apiResponse($message, $code); - } - public function serviceUnavailable($message = 'Service unavailable'): JsonResponse { return $this->error($message, 503); @@ -97,6 +92,11 @@ public function serverError($message = 'Server error'): JsonResponse return $this->error($message, 500); } + public function failed($message = 'Failed', $code = 400): JsonResponse + { + return $this->apiResponse($message, $code); + } + public function unauthorized($message = 'Unauthorized'): JsonResponse { return $this->error($message, 401); diff --git a/app/Http/Controllers/Web/RealNameController.php b/app/Http/Controllers/Web/RealNameController.php index 968d6a6..25d079f 100644 --- a/app/Http/Controllers/Web/RealNameController.php +++ b/app/Http/Controllers/Web/RealNameController.php @@ -9,11 +9,6 @@ class RealNameController extends Controller { - public function create() - { - return view('real_name.create'); - } - public function store(Request $request) { $request->validate([ @@ -46,4 +41,9 @@ public function store(Request $request) return redirect($output); } + + public function create() + { + return view('real_name.create'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 23918ef..7c85225 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -95,6 +95,16 @@ public function hosts(): HasMany return $this->hasMany(Host::class); } + private function getBirthdayFromIdCard(): string + { + $idCard = $this->id_card; + + $year = substr($idCard, 6, 4); + $month = substr($idCard, 10, 2); + $day = substr($idCard, 12, 2); + return $year . '-' . $month . '-' . $day; + } + public function user_group(): BelongsTo { return $this->belongsTo(UserGroup::class); @@ -112,14 +122,4 @@ public function selectPublic(): User // 过滤掉私有字段 return $this->select(['id', 'name', 'email_md5', 'created_at']); } - - private function getBirthdayFromIdCard(): string - { - $idCard = $this->id_card; - - $year = substr($idCard, 6, 4); - $month = substr($idCard, 10, 2); - $day = substr($idCard, 12, 2); - return $year . '-' . $month . '-' . $day; - } } diff --git a/app/Notifications/WebNotification.php b/app/Notifications/WebNotification.php index 0073691..f9f304b 100644 --- a/app/Notifications/WebNotification.php +++ b/app/Notifications/WebNotification.php @@ -12,6 +12,7 @@ class WebNotification extends Notification use Queueable; public array|Model $message = []; + /** * Create a new notification instance. * diff --git a/app/Support/RealNameSupport.php b/app/Support/RealNameSupport.php index e3ef63e..5ad2266 100644 --- a/app/Support/RealNameSupport.php +++ b/app/Support/RealNameSupport.php @@ -53,30 +53,6 @@ public function create($user_id, $name, $id_card): string return $this->submit($id); } - /** - * 验证实名认证请求 - * - * @param array $request - * - * @return array|bool - */ - public function verify(array $request): array|bool - { - $data = json_decode($request['data'], true); - - $verify = $this->verifyIfSuccess($request['data'], $request['sign']); - - if (!$verify) { - return false; - } - - if ($data['code'] !== 'PASS') { - return false; - } - - return Cache::get('real_name:' . $data['bizNo'], false); - } - /** 向 实名认证服务 发送请求 * * @param string $id @@ -117,6 +93,30 @@ private function submit(string $id): string return $resp['verifyUrl']; } + /** + * 验证实名认证请求 + * + * @param array $request + * + * @return array|bool + */ + public function verify(array $request): array|bool + { + $data = json_decode($request['data'], true); + + $verify = $this->verifyIfSuccess($request['data'], $request['sign']); + + if (!$verify) { + return false; + } + + if ($data['code'] !== 'PASS') { + return false; + } + + return Cache::get('real_name:' . $data['bizNo'], false); + } + private function verifyIfSuccess(string $request, string $sign): bool {