<?php use Model\listsSql; include_once "../vendor/autoload.php"; /** * 只有黑格 在使用此业务 * 预热 邮件 数据处理 * 主要功能: * 在 https://fob.ai.cc/api/mail/preheat 拉取 预热邮件 * 在 https://oa.shopk.com/api/mail/preheat 拉取 预热邮件 * 在 lists表中找到这些邮箱发出的邮件 * 然后在 hot_mail表中记录起来 * @author:dc * @time 2024/7/18 13:50 * Class HotMail */ class HotMail { public function __construct(){ $this->db = db(); $this->start(); } /** * shopk那边的预热邮箱 * @var array */ private $shopkHotEmail = []; /** * @var \Lib\Db|\Lib\DbPool */ private $db; private $back = []; /** * @author:dc * @time 2024/7/18 14:04 */ private function start(){ _echo('启动预热邮件处理 '.getmypid()); if(redis()->add('hot_mail_sync',1,30)){ $fob = $this->getFobHotEmail(); // 把黑格自己的也算进去 $this->shopkHotEmail = array_merge($this->getHotEmail('e'),$this->getHotEmail('w'),$fob); $this->shopkHotEmail = array_map('strtolower',$this->shopkHotEmail); $this->shopkHotEmail = array_flip($this->shopkHotEmail); $this->shopkHotEmail['job@aicc-email.com'] = 1; foreach ($this->shopkHotEmail as $e=>$i){ try { if(!$this->db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$e]))){ echo '插入数据 '.$e."\n"; $this->db->throw()->insert('hot_mail',['email'=>$e],false); } }catch (Throwable $e){ } } // 黑名单 if(!empty($this->back)&&is_array($this->back)){ foreach ($this->back as $item){ if(!$this->db->count("select count(*) from `ai_black_email` where ".dbWhere(['email'=>$item]))){ echo '插入数据 '.$item."\n"; $this->db->insert('ai_black_email',['email'=>$item],false); } } } } echo date('d H:i:s').' ==》 已执行完成'.PHP_EOL; } /** * 获取预热邮箱 * shopk的 * @return array * @author:dc * @time 2024/7/18 13:58 */ private function getHotEmail($t='e'):array { $url['e'] = 'https://oa.shopk.com/api/mail/preheat'; $url['w'] = 'https://oa.shopk.com/api/mail/write?iswrite=1&id=11321'; $data = @file_get_contents($url[$t]); if($data){ $data = @json_decode($data,1); if($data && isset($data['data']) && is_array($data['data'])){ // 全部转小写 return array_map("strtolower",$data['data']); } } logs('shopk 获取预热邮箱错误:'.print_r($data,1),'get_hot_oa_email.error.log')->write(); return []; } /** * fob黑格的预热邮箱 * @author:dc * @time 2024/7/18 14:21 */ private function getFobHotEmail(){ $data = @file_get_contents('https://fob.ai.cc/api/mail/preheat/'.md5('aicc.'.date('ymdh'))); if($data){ $data = @json_decode($data,1); if($data && isset($data['data']) && is_array($data['data'])){ if(!empty($data['back'])){ $this->back = $data['back']??[]; } return $data['data']; } } logs('fob 获取预热邮箱错误:'.print_r($data,1),'get_hot_fob_email.error.log')->write(); return []; } } new HotMail();