改进 实名认证
This commit is contained in:
parent
7666c4f7a8
commit
6676ccfc94
@ -15,12 +15,32 @@ class RealNameController extends Controller
|
||||
{
|
||||
public function verify(Request $request): JsonResponse
|
||||
{
|
||||
Log::debug('实名认证回调', $request->all());
|
||||
|
||||
return $this->validateOrSave($request)
|
||||
? $this->success()
|
||||
: $this->failed();
|
||||
}
|
||||
|
||||
public function process(Request $request): View
|
||||
{
|
||||
Log::debug('实名认证回调', $request->all());
|
||||
|
||||
return $this->validateOrSave($request)
|
||||
? view('real_name.success')
|
||||
: view('real_name.failed');
|
||||
}
|
||||
|
||||
public function validateOrSave(Request $request): bool
|
||||
{
|
||||
Log::debug('实名认证回调', $request->all());
|
||||
|
||||
$result = (new RealNameSupport())->verify($request->all());
|
||||
|
||||
if (! $result) {
|
||||
Log::warning('实名认证失败', $request->all());
|
||||
|
||||
return $this->error('实名认证失败。');
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = (new User)->find($result['user_id']);
|
||||
@ -32,11 +52,6 @@ public function verify(Request $request): JsonResponse
|
||||
|
||||
$user->notify(new UserNotification('再次欢迎您!', '再次欢迎您!您的实人认证已通过。', true));
|
||||
|
||||
return $this->success('实名认证成功。');
|
||||
}
|
||||
|
||||
public function process(): View
|
||||
{
|
||||
return view('real_name.process');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Exceptions\CommonException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\RealNameSupport;
|
||||
use Carbon\Exceptions\InvalidFormatException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
@ -22,7 +23,12 @@ public function store(Request $request): RedirectResponse
|
||||
|
||||
$realNameSupport = new RealNameSupport();
|
||||
|
||||
try {
|
||||
$birthday = $realNameSupport->getBirthday($request->input('id_card'));
|
||||
} catch (InvalidFormatException) {
|
||||
return back()->with('error', '身份证号码格式错误。');
|
||||
}
|
||||
|
||||
// 检查年龄是否在区间内 settings.supports.real_name.min_age ~ settings.supports.real_name.max_age
|
||||
if (Carbon::now()->diffInYears($birthday) < config('settings.supports.real_name.min_age') || Carbon::now()->diffInYears($birthday) > config('settings.supports.real_name.max_age')) {
|
||||
$message = '至少需要 '.config('settings.supports.real_name.min_age').' 岁,最大 '.config('settings.supports.real_name.max_age').' 岁。';
|
||||
|
@ -19,6 +19,8 @@ class ValidateReferer
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
// return $next($request);
|
||||
|
||||
// 如果 referer 不为空,且不是来自本站的请求,则返回 403
|
||||
if ($request->headers->get('referer') && ! Str::contains($request->headers->get('referer'), config('app.url'))) {
|
||||
abort(403, '来源不属于后台。');
|
||||
|
@ -18,6 +18,7 @@
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Str;
|
||||
@ -110,11 +111,11 @@ protected static function boot()
|
||||
$user->real_name_verified_at = now();
|
||||
|
||||
// 更新生日
|
||||
try {
|
||||
$user->birthday_at = $user->getBirthdayFromIdCard();
|
||||
} catch (InvalidFormatException) {
|
||||
$user->birthday_at = null;
|
||||
}
|
||||
// try {
|
||||
// $user->birthday_at = $user->getBirthdayFromIdCard();
|
||||
// } catch (InvalidFormatException) {
|
||||
// $user->birthday_at = null;
|
||||
// }
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -130,16 +131,18 @@ public function hosts(): HasMany
|
||||
return $this->hasMany(Host::class);
|
||||
}
|
||||
|
||||
private function getBirthdayFromIdCard(): string
|
||||
public function getBirthdayFromIdCard(string|null $id_card = null): Carbon
|
||||
{
|
||||
$idCard = $this->id_card;
|
||||
if (empty($id_card)) {
|
||||
$id_card = $this->id_card;
|
||||
}
|
||||
|
||||
$bir = substr($idCard, 6, 8);
|
||||
$bir = substr($id_card, 6, 8);
|
||||
$year = (int) substr($bir, 0, 4);
|
||||
$month = (int) substr($bir, 4, 2);
|
||||
$day = (int) substr($bir, 6, 2);
|
||||
|
||||
return $year.'-'.$month.'-'.$day;
|
||||
return Carbon::parse($year.'-'.$month.'-'.$day);
|
||||
}
|
||||
|
||||
public function hasBalance(string $amount = '0.01'): bool
|
||||
|
@ -3,7 +3,9 @@
|
||||
namespace App\Support;
|
||||
|
||||
use App\Exceptions\CommonException;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -77,6 +79,8 @@ private function submit(string $id): string
|
||||
'idName' => $real_name['name'],
|
||||
'pageTitle' => config('app.display_name').' 实名认证',
|
||||
'notifyUrl' => route('public.real-name.notify'),
|
||||
// 'notifyUrl' => 'http://99dsazj8qp.sharedwithexpose.com/public/real_name/notify',
|
||||
|
||||
'procedureType' => 'video',
|
||||
'txtBgColor' => '#cccccc',
|
||||
|
||||
@ -86,6 +90,8 @@ private function submit(string $id): string
|
||||
'retIdImg' => 'false',
|
||||
'returnImg' => 'false',
|
||||
'returnUrl' => route('public.real-name.process'),
|
||||
// 'returnUrl' => 'http://99dsazj8qp.sharedwithexpose.com/public/real_name/process',
|
||||
|
||||
];
|
||||
|
||||
$resp = $this->http->asForm()->post('/edis_ctid_id_name_video_ocr_h5', $data)->json();
|
||||
@ -107,8 +113,6 @@ public function verify(array $request): array|bool
|
||||
{
|
||||
$data = json_decode($request['data'], true);
|
||||
|
||||
Log::debug('实名认证回调', $request);
|
||||
|
||||
$verify = $this->verifyIfSuccess($request['data'], $request['sign']);
|
||||
|
||||
if (! $verify) {
|
||||
@ -149,12 +153,8 @@ private function verifyIfSuccess(string $request, string $sign): bool
|
||||
return $flag === 1;
|
||||
}
|
||||
|
||||
public function getBirthday(string $id_card): string
|
||||
public function getBirthday(string $id_card): Carbon
|
||||
{
|
||||
$year = substr($id_card, 6, 4);
|
||||
$month = substr($id_card, 10, 2);
|
||||
$day = substr($id_card, 12, 2);
|
||||
|
||||
return $year.'-'.$month.'-'.$day;
|
||||
return (new User())->getBirthdayFromIdCard($id_card);
|
||||
}
|
||||
}
|
||||
|
9
resources/views/real_name/failed.blade.php
Normal file
9
resources/views/real_name/failed.blade.php
Normal file
@ -0,0 +1,9 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<h3>我们不能确定这是你。</h3>
|
||||
|
||||
<p>
|
||||
请尝试重新登录。
|
||||
</p>
|
||||
@endsection
|
9
resources/views/real_name/success.blade.php
Normal file
9
resources/views/real_name/success.blade.php
Normal file
@ -0,0 +1,9 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<h3>再次欢迎您。</h3>
|
||||
|
||||
<p>
|
||||
您已成功完成实人认证,再次欢迎您。
|
||||
</p>
|
||||
@endsection
|
@ -8,7 +8,7 @@
|
||||
use App\Http\Controllers\Public\RealNameController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::post('real_name/notify', [RealNameController::class, 'verify'])->name('real-name.notify');
|
||||
Route::match(['post', 'get'], 'real_name/notify', [RealNameController::class, 'verify'])->name('real-name.notify');
|
||||
Route::match(['post', 'get'], 'real_name/process', [RealNameController::class, 'process'])->name('real-name.process');
|
||||
|
||||
Route::post('auth_request', [AuthRequestController::class, 'store']);
|
||||
|
Loading…
Reference in New Issue
Block a user