作者 邓超

国内项目不回复

... ... @@ -13,7 +13,8 @@ require_once "../vendor/autoload.php";
* @time 2025/7/2 9:58
* Class fob_ai_mail_auto_reply
*/
class fob_hot_ai_mail_auto_reply {
class fob_hot_ai_mail_auto_reply
{
public $isStop = false;
... ... @@ -34,8 +35,8 @@ class fob_hot_ai_mail_auto_reply {
{
$this->db = db();
$handler = function ($signal){
_echo('收到进程信号 '. $signal);
$handler = function ($signal) {
_echo('收到进程信号 ' . $signal);
// 可以处理其他程序
$this->isStop = true;
};
... ... @@ -55,7 +56,7 @@ class fob_hot_ai_mail_auto_reply {
pcntl_signal_dispatch();
// 是否超过来最大执行时间
if(time()-43200 > $this->startTime){
if (time() - 43200 > $this->startTime) {
return true;
}
... ... @@ -64,18 +65,19 @@ class fob_hot_ai_mail_auto_reply {
protected $bodys = [];
public function handler(){
public function handler()
{
// $this->bodys = file_get_contents(__DIR__."/body.reply");
// $this->bodys = explode("--------------",$this->bodys);
while (!$this->isStop()){
while (!$this->isStop()) {
try {
$id = redis()->lPop('new_hot_mail_auto_reply_ids');
if($id){
if ($id) {
// 检查是否到时间了
list($did,$time) = explode('.',((string) $id).'.0');
list($did, $time) = explode('.', ((string)$id) . '.0');
// $h = (int) date('H');
// if($h >= 23 || $h < 6 ){
... ... @@ -84,79 +86,81 @@ class fob_hot_ai_mail_auto_reply {
// }
// 查询数据
$data = $this->db->first(\Model\listsSql::first('`id` = '.$did,'`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`'));
if($data && $data['is_hots']){
$data = $this->db->first(\Model\listsSql::first('`id` = ' . $did, '`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`'));
if ($data && $data['is_hots']) {
// 在检查下是否是 收件箱
if($this->db->cache(3600)->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){
_echo('处理 '.$data['id']. " run " .date("Y-m-d H:i:s",$data['udate']));
if ($this->db->cache(3600)->value(\Model\folderSql::has(['id' => $data['folder_id'], 'origin_folder' => 'INBOX']))) {
_echo('处理 ' . $data['id'] . " run " . date("Y-m-d H:i:s", $data['udate']));
$email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id']));
// 验证是否是ai邮箱
if($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'",$email['email']))){
if ($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'", $email['email']))) {
// 验证邮箱状态
// $fobemail = fob_mysql()->cache(300)->first("select `status`,`is_send_mail`,`is_web_send` from `e_mail_binds` where `email_id` = ".$data['email_id']);
// // 状态异常的跳过
// if(!$fobemail || $fobemail['status']!=1||!$fobemail['is_send_mail']){
// continue;
// }
$post_id = fob_mysql()->cache(3600)->value("select `post_id` from `e_mail_binds` where `email_id` = " . $data['email_id']);
// // 国内项目不回复
if ($post_id == 10001746) {
_echo('国内项目跳过');
continue;
}
// 标记已读
$email['password'] = base64_decode($email['password']);
$email['host'] = $email['imap'];
$mailInstance = new Imap(new \Lib\Imap\ImapConfig($email));
if($mailInstance->login()){
if ($mailInstance->login()) {
$mailInstance->folder('INBOX')->msg()->uid($data['uid'])->seen();
$mailInstance = null;
}
// 来回超过5次就不回了
if(substr_count($data['subject'],"Re:") < 1 ){
if (substr_count($data['subject'], "Re:") < 1) {
// 有配置才回复
$email['hot_email'] = 1;
$email['password'] = base64_encode($email['password']);
$ret = \Lib\Mail\MailFun::sendEmail([
'subject' => 'Re:'.$data['subject'],
'tos' => [['email'=>$data['from'],'name'=>explode('@',$data['from'])[0]]],
'body' => $this->trimBody($data,$data['subject']),
'subject' => 'Re:' . $data['subject'],
'tos' => [['email' => $data['from'], 'name' => explode('@', $data['from'])[0]]],
'body' => $this->trimBody($data, $data['subject']),
'mail-header' => [
'Aicc-Hot-Mail' => 'hot' // 预热邮件
'Aicc-Hot-Mail' => 'hot' // 预热邮件
]
],$email);
], $email);
_echo(($ret[0]?'回复成功 ':'失败 ').$data['id']." ".$email['email'].' to '.$data['from']." ".$ret[1]);
}else{
_echo('来回超过5次就不回了 '.$data['id']);
_echo(($ret[0] ? '回复成功 ' : '失败 ') . $data['id'] . " " . $email['email'] . ' to ' . $data['from'] . " " . $ret[1]);
} else {
_echo('来回超过5次就不回了 ' . $data['id']);
}
}
}
}
}else{
} else {
sleep(1);
}
}catch (Throwable $e){
logs($e->getMessage().$e->getFile().$e->getLine());
} catch (Throwable $e) {
logs($e->getMessage() . $e->getFile() . $e->getLine());
}
}
}
public function trimBody($data,$inbox){
if(count($this->bodys) < 1000){
$temp = @json_decode(file_get_contents("http://oa.shopk.com/api/email_template?tag=预热邮件"),true);
if(!empty($temp['data']['body'])){
$this->bodys[] = $temp['data']['body']??'';
public function trimBody($data, $inbox)
{
if (count($this->bodys) < 1000) {
$temp = @json_decode(file_get_contents("http://oa.shopk.com/api/email_template?tag=预热邮件"), true);
if (!empty($temp['data']['body'])) {
$this->bodys[] = $temp['data']['body'] ?? '';
}
}
$reply = $this->bodys[array_rand($this->bodys)];
return $reply."<pre style='background-color: #e8d6d6;'>------------------ original message ------------------
return $reply . "<pre style='background-color: #e8d6d6;'>------------------ original message ------------------
from: {$data['from']};
send time: " .date("Ymd H:i",$data['udate'])."
send time: " . date("Ymd H:i", $data['udate']) . "
to: {$data['to']};
subject: {$data['subject']}
... ... @@ -164,8 +168,6 @@ subject: {$data['subject']}
}
}
(new fob_hot_ai_mail_auto_reply())->handler();
... ...