97 lines
3.3 KiB
PHP
97 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Http\Controllers\UploadController;
|
|
use App\Services\UserService;
|
|
use App\Models\FaceMatch;
|
|
use App\Models\Liveperson;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
class StorageLivePerson implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
public $tries = 1;
|
|
public $result;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($result)
|
|
{
|
|
$this->result = $result;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
//存储视频认证结果
|
|
$avatar = $this->uploadFile($this->result['result']['avatar']);
|
|
$live_person = new Liveperson();
|
|
$live_person->user_id = $this->result['user_id'];
|
|
$live_person->status = $this->result['result']['status'];
|
|
$live_person->taskId = $this->result['result']['taskId'];
|
|
$live_person->reasonType = $this->result['result']['reasonType'];
|
|
$live_person->picType = $this->result['result']['picType'];
|
|
$live_person->avatar = $avatar;
|
|
$live_person->faceMatched = $this->result['result']['faceMatched'];
|
|
$live_person->similarityScore = $this->result['result']['similarityScore'];
|
|
$live_person->save();
|
|
//对比头像
|
|
$this->createFaceMatch($live_person);
|
|
}
|
|
|
|
public function uploadFile($file){
|
|
try {
|
|
//下载文件到本地
|
|
$baseName = md5($file).'.jpg';
|
|
$local_name = storage_path() . '/qrcode/' . $baseName;
|
|
// $result = fopen($local_name, 'x+');
|
|
if (!copy(trim($file), $local_name)) {
|
|
throw new \Exception("下载图片失败", 1);
|
|
}
|
|
|
|
$ossClient = UploadController::getOssClient();
|
|
//生成file
|
|
$object = date('Y').date('m')."/".date('d')."/".$baseName;
|
|
$url = 'https://'.config('alioss.picture_domain').'/'.$object;
|
|
//$result = $ossClient->putObject(config('alioss.buckets.picture'), $object, $file);
|
|
$result = $ossClient->uploadFile(config('alioss.buckets.picture'), $object, $local_name);
|
|
} catch(\OSS\Core\OssException $e) {
|
|
\Log::info($e->getMessage());
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
|
|
|
|
//照片对比
|
|
public function createFaceMatch($live_person){
|
|
$user_service = new UserService();
|
|
$result = $user_service->faceMatch($live_person->avatar, $live_person->love_avatar);
|
|
if (empty($result)) return ;
|
|
$face_log = FaceMatch::where('user_id', $live_person->user_id)->first();
|
|
if (empty($face_log)) {
|
|
$face_log = new FaceMatch;
|
|
}
|
|
if (empty($result) || empty($result->face_list)) return ;
|
|
$face_log->user_id = $live_person->user->id;
|
|
$face_log->first_image = $live_person->avatar;
|
|
$face_log->last_image = $live_person->love_avatar;
|
|
$face_log->first_token = ($result->face_list)[0]->face_token;
|
|
$face_log->last_token = ($result->face_list)[1]->face_token;
|
|
$face_log->score = $result->score;
|
|
$face_log->save();
|
|
}
|
|
}
|