<?php use Model\listsSql; /** * 自动回复的邮件 * @author:dc * @time 2024/9/6 17:09 * Class HotMail */ class AutoMail { public function __construct(){ $this->db = db(); $this->start(); } /** * shopk那边的预热邮箱 * @var array */ private $shopkHotEmail = []; /** * @var \Lib\Db|\Lib\DbPool */ private $db; private $fids = []; /** * @author:dc * @time 2024/7/18 14:04 */ private function start(){ $this->fids = $this->db->all("select `id` from `folders` where `folder` = '收件箱'"); $this->fids = array_column($this->fids,'id'); $filter = @file_get_contents('https://fob.ai.cc/api/mail/ai_inbox_filter/'.md5('aicc.'.date('ymdh'))); $filter = @json_decode($filter,true); if(!is_array($filter)){ return 0; } array_map(function ($v){ $this->filter[] = [ $v['type'], $v['text'], ]; },$filter[0]); if($this->filter){ redis()->set('ai_email_filter_lists',$this->filter,86400); } if(redis()->add('auto_mail_sync2',1,60)){ _echo('正在计算数据'); $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); $startId = $maxId-20000; foreach (minMaxToArray($startId,$maxId) as $ids){ redis()->rPush('auto_check_ids',implode(',',$ids)); } _echo('计算完成'); } while (1){ $ids = redis()->lPop('auto_check_ids'); if($ids){ $ids = explode(',',$ids); $this->run($ids); }else{ break; } } } private $filter = []; private function run($id){ $list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id]),'`id`,`from`,`subject`,`folder_id`')); foreach ($list as $item){ // 必须是收件箱 if(in_array($item['folder_id'],$this->fids)){ foreach ($this->filter as $f){ list($t,$str) = $f; $haystack = ''; if($t==2){ $haystack = $item['subject']; }elseif ($t==1){ $haystack = $item['from']; } if(stripos($haystack,$str)!==false){ if(!$this->db->count("select count(*) from `lists_auto` where `list_id` = ".$item['id'])){ _echo("插入数据 ".$item['id'].'==>'.$this->db->create('lists_auto',['list_id'=>$item['id']],false).'==>'.$haystack); } break; } } } } } } include_once "../vendor/autoload.php"; new AutoMail();