FaceVerifyJob.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\User\UserModel;
  4. use App\Services\Partner\NoticeService;
  5. use App\Services\User\PartnerService;
  6. use App\Services\Vendor\BaiduAi\FaceService;
  7. use Carbon\Carbon;
  8. use Illuminate\Bus\Queueable;
  9. use Illuminate\Queue\SerializesModels;
  10. use Illuminate\Queue\InteractsWithQueue;
  11. use Illuminate\Contracts\Queue\ShouldQueue;
  12. use Illuminate\Foundation\Bus\Dispatchable;
  13. class FaceVerifyJob implements ShouldQueue
  14. {
  15. use Dispatchable;
  16. use InteractsWithQueue;
  17. use Queueable;
  18. use SerializesModels;
  19. private $uid;
  20. private $liveness_image;
  21. private $check_image;
  22. private $cnt = 0;
  23. /**
  24. * Create a new job instance.
  25. *
  26. * @param int $uid
  27. * @param string $liveness_image
  28. * @param string $check_image
  29. * @param int $cnt
  30. */
  31. public function __construct(int $uid, string $liveness_image, string $check_image, int $cnt)
  32. {
  33. $this->uid = $uid;
  34. $this->liveness_image = $liveness_image;
  35. $this->check_image = $check_image;
  36. $this->cnt = $cnt;
  37. }
  38. /**
  39. * Execute the job.
  40. *
  41. */
  42. public function handle()
  43. {
  44. sleep(5);
  45. $checks = array(
  46. 'photo_src' => 'check_photo',
  47. 'photo_1' => 'photo_1_check',
  48. 'photo_2' => 'photo_2_check',
  49. 'photo_3' => 'photo_3_check',
  50. 'photo_4' => 'photo_4_check'
  51. );
  52. if ($this->cnt > 5) {
  53. return;
  54. }
  55. $photo_field = null;
  56. try {
  57. $user = UserModel::findOrFail($this->uid);
  58. if (!empty($user->identity_auth)) {
  59. return;
  60. }
  61. if ($user->photo_src == $this->check_image) {
  62. $photo_field = "photo_src";
  63. }
  64. if ($user->photo_1 == $this->check_image) {
  65. $photo_field = "photo_1";
  66. }
  67. if ($user->photo_2 == $this->check_image) {
  68. $photo_field = "photo_2";
  69. }
  70. if ($user->photo_3 == $this->check_image) {
  71. $photo_field = "photo_3";
  72. }
  73. if ($user->photo_4 == $this->check_image) {
  74. $photo_field = "photo_4";
  75. }
  76. if (empty($photo_field)) {
  77. return false;
  78. }
  79. } catch (\Exception $exception) {
  80. return;
  81. }
  82. $fs = new FaceService();
  83. $images = array(
  84. [
  85. 'image' => $this->liveness_image,
  86. 'image_type' => 'URL',
  87. 'face_type' => 'LIVE',
  88. 'quality_control' => 'NONE',
  89. 'liveness_control' => 'LOW'
  90. ],
  91. [
  92. 'image' => "https://oss.pocketuniversity.cn" . $this->check_image,
  93. 'image_type' => 'URL',
  94. 'face_type' => 'LIVE',
  95. 'quality_control' => 'NONE',
  96. 'liveness_control' => 'NONE'
  97. ]
  98. );
  99. $data = $fs->match($images);
  100. $msg = $data;
  101. $msg['uid'] = $this->uid;
  102. $msg['liveness_image'] = $this->liveness_image;
  103. $msg['check_image'] = $this->check_image;
  104. $msg['field'] = $photo_field;
  105. switch ($data['error_code']) {
  106. case 0:
  107. if ($data['result']['score'] > 69) {
  108. $user->identity_auth = $photo_field;
  109. $user->save();
  110. if ($user->partner_id > 0) {
  111. $ps = new PartnerService();
  112. $ps->check($user->partner_id, $checks[$photo_field], 1);
  113. }
  114. if ($user->wx_auth == 1) {
  115. $ns = new NoticeService();
  116. $ns->authenticationSuccess($user->uid);
  117. }
  118. return;
  119. } else {
  120. return;
  121. }
  122. break;
  123. FaceVerifyJob::dispatch(
  124. $this->uid,
  125. $this->liveness_image,
  126. $this->check_image,
  127. $this->cnt + 1
  128. )->delay(Carbon::now()->addMinutes(10));
  129. break;
  130. case 222204:
  131. default:
  132. break;
  133. }
  134. }
  135. }