正在显示
1 个修改的文件
包含
42 行增加
和
40 行删除
| @@ -13,7 +13,8 @@ require_once "../vendor/autoload.php"; | @@ -13,7 +13,8 @@ require_once "../vendor/autoload.php"; | ||
| 13 | * @time 2025/7/2 9:58 | 13 | * @time 2025/7/2 9:58 |
| 14 | * Class fob_ai_mail_auto_reply | 14 | * Class fob_ai_mail_auto_reply |
| 15 | */ | 15 | */ |
| 16 | -class fob_hot_ai_mail_auto_reply { | 16 | +class fob_hot_ai_mail_auto_reply |
| 17 | +{ | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | public $isStop = false; | 20 | public $isStop = false; |
| @@ -34,8 +35,8 @@ class fob_hot_ai_mail_auto_reply { | @@ -34,8 +35,8 @@ class fob_hot_ai_mail_auto_reply { | ||
| 34 | { | 35 | { |
| 35 | $this->db = db(); | 36 | $this->db = db(); |
| 36 | 37 | ||
| 37 | - $handler = function ($signal){ | ||
| 38 | - _echo('收到进程信号 '. $signal); | 38 | + $handler = function ($signal) { |
| 39 | + _echo('收到进程信号 ' . $signal); | ||
| 39 | // 可以处理其他程序 | 40 | // 可以处理其他程序 |
| 40 | $this->isStop = true; | 41 | $this->isStop = true; |
| 41 | }; | 42 | }; |
| @@ -55,7 +56,7 @@ class fob_hot_ai_mail_auto_reply { | @@ -55,7 +56,7 @@ class fob_hot_ai_mail_auto_reply { | ||
| 55 | pcntl_signal_dispatch(); | 56 | pcntl_signal_dispatch(); |
| 56 | 57 | ||
| 57 | // 是否超过来最大执行时间 | 58 | // 是否超过来最大执行时间 |
| 58 | - if(time()-43200 > $this->startTime){ | 59 | + if (time() - 43200 > $this->startTime) { |
| 59 | return true; | 60 | return true; |
| 60 | } | 61 | } |
| 61 | 62 | ||
| @@ -64,18 +65,19 @@ class fob_hot_ai_mail_auto_reply { | @@ -64,18 +65,19 @@ class fob_hot_ai_mail_auto_reply { | ||
| 64 | 65 | ||
| 65 | protected $bodys = []; | 66 | protected $bodys = []; |
| 66 | 67 | ||
| 67 | - public function handler(){ | 68 | + public function handler() |
| 69 | + { | ||
| 68 | 70 | ||
| 69 | // $this->bodys = file_get_contents(__DIR__."/body.reply"); | 71 | // $this->bodys = file_get_contents(__DIR__."/body.reply"); |
| 70 | // $this->bodys = explode("--------------",$this->bodys); | 72 | // $this->bodys = explode("--------------",$this->bodys); |
| 71 | 73 | ||
| 72 | - while (!$this->isStop()){ | 74 | + while (!$this->isStop()) { |
| 73 | 75 | ||
| 74 | try { | 76 | try { |
| 75 | $id = redis()->lPop('new_hot_mail_auto_reply_ids'); | 77 | $id = redis()->lPop('new_hot_mail_auto_reply_ids'); |
| 76 | - if($id){ | 78 | + if ($id) { |
| 77 | // 检查是否到时间了 | 79 | // 检查是否到时间了 |
| 78 | - list($did,$time) = explode('.',((string) $id).'.0'); | 80 | + list($did, $time) = explode('.', ((string)$id) . '.0'); |
| 79 | 81 | ||
| 80 | // $h = (int) date('H'); | 82 | // $h = (int) date('H'); |
| 81 | // if($h >= 23 || $h < 6 ){ | 83 | // if($h >= 23 || $h < 6 ){ |
| @@ -84,79 +86,81 @@ class fob_hot_ai_mail_auto_reply { | @@ -84,79 +86,81 @@ class fob_hot_ai_mail_auto_reply { | ||
| 84 | // } | 86 | // } |
| 85 | 87 | ||
| 86 | // 查询数据 | 88 | // 查询数据 |
| 87 | - $data = $this->db->first(\Model\listsSql::first('`id` = '.$did,'`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`')); | ||
| 88 | - if($data && $data['is_hots']){ | 89 | + $data = $this->db->first(\Model\listsSql::first('`id` = ' . $did, '`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`')); |
| 90 | + if ($data && $data['is_hots']) { | ||
| 89 | // 在检查下是否是 收件箱 | 91 | // 在检查下是否是 收件箱 |
| 90 | - if($this->db->cache(3600)->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){ | ||
| 91 | - _echo('处理 '.$data['id']. " run " .date("Y-m-d H:i:s",$data['udate'])); | 92 | + if ($this->db->cache(3600)->value(\Model\folderSql::has(['id' => $data['folder_id'], 'origin_folder' => 'INBOX']))) { |
| 93 | + _echo('处理 ' . $data['id'] . " run " . date("Y-m-d H:i:s", $data['udate'])); | ||
| 92 | $email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id'])); | 94 | $email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id'])); |
| 93 | 95 | ||
| 94 | // 验证是否是ai邮箱 | 96 | // 验证是否是ai邮箱 |
| 95 | - if($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'",$email['email']))){ | 97 | + if ($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'", $email['email']))) { |
| 96 | 98 | ||
| 97 | // 验证邮箱状态 | 99 | // 验证邮箱状态 |
| 98 | -// $fobemail = fob_mysql()->cache(300)->first("select `status`,`is_send_mail`,`is_web_send` from `e_mail_binds` where `email_id` = ".$data['email_id']); | ||
| 99 | -// // 状态异常的跳过 | ||
| 100 | -// if(!$fobemail || $fobemail['status']!=1||!$fobemail['is_send_mail']){ | ||
| 101 | -// continue; | ||
| 102 | -// } | 100 | + $post_id = fob_mysql()->cache(3600)->value("select `post_id` from `e_mail_binds` where `email_id` = " . $data['email_id']); |
| 101 | +// // 国内项目不回复 | ||
| 102 | + if ($post_id == 10001746) { | ||
| 103 | + _echo('国内项目跳过'); | ||
| 104 | + continue; | ||
| 105 | + } | ||
| 103 | 106 | ||
| 104 | // 标记已读 | 107 | // 标记已读 |
| 105 | $email['password'] = base64_decode($email['password']); | 108 | $email['password'] = base64_decode($email['password']); |
| 106 | $email['host'] = $email['imap']; | 109 | $email['host'] = $email['imap']; |
| 107 | $mailInstance = new Imap(new \Lib\Imap\ImapConfig($email)); | 110 | $mailInstance = new Imap(new \Lib\Imap\ImapConfig($email)); |
| 108 | - if($mailInstance->login()){ | 111 | + if ($mailInstance->login()) { |
| 109 | $mailInstance->folder('INBOX')->msg()->uid($data['uid'])->seen(); | 112 | $mailInstance->folder('INBOX')->msg()->uid($data['uid'])->seen(); |
| 110 | $mailInstance = null; | 113 | $mailInstance = null; |
| 111 | } | 114 | } |
| 112 | 115 | ||
| 113 | // 来回超过5次就不回了 | 116 | // 来回超过5次就不回了 |
| 114 | - if(substr_count($data['subject'],"Re:") < 1 ){ | 117 | + if (substr_count($data['subject'], "Re:") < 1) { |
| 115 | // 有配置才回复 | 118 | // 有配置才回复 |
| 116 | $email['hot_email'] = 1; | 119 | $email['hot_email'] = 1; |
| 117 | $email['password'] = base64_encode($email['password']); | 120 | $email['password'] = base64_encode($email['password']); |
| 118 | $ret = \Lib\Mail\MailFun::sendEmail([ | 121 | $ret = \Lib\Mail\MailFun::sendEmail([ |
| 119 | - 'subject' => 'Re:'.$data['subject'], | ||
| 120 | - 'tos' => [['email'=>$data['from'],'name'=>explode('@',$data['from'])[0]]], | ||
| 121 | - 'body' => $this->trimBody($data,$data['subject']), | 122 | + 'subject' => 'Re:' . $data['subject'], |
| 123 | + 'tos' => [['email' => $data['from'], 'name' => explode('@', $data['from'])[0]]], | ||
| 124 | + 'body' => $this->trimBody($data, $data['subject']), | ||
| 122 | 'mail-header' => [ | 125 | 'mail-header' => [ |
| 123 | - 'Aicc-Hot-Mail' => 'hot' // 预热邮件 | 126 | + 'Aicc-Hot-Mail' => 'hot' // 预热邮件 |
| 124 | ] | 127 | ] |
| 125 | - ],$email); | 128 | + ], $email); |
| 126 | 129 | ||
| 127 | - _echo(($ret[0]?'回复成功 ':'失败 ').$data['id']." ".$email['email'].' to '.$data['from']." ".$ret[1]); | ||
| 128 | - }else{ | ||
| 129 | - _echo('来回超过5次就不回了 '.$data['id']); | 130 | + _echo(($ret[0] ? '回复成功 ' : '失败 ') . $data['id'] . " " . $email['email'] . ' to ' . $data['from'] . " " . $ret[1]); |
| 131 | + } else { | ||
| 132 | + _echo('来回超过5次就不回了 ' . $data['id']); | ||
| 130 | } | 133 | } |
| 131 | } | 134 | } |
| 132 | } | 135 | } |
| 133 | 136 | ||
| 134 | } | 137 | } |
| 135 | 138 | ||
| 136 | - }else{ | 139 | + } else { |
| 137 | sleep(1); | 140 | sleep(1); |
| 138 | } | 141 | } |
| 139 | - }catch (Throwable $e){ | ||
| 140 | - logs($e->getMessage().$e->getFile().$e->getLine()); | 142 | + } catch (Throwable $e) { |
| 143 | + logs($e->getMessage() . $e->getFile() . $e->getLine()); | ||
| 141 | } | 144 | } |
| 142 | 145 | ||
| 143 | } | 146 | } |
| 144 | 147 | ||
| 145 | } | 148 | } |
| 146 | 149 | ||
| 147 | - public function trimBody($data,$inbox){ | ||
| 148 | - if(count($this->bodys) < 1000){ | ||
| 149 | - $temp = @json_decode(file_get_contents("http://oa.shopk.com/api/email_template?tag=预热邮件"),true); | ||
| 150 | - if(!empty($temp['data']['body'])){ | ||
| 151 | - $this->bodys[] = $temp['data']['body']??''; | 150 | + public function trimBody($data, $inbox) |
| 151 | + { | ||
| 152 | + if (count($this->bodys) < 1000) { | ||
| 153 | + $temp = @json_decode(file_get_contents("http://oa.shopk.com/api/email_template?tag=预热邮件"), true); | ||
| 154 | + if (!empty($temp['data']['body'])) { | ||
| 155 | + $this->bodys[] = $temp['data']['body'] ?? ''; | ||
| 152 | } | 156 | } |
| 153 | } | 157 | } |
| 154 | 158 | ||
| 155 | $reply = $this->bodys[array_rand($this->bodys)]; | 159 | $reply = $this->bodys[array_rand($this->bodys)]; |
| 156 | 160 | ||
| 157 | - return $reply."<pre style='background-color: #e8d6d6;'>------------------ original message ------------------ | 161 | + return $reply . "<pre style='background-color: #e8d6d6;'>------------------ original message ------------------ |
| 158 | from: {$data['from']}; | 162 | from: {$data['from']}; |
| 159 | -send time: " .date("Y年m月d日 H:i",$data['udate'])." | 163 | +send time: " . date("Y年m月d日 H:i", $data['udate']) . " |
| 160 | to: {$data['to']}; | 164 | to: {$data['to']}; |
| 161 | subject: {$data['subject']} | 165 | subject: {$data['subject']} |
| 162 | 166 | ||
| @@ -164,8 +168,6 @@ subject: {$data['subject']} | @@ -164,8 +168,6 @@ subject: {$data['subject']} | ||
| 164 | } | 168 | } |
| 165 | 169 | ||
| 166 | 170 | ||
| 167 | - | ||
| 168 | - | ||
| 169 | } | 171 | } |
| 170 | 172 | ||
| 171 | (new fob_hot_ai_mail_auto_reply())->handler(); | 173 | (new fob_hot_ai_mail_auto_reply())->handler(); |
-
请 注册 或 登录 后发表评论