作者 邓超

proxy

@@ -7,6 +7,7 @@ use Lib\Imap\ImapPool; @@ -7,6 +7,7 @@ use Lib\Imap\ImapPool;
7 use Lib\Mail\MailFun; 7 use Lib\Mail\MailFun;
8 use Lib\Verify; 8 use Lib\Verify;
9 use Model\emailSql; 9 use Model\emailSql;
  10 +use Service\MailProxy;
10 use Service\SyncMail; 11 use Service\SyncMail;
11 12
12 13
@@ -46,76 +47,14 @@ class Login { @@ -46,76 +47,14 @@ class Login {
46 app()->e('smtp_verify_error'); 47 app()->e('smtp_verify_error');
47 } 48 }
48 49
49 - // 是否是shopk那边已添加的邮箱,进行代理  
50 - $status = file_get_contents('https://oa.shopk.com/fob-check-email/'.$formData['email']);  
51 - // 存在 就把服务器替换为代理服务器  
52 - if($status=='exist'){  
53 - /**  
54 - * 代理功能 去shopk检查邮件是否被添加到shopk了。  
55 - * 如果添加到shopk了就把请求地址替换成shopk的服务器地址  
56 - * 由shopk代理  
57 - * 避免出现换ip登录的情况而被封号  
58 - */  
59 - $callHost = function (string $host,int $prot){  
60 - $host = parse_url($host);  
61 - if(empty($host['host'])){  
62 - $host = $host['path'].':'.$prot;  
63 - }else{  
64 - $host = $host['host'].':'.(empty($host['port'])?$prot:$host['port']);  
65 - }  
66 - return $host;  
67 - };  
68 -  
69 - $formData['imap'] = $callHost($formData['imap'],993);  
70 - $formData['smtp'] = $callHost($formData['smtp'],465);  
71 - // 服务器代理到shopk服务器上面  
72 - // 新增代理 域名 必须要在 43.154.117.107服务器的nginx添加对应的配置,一个域名一个端口为一个配置  
73 - // 配置在 /www/server/panel/vhost/nginx/tcp/ 目录  
74 - $proxy = [  
75 - 'imap.gmail.com:993' => '43.154.117.107:10086',  
76 - 'smtp.gmail.com:465' => '43.154.117.107:10087',  
77 -  
78 - 'imap-mail.outlook.com:993' => '43.154.117.107:10088',  
79 - 'smtp-mail.outlook.com:465' => '43.154.117.107:10089',  
80 -// 'outlook.office365.com:993' => '43.154.117.107:10098',  
81 -  
82 -// 'imap.aol.com:993' => '43.154.117.107:10090',  
83 -// 'smtp.aol.com:465' => '43.154.117.107:10091',  
84 -  
85 - 'imap.mail.yahoo.com:993' => '43.154.117.107:10092',  
86 - 'smtp.mail.yahoo.com:465' => '43.154.117.107:10093',  
87 -  
88 - 'imap.qiye.aliyun.com:993' => '43.154.117.107:10094',  
89 - 'smtp.qiye.aliyun.com:465' => '43.154.117.107:10095',  
90 -  
91 -// 'imap.rambler.ru:993' => '43.154.117.107:10096',  
92 -// 'smtp.rambler.ru:465' => '43.154.117.107:10097',  
93 -  
94 - 'imaphz.qiye.163.com:993' => '43.154.117.107:10080',  
95 - 'smtphz.qiye.163.com:465' => '43.154.117.107:10081',  
96 -  
97 -  
98 - ];  
99 - // 是否存在代理  
100 - if(empty($proxy[$formData['imap']]) || empty($proxy[$formData['smtp']]) ){  
101 - app()->e('请联系站点管理员添加代理');  
102 - }  
103 - // 替换为代理服务器  
104 - $formData['imap'] = $proxy[$formData['imap']];  
105 - $formData['smtp'] = $proxy[$formData['smtp']];  
106 -  
107 - }  
108 - 50 + $proxy = (new MailProxy($formData['email'],$formData['imap'],$formData['smtp']));
109 51
110 $mailClient = ImapPool::get( 52 $mailClient = ImapPool::get(
111 (new ImapConfig()) 53 (new ImapConfig())
112 ->setPassword($formData['password']) 54 ->setPassword($formData['password'])
113 - ->setHost($formData['imap']) 55 + ->setHost($proxy->getImapProxy())
114 ->setEmail($formData['email']) 56 ->setEmail($formData['email'])
115 ); 57 );
116 - // 进行远程登录,验证  
117 -// $mailClient = (new Mail($formData['email'],$formData['password'],$formData['imap']));  
118 -  
119 58
120 $login = $mailClient->login(); 59 $login = $mailClient->login();
121 if(!$login->isOk()){ 60 if(!$login->isOk()){
@@ -125,7 +64,7 @@ class Login { @@ -125,7 +64,7 @@ class Login {
125 64
126 65
127 // 验证smtp登录 66 // 验证smtp登录
128 - if(!MailFun::smtpLoginTest($formData['smtp'],$formData['email'],$formData['password'])){ 67 + if(!MailFun::smtpLoginTest($proxy->getSmtpProxy(),$formData['email'],$formData['password'])){
129 app()->e('email_smtp_server_error'); 68 app()->e('email_smtp_server_error');
130 } 69 }
131 70
@@ -135,11 +74,12 @@ class Login { @@ -135,11 +74,12 @@ class Login {
135 74
136 $data = [ 75 $data = [
137 'password' => base64_encode($formData['password']), 76 'password' => base64_encode($formData['password']),
138 - 'imap' => $formData['imap'],  
139 - 'smtp' => $formData['smtp'], 77 + 'imap' => $proxy->getImapProxy(),
  78 + 'smtp' => $proxy->getSmtpProxy(),
140 'status' => 1, 79 'status' => 1,
141 'pwd_error' => 0 80 'pwd_error' => 0
142 ]; 81 ];
  82 + $proxy->proxySuccess();// 标记代理成功
143 83
144 if($id){ 84 if($id){
145 // 修改 85 // 修改
@@ -51,8 +51,8 @@ class MailProxy { @@ -51,8 +51,8 @@ class MailProxy {
51 'imap.qiye.aliyun.com:993' => '10094', 51 'imap.qiye.aliyun.com:993' => '10094',
52 'smtp.qiye.aliyun.com:465' => '10095', 52 'smtp.qiye.aliyun.com:465' => '10095',
53 53
54 - 'imap.qq.com:993' => '10096',  
55 - 'smtp.qq.com:465' => '10097', 54 +// 'imap.qq.com:993' => '10096',
  55 +// 'smtp.qq.com:465' => '10097',
56 56
57 ]; 57 ];
58 58