作者 邓超

增加代理

... ... @@ -529,6 +529,7 @@ class Home extends Base {
}
else{
// 立即发送
$email['hot_email'] = db()->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$email['email']]));
$result = MailFun::sendEmail($sendData,$email);
if($result[0]){
app()->_json(['messageId' => $result[1]]);
... ...
... ... @@ -281,8 +281,9 @@ class MailFun {
return [true,$mail->getLastMessageID()];
}
}else{
// ai邮箱才使用代理
if(!empty($email['hot_email'])){
$mail->Port = 9527;
$mail->send_proxy_host = implode(':',$smtp);
foreach (MailProxy::getProxy() as $ip){
... ... @@ -291,14 +292,13 @@ class MailFun {
if($mail->send()){
return [true,$mail->getLastMessageID()];
}
}
// 以上全部失败了,再次发送
// 以上全部失败了,再次 本服务器发送
$mail->Port = $smtp['port'];
$mail->send_proxy_host = '';
$mail->Host = $smtp['host'];
$mail->send_proxy_host = '';
}
// 发送成功直接返回
if($mail->send()){
... ...
... ... @@ -2233,9 +2233,10 @@ class PHPMailer
if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
// 是否是代理 如果是代理就需要发送代理认证
if($this->send_proxy_host){
$this->smtp->proxy_server = true;
// 代理操作
$r =rand(1,9999);
$this->smtp->client_send('tag1 '.md5('fob.'.$r).' '.$r.' 0 '.$this->send_proxy_host.' 30');
$this->smtp->client_send('tag1 '.md5('fob.'.$r).' '.$r.' 0 '.$this->send_proxy_host." ".$this->Timeout."\r\n");
$this->edebug($this->smtp->get_lines());
}
... ...
... ... @@ -59,6 +59,12 @@ class SMTP
const DEFAULT_SECURE_PORT = 465;
/**
* 是否是代理服务器 是代理服务器 就要特殊处理
* @var bool
*/
public $proxy_server = false;
/**
* The maximum line length allowed by RFC 5321 section 4.5.3.1.6,
* *excluding* a trailing CRLF break.
*
... ... @@ -806,6 +812,9 @@ class SMTP
foreach ($allDataLines as $allDataLine){
$this->client_send($allDataLine, 'DATA');
if($this->proxy_server){
$this->edebug($this->get_lines());
}
}
//Message data has been sent, complete the command
... ...
... ... @@ -29,10 +29,10 @@ class SmtpClient{
* @author:dc
* @time 2025/3/31 10:27
*/
public function open(string $out_ip, int $timeout=3){
public function open(string $out_ip, int $timeout=5){
$client = new \Swoole\Coroutine\Client(SWOOLE_SOCK_TCP | SWOOLE_SSL);
$client->set([
// 'timeout'=> $timeout,
'timeout'=> $timeout,
'ssl_verify_peer' => false,// 关闭证书验证
// 'bind_address' => $out_ip,
// 'bind_port' => 36002,
... ... @@ -44,8 +44,11 @@ class SmtpClient{
throw new Exception($this->host." connection fail. ".$client->errMsg);
}
if($client->isConnected()){
$this->client = $client;
}else{
throw new Exception($this->host." connection fail. ");
}
}
/**
... ... @@ -74,16 +77,17 @@ class SmtpClient{
* @author:dc
* @time 2024/9/13 15:49
*/
public function readLine(){
public function readLine($timeout=5){
if($this->is_read === 2){
return false;
return '220 DATA OK';
}
if($this->is_read === 1){
$this->is_read = 2;
}
return $this->client->recv();
$online = $this->client->recv($timeout);
return $online===false ? '500 read time out.' : $online;
}
... ...
... ... @@ -14,10 +14,9 @@ class ProxyService
protected static $clients = [];
protected function push(...$params){
echo co::getCid()." => ";
echo implode(' => ',$params);
return $params;
protected function push($msg){
echo 'out '.$msg;
return $msg;
}
/**
... ... @@ -35,19 +34,19 @@ class ProxyService
//监听连接进入事件。
$server->on('Connect', function ($server, $fd) {
$server->send($fd, "220 proxy client ok\r\n");
$server->send($fd, $this->push("220 proxy client ok\r\n"));
});
//监听数据接收事件。
$server->on('Receive', function ($server, $fd, $reactor_id, $data) {
// echo "in ".co::getCid()." ==> ".$data."\n";
echo "in > ".$data;
// 建立连接
if (empty(self::$clients[$fd])) {
try {
$auth = new Auth($data);
}catch (Throwable $e){
$server->send($fd, $e->getMessage());
$server->send($fd, $this->push($e->getMessage()));
$server->close($fd,true);
return;
}
... ... @@ -57,23 +56,20 @@ class ProxyService
try {
self::$clients[$fd]->open($auth->out_ip, $auth->timeOut);
}catch (Throwable $e){
$server->send($fd, '500 ' . $e->getMessage()."\r\n");
$server->send($fd,$this->push('500 ' . $e->getMessage()."\r\n"));
$server->close($fd,true);
return;
}
$line = self::$clients[$fd]->readLine();
$line = self::$clients[$fd]->readLine(1);
if($line) $server->send($fd,$line);
// 发送成功消息
// $server->send($fd, "200 OK The proxy server is successfully connected.\r\n");
$server->send($fd,$this->push($line));
} // 正式请求转发
else {
// 没有连接成功
if(empty(self::$clients[$fd])){
$server->send($fd, "500 No proxy server.\r\n");
$server->send($fd, $this->push("500 No proxy server.\r\n"));
$server->close($fd,true);
return;
}
... ... @@ -86,12 +82,12 @@ class ProxyService
if($num) $line = self::$clients[$fd]->readLine();
}catch (Throwable $e){
echo date('Y-m-d H:i:s').' 协程读取异常 ' .$data." ::".$e->getMessage()."\n";
$line = '500 server error '.$e->getMessage()."\r\n";
}
// echo 'out '.co::getCid()." => ".$line;
if($line!==false) $server->send($fd,$line);
if($line!==false) $server->send($fd,$this->push($line));
}
});
... ...
... ... @@ -46,15 +46,24 @@ class MailProxy {
* @var string[]
*/
public static $proxyService = [
'43.134.162.250', // 这个是新加坡服务器 代理
'119.28.113.113', // 这个是新加坡服务器 代理02
'43.163.110.196', // 这个是新加坡服务器 代理02
'43.134.162.250', // 这个是新加坡服务器 代理
'43.154.117.107', // 这个是 shopk的那台服务器
];
/**
* 这些ip 不被分配 这些ip信誉低
* @var array
*/
public static $noip = [
'43.134.162.250', // 这个是新加坡服务器 代理
'43.154.117.107', // 这个是 shopk的那台服务器
];
/**
* 读取代理ip 随机打乱
... ... @@ -65,7 +74,7 @@ class MailProxy {
public static function getProxy(){
$host = self::$proxyService;
foreach ($host as $k => $v){
if($v =='43.154.117.107'){
if(in_array($v,self::$noip)){
unset($host[$k]);
}
}
... ... @@ -254,7 +263,7 @@ class MailProxy {
$t = date('Y-m-d H:i:s',strtotime("-30 day"));
foreach ($this::$proxyService as $ip){
// shopk的不分配
if($ip=='43.154.117.107'){
if(in_array($ip,self::$noip)){
continue;
}
$num = db()->count("select count(*) from `mail_proxy` where `status` = 1 and `ip` = '{$ip}'");
... ...