SmsJob.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zhoujun
  5. * Date: 2018/9/1
  6. * Time: 11:40
  7. */
  8. namespace addons\faqueue\library\jobs;
  9. use addons\faqueue\model\FaqueueLog;
  10. use app\common\library\Sms;
  11. use think\Log;
  12. use think\queue\job;
  13. class SmsJob
  14. {
  15. public function fire(Job $job, $data){
  16. $method = $data['method'];
  17. switch ($method){
  18. case 'send':
  19. $result = Sms::send($data['mobile'],$data['code'],$data['event']);
  20. break;
  21. case 'notice':
  22. $result = Sms::notice($data['mobile'],$data['smg'],$data['template']);
  23. break;
  24. default:
  25. $result = false;
  26. }
  27. if($result){
  28. Log::write("发送成功,result:".print_r($result,true));
  29. $job->delete();
  30. (new FaqueueLog())->log($job->getQueue(),$job->getName(),$data);
  31. }else{
  32. $job->release();
  33. Log::write("短信发送失败:".print_r([
  34. 'name' => $job->getName(),
  35. 'result' => $result
  36. ],true),'error');
  37. }
  38. }
  39. public function failed($data){
  40. Log::write("短信任务失败:".print_r(['data' => $data,],true),'error');
  41. }
  42. }