Messenger.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\job;
  3. use think\queue\Job;
  4. use think\facade\Log;
  5. use think\facade\Db;
  6. use app\common\api\ChuanglanSmsApi;
  7. /**
  8. * Description of Messenger
  9. *
  10. * @author sgq
  11. */
  12. class Messenger {
  13. public function fire(Job $job, $data) {
  14. if ($this->deal($data)) {
  15. Log::info(json_encode($data));
  16. $job->delete();
  17. return true;
  18. }
  19. Log::error(json_encode($data));
  20. if ($job->attempts() >= 3) {
  21. $job->delete();
  22. return false;
  23. }
  24. $job->release(10); //10秒后重试
  25. }
  26. /**
  27. * 处理业务逻辑
  28. * @param type $data
  29. * @return bool
  30. */
  31. public function deal($data): bool {
  32. $type = $data["type"];
  33. switch ($type) {
  34. case 1:
  35. //通知单位审核注册
  36. $enterprise = $data["info"]; //企业信息
  37. $msg["createTime"] = date("Y-m-d H:i:s");
  38. $sender = new ChuanglanSmsApi();
  39. $sender->sendSMS($mobile, $msg);
  40. case 2:
  41. break;
  42. }
  43. return false;
  44. }
  45. }