queue="sms";//指定队列 $this->mobile = $mobile; $this->sms_template_alias = $sms_template_alias; $this->params = $params; $this->isAuthSms = $isAuthSms; $this->utype = 0; $this->sender_id = 0; $this->batch_id = 0; $this->isVariable = $isVariable; $this->content = $content; } /** * Execute the job. * * @param SmsRepository $smsRepository * @param SmsTemplateRepository $smsTemplateRepository * @param SmsQueueRepository $smsQueueRepository * @param SmsBatchRepository $smsBatchRepository * @return void * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handle( SmsRepository $smsRepository, SmsTemplateRepository $smsTemplateRepository, SmsQueueRepository $smsQueueRepository, SmsBatchRepository $smsBatchRepository ) { $sms=$smsRepository->getUsefulSms(); $class="Aix\\Sms\\".$sms['alias']; /** @var Smser $smsInstance */ $smsInstance=new $class($sms->app_key, $sms->secret_key, $sms->signature_key); if($sms['alias'] == 'ChuanglanSms'){ $template = $smsTemplateRepository->getTemplateByCL($this->sms_template_alias, $sms['alias']); }else{ $template=$smsTemplateRepository->getTemplate($this->sms_template_alias, $sms['alias'], $this->params); } $smsQueue=$smsQueueRepository->createRecord($template, $this->mobile, $this->utype, $this->sender_id, $this->batch_id); if (!isset($template->role) || $template->role->status == 0) { $smsQueueRepository->saveRecord($smsQueue->id, 3, "短信规则不存在或者短信规则没有开启"); $smsBatchRepository->updateBatch($this->batch_id, false); return; } try { if ($this->isAuthSms) { $code = $smsInstance->sendAuthSms($this->mobile, $template); } else { if($this->isVariable){ $code = $smsInstance->sendSms($this->mobile, $template, $this->params); }else{ $code = $smsInstance->sendSms($this->mobile, $template, $this->params, false, $this->content); } } $smsQueueRepository->saveRecord($smsQueue->id, 1, $code); $smsBatchRepository->updateBatch($this->batch_id); } catch (\Exception $e) { $smsQueueRepository->saveRecord($smsQueue->id, 3, $e->getMessage()); $smsBatchRepository->updateBatch($this->batch_id, false); //throw $e; } if (!empty($this->callback)) { $obj=app($this->callback[0][0]); call_user_func_array([$obj, $this->callback[0][1]], $this->callback[1]); } } /** * @param $callback */ public function setCallback($callback): void { $this->callback = $callback; } /** * 设置发送者 * @param $utype: 0系统,1企业,2用户 * @param $id: 对应 utype id */ public function setSender($utype, $id) { $this->utype=$utype; $this->sender_id=$id; } /** * @param mixed $batch_id */ public function setBatchId($batch_id): void { $this->batch_id = $batch_id; } }