AutoService.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\wechat\service;
  3. use think\admin\Service;
  4. use think\admin\service\QueueService;
  5. /**
  6. * 关注自动回复服务
  7. * Class AutoService
  8. * @package app\wechat\service
  9. */
  10. class AutoService extends Service
  11. {
  12. /**
  13. * 注册微信用户推送任务
  14. * @param string $openid
  15. * @throws \think\admin\Exception
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\DbException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. */
  20. public function register(string $openid)
  21. {
  22. foreach ($this->app->db->name('WechatAuto')->where(['status' => 1])->order('time asc')->cursor() as $vo) {
  23. [$name, $time] = ["推送客服消息 {$vo['code']}#{$openid}", $this->parseTimeString($vo['time'])];
  24. QueueService::instance()->register($name, "xadmin:fansmsg {$openid} {$vo['code']}", $time, []);
  25. }
  26. }
  27. /**
  28. * 解析配置时间格式
  29. * @param string $time
  30. * @return int
  31. */
  32. private function parseTimeString(string $time): int
  33. {
  34. if (preg_match('|^.*?(\d{2}).*?(\d{2}).*?(\d{2}).*?$|', $time, $vars)) {
  35. return intval($vars[1]) * 3600 * intval($vars[2]) * 60 + intval($vars[3]);
  36. } else {
  37. return 0;
  38. }
  39. }
  40. }