AutoService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ 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 app\wechat\model\WechatAuto;
  17. use think\admin\Service;
  18. use think\admin\service\QueueService;
  19. /**
  20. * 关注自动回复服务
  21. * Class AutoService
  22. * @package app\wechat\service
  23. */
  24. class AutoService extends Service
  25. {
  26. /**
  27. * 注册微信用户推送任务
  28. * @param string $openid
  29. * @throws \think\admin\Exception
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function register(string $openid)
  35. {
  36. foreach (WechatAuto::mk()->where(['status' => 1])->order('time asc')->cursor() as $vo) {
  37. [$name, $time] = ["推送客服消息 {$vo['code']}#{$openid}", $this->parseTimeString($vo['time'])];
  38. QueueService::instance()->register($name, "xadmin:fansmsg {$openid} {$vo['code']}", $time, []);
  39. }
  40. }
  41. /**
  42. * 解析配置时间格式
  43. * @param string $time
  44. * @return int
  45. */
  46. private function parseTimeString(string $time): int
  47. {
  48. if (preg_match('|^.*?(\d{2}).*?(\d{2}).*?(\d{2}).*?$|', $time, $vars)) {
  49. return intval($vars[1]) * 3600 * intval($vars[2]) * 60 + intval($vars[3]);
  50. } else {
  51. return 0;
  52. }
  53. }
  54. }