SendAliyunSmsJobs.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Jobs\Manager\Process;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldBeUnique;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use App\Facades\Servers\Logs\Log;
  10. use App\Servers\Sms\VerifyCode as SmsVerifyCode;
  11. use App\Models\Manager\Process\SubNoticeLog as SubNoticeLogModel;
  12. /**
  13. * 阿里云短信通知队列
  14. * @author 唐远望
  15. * @version 1.0
  16. * @date 2026-04-16
  17. */
  18. class SendAliyunSmsJobs implements ShouldQueue
  19. {
  20. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  21. protected $message_data;
  22. protected $company_id;
  23. /**
  24. * Create a new job instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct(array $message_data)
  29. {
  30. $this->message_data = $message_data;
  31. }
  32. /**
  33. * Execute the job.
  34. *
  35. * @return void
  36. */
  37. public function handle()
  38. {
  39. try {
  40. $SmsVerifyCode = new SmsVerifyCode();
  41. $SubNoticeLogModel = new SubNoticeLogModel();
  42. $notice_data_info = $this->message_data['notice_data_info'];
  43. $mobile = $notice_data_info['mobile'];
  44. $sms_content = json_decode($notice_data_info['mobile_content'], true);
  45. $parameter = $sms_content['parameter'];
  46. $totle_number = $parameter['totle_number'];
  47. $number1 = $parameter['number1'];
  48. $number2 = $parameter['number2'];
  49. $number3 = $parameter['number3'];
  50. $sms_tpl_id = $sms_content['sms_tpl_id'];
  51. $res_msg = $SmsVerifyCode->sendContent($mobile, ['totle_number' => $totle_number, 'number1' => $number1, 'number2' => $number2, 'number3' => $number3], $sms_tpl_id);
  52. Log::info('job_send_sms', '订阅短信通知推送队列记录', ['email' => $mobile, 'sms_tpl_id' => $sms_tpl_id, 'msg' => $res_msg]);
  53. //更新发送状态
  54. $SubNoticeLogModel->where(['id' => $notice_data_info['id']])->update(['sms_status' => 0]);
  55. } catch (\Exception $e) {
  56. Log::info('job_send_sms', '阿里云短信通知队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  57. }
  58. }
  59. public function failed(\Throwable $exception)
  60. {
  61. Log::info('job_send_sms', '阿里云短信通知队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  62. }
  63. }