作者 邓超

proxy

... ... @@ -7,6 +7,7 @@ use Lib\Imap\ImapPool;
use Lib\Mail\MailFun;
use Lib\Verify;
use Model\emailSql;
use Service\MailProxy;
use Service\SyncMail;
... ... @@ -46,76 +47,14 @@ class Login {
app()->e('smtp_verify_error');
}
// 是否是shopk那边已添加的邮箱,进行代理
$status = file_get_contents('https://oa.shopk.com/fob-check-email/'.$formData['email']);
// 存在 就把服务器替换为代理服务器
if($status=='exist'){
/**
* 代理功能 去shopk检查邮件是否被添加到shopk了。
* 如果添加到shopk了就把请求地址替换成shopk的服务器地址
* 由shopk代理
* 避免出现换ip登录的情况而被封号
*/
$callHost = function (string $host,int $prot){
$host = parse_url($host);
if(empty($host['host'])){
$host = $host['path'].':'.$prot;
}else{
$host = $host['host'].':'.(empty($host['port'])?$prot:$host['port']);
}
return $host;
};
$formData['imap'] = $callHost($formData['imap'],993);
$formData['smtp'] = $callHost($formData['smtp'],465);
// 服务器代理到shopk服务器上面
// 新增代理 域名 必须要在 43.154.117.107服务器的nginx添加对应的配置,一个域名一个端口为一个配置
// 配置在 /www/server/panel/vhost/nginx/tcp/ 目录
$proxy = [
'imap.gmail.com:993' => '43.154.117.107:10086',
'smtp.gmail.com:465' => '43.154.117.107:10087',
'imap-mail.outlook.com:993' => '43.154.117.107:10088',
'smtp-mail.outlook.com:465' => '43.154.117.107:10089',
// 'outlook.office365.com:993' => '43.154.117.107:10098',
// 'imap.aol.com:993' => '43.154.117.107:10090',
// 'smtp.aol.com:465' => '43.154.117.107:10091',
'imap.mail.yahoo.com:993' => '43.154.117.107:10092',
'smtp.mail.yahoo.com:465' => '43.154.117.107:10093',
'imap.qiye.aliyun.com:993' => '43.154.117.107:10094',
'smtp.qiye.aliyun.com:465' => '43.154.117.107:10095',
// 'imap.rambler.ru:993' => '43.154.117.107:10096',
// 'smtp.rambler.ru:465' => '43.154.117.107:10097',
'imaphz.qiye.163.com:993' => '43.154.117.107:10080',
'smtphz.qiye.163.com:465' => '43.154.117.107:10081',
];
// 是否存在代理
if(empty($proxy[$formData['imap']]) || empty($proxy[$formData['smtp']]) ){
app()->e('请联系站点管理员添加代理');
}
// 替换为代理服务器
$formData['imap'] = $proxy[$formData['imap']];
$formData['smtp'] = $proxy[$formData['smtp']];
}
$proxy = (new MailProxy($formData['email'],$formData['imap'],$formData['smtp']));
$mailClient = ImapPool::get(
(new ImapConfig())
->setPassword($formData['password'])
->setHost($formData['imap'])
->setHost($proxy->getImapProxy())
->setEmail($formData['email'])
);
// 进行远程登录,验证
// $mailClient = (new Mail($formData['email'],$formData['password'],$formData['imap']));
$login = $mailClient->login();
if(!$login->isOk()){
... ... @@ -125,7 +64,7 @@ class Login {
// 验证smtp登录
if(!MailFun::smtpLoginTest($formData['smtp'],$formData['email'],$formData['password'])){
if(!MailFun::smtpLoginTest($proxy->getSmtpProxy(),$formData['email'],$formData['password'])){
app()->e('email_smtp_server_error');
}
... ... @@ -135,11 +74,12 @@ class Login {
$data = [
'password' => base64_encode($formData['password']),
'imap' => $formData['imap'],
'smtp' => $formData['smtp'],
'imap' => $proxy->getImapProxy(),
'smtp' => $proxy->getSmtpProxy(),
'status' => 1,
'pwd_error' => 0
];
$proxy->proxySuccess();// 标记代理成功
if($id){
// 修改
... ...
... ... @@ -51,8 +51,8 @@ class MailProxy {
'imap.qiye.aliyun.com:993' => '10094',
'smtp.qiye.aliyun.com:465' => '10095',
'imap.qq.com:993' => '10096',
'smtp.qq.com:465' => '10097',
// 'imap.qq.com:993' => '10096',
// 'smtp.qq.com:465' => '10097',
];
... ...