作者 邓超

优化

... ... @@ -63,36 +63,10 @@ class fob_hot_ai_mail_auto_reply {
protected $bodys = [];
public function getDelayTime(){
/**
* 随机一个延时时间秒 极小的概率30-60分钟,小概率60-120分钟,中概率120-180分钟 大概率180-240分钟
*/
// 生成一个 0 到 100 之间的随机数
$randomValue = rand(0, 100);
// 根据随机值的范围来决定延迟时间
if ($randomValue < 5) { // 5% 的概率
// 随机 30-60分钟
$rand = rand(45, 60) * 60; // 转换为秒
} elseif ($randomValue < 15) { // 10% 的概率 (5% + 10%)
// 随机 60-120分钟
$rand = rand(65, 120) * 60; // 转换为秒
} elseif ($randomValue < 45) { // 30% 的概率 (15% + 30%)
// 随机 120-180分钟
$rand = rand(125, 180) * 60; // 转换为秒
} else { // 55% 的概率 (45% + 55%)
// 随机 180-240分钟
$rand = rand(180, 240) * 60; // 转换为秒
}
return time()+$rand;
}
public function handler(){
$this->bodys = file_get_contents(__DIR__."/body.reply");
$this->bodys = explode("--------------",$this->bodys);
// $this->bodys = file_get_contents(__DIR__."/body.reply");
// $this->bodys = explode("--------------",$this->bodys);
while (!$this->isStop()){
... ... @@ -100,10 +74,6 @@ class fob_hot_ai_mail_auto_reply {
if($id){
// 检查是否到时间了
list($did,$time) = explode('.',((string) $id).'.0');
if($time == '0'){
redis()->rPush('new_hot_mail_auto_reply_ids',$id.'.'.$this->getDelayTime());
continue;
}
$h = (int) date('H');
if($h >= 23 || $h < 6 ){
... ... @@ -111,13 +81,6 @@ class fob_hot_ai_mail_auto_reply {
continue;
}
if($time > time()){
redis()->rPush('new_hot_mail_auto_reply_ids',$id);
usleep(10000);
// echo $did." ".date("Y-m-d H:i:s",$time)." 时间未到 \n";
continue;
}
// 查询数据
$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']){
... ... @@ -130,7 +93,7 @@ class fob_hot_ai_mail_auto_reply {
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` from `e_mail_binds` where `email_id` = ".$data['email_id']);
$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;
... ... @@ -146,7 +109,7 @@ class fob_hot_ai_mail_auto_reply {
}
// 来回超过5次就不回了
if(substr_count($data['subject'],"Re:") < 2){
if(substr_count($data['subject'],"Re:") < 1 ){
// 有配置才回复
$email['hot_email'] = 1;
$email['password'] = base64_encode($email['password']);
... ... @@ -176,18 +139,14 @@ class fob_hot_ai_mail_auto_reply {
}
public function trimBody($data,$inbox){
// 随机body内容
$reply = $this->bodys[array_rand($this->bodys)];
if(rand(1,2)==1){
$reply = "<pre>".$reply."</pre>";
}else{
$reply = array_map(function ($v){
return "<p>".$v."</p>";
},explode("\n",$reply));
$reply = implode("\n",$reply);
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 ------------------
from: {$data['from']};
... ...