AutoService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\wechat\service;
  16. use think\admin\Service;
  17. use think\admin\service\QueueService;
  18. /**
  19. * 关注自动回复服务
  20. * Class AutoService
  21. * @package app\wechat\service
  22. */
  23. class AutoService extends Service
  24. {
  25. /**
  26. * 注册微信用户推送任务
  27. * @param string $openid
  28. * @throws \think\admin\Exception
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function register(string $openid)
  34. {
  35. foreach ($this->app->db->name('WechatAuto')->where(['status' => 1])->order('time asc')->cursor() as $vo) {
  36. [$name, $time] = ["推送客服消息 {$vo['code']}#{$openid}", $this->parseTimeString($vo['time'])];
  37. QueueService::instance()->register($name, "xadmin:fansmsg {$openid} {$vo['code']}", $time, []);
  38. }
  39. }
  40. /**
  41. * 解析配置时间格式
  42. * @param string $time
  43. * @return int
  44. */
  45. private function parseTimeString(string $time): int
  46. {
  47. if (preg_match('|^.*?(\d{2}).*?(\d{2}).*?(\d{2}).*?$|', $time, $vars)) {
  48. return intval($vars[1]) * 3600 * intval($vars[2]) * 60 + intval($vars[3]);
  49. } else {
  50. return 0;
  51. }
  52. }
  53. }