Commit 3857bfe4 authored by 郝聪敏's avatar 郝聪敏

采用阿里云方案

parent a881f582
This diff is collapsed.
...@@ -2,13 +2,6 @@ ...@@ -2,13 +2,6 @@
const mailer = require('nodemailer-promise'); const mailer = require('nodemailer-promise');
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const account = 'xyqb@liangkebang.net';
const password = 'Ztg202020';
const cookiePath = '../public/data/ali-cookies.json';
const userInfo = `vn1sahsubs@163.com----anncprv const userInfo = `vn1sahsubs@163.com----anncprv
hwm32fxuix@163.com----qfagkir hwm32fxuix@163.com----qfagkir
...@@ -411,142 +404,43 @@ y3umsz985@163.com----u4dry5lm2 ...@@ -411,142 +404,43 @@ y3umsz985@163.com----u4dry5lm2
mo3q4qv6@163.com----va7ijir50 mo3q4qv6@163.com----va7ijir50
tsr8sfk0@163.com----bncs9hs6`.split(/[\s\n]/).map(v => ({ receiver: v.split('----')[0] })); tsr8sfk0@163.com----bncs9hs6`.split(/[\s\n]/).map(v => ({ receiver: v.split('----')[0] }));
// const transporter = nodemailer.createTransport({ const mails = [
// host: 'smtp.mxhichina.com', { receiver: 'pfe1xtbc1g@163.com' },
// port: 465, { receiver: 'caokaoqiao1@126.com' },
// secure: true, // use SSL { receiver: 'tsr8sfk0@163.com' },
// auth: { { receiver: 'np7sdr7@163.com' },
// user: 'xyqb@liangkebang.net', { receiver: 'yangshixia07@126.com' },
// pass: 'Ztg202020', // 这是邮箱的授权码不是登录密码。 安全登录的客户端专用密码: { receiver: 'v6j0g14tv@163.com' },
// }, { receiver: 'ruantui5117@126.com' },
// }); ];
const sendEmail = mailer.config({
host: 'smtp.mxhichina.com',
port: 465,
secure: true, // use SSL
auth: {
user: 'xyqb@liangkebang.net',
pass: 'Ztg202020', // 这是邮箱的授权码不是登录密码。 安全登录的客户端专用密码:
},
});
const browserConfig = {
headless: false,
defaultViewport: {
width: 1024,
height: 768,
},
};
const addCookies = async (cookies, page) => {
for (let j = 0; j < cookies.length; j++) {
await page.setCookie(cookies[j]);
}
};
const getBase64Image = async (page, selector) => {
return page.evaluate(selector => {
console.log(this, this.selector);
const img = document.querySelector(selector);
const element = document.createElement('canvas');
element.width = img.width;
element.height = img.height;
const ctx = element.getContext('2d');
ctx.drawImage(img, 0, 0, img.width, img.height);
const dataURL = element.toDataURL('image/png');
return dataURL.replace('data:image/png;base64,', '');
}, selector);
};
const getCode = async (ctx, page, selector) => {
const base64Img = await getBase64Image(page, selector);
return ctx.service.home.getCode(base64Img);
};
const writeLoginCode = async (page, ctx) => {
const code = await getCode(ctx, page, '#login_checkcode_ico');
if (!code || code.length !== 4) {
await page.click('#login_checkcode_ico');
await page.waitFor(3000);
return writeLoginCode(page, ctx);
}
ctx.logger.info(`aliyun mail: 获取到的验证码是${code}`);
await page.$eval('#username', input => { input.value = ''; });
await page.type('#username', account);
await page.type('#login_checkcode', code);
await page.type('#password', password);
await page.waitFor(3000);
await page.click('#login_submit_btn');
};
const wait = async seconds => new Promise(resolve => { setTimeout(resolve, seconds); });
class mailController extends Controller { class mailController extends Controller {
async index() { async index() {
const { ctx } = this; const { ctx, service } = this;
for (let i = 362; i < userInfo.length; i++) { let sendRealEmail = [];
const sendEmail = mailer.config(ctx.app.config.smtp);
try {
for (let i = 0; i < 400; i++) {
const message = { const message = {
from: 'xyqb@liangkebang.net', from: 'xyqb3@liangkebang.net',
to: userInfo[i].receiver, to: userInfo[i].receiver,
subject: '债权转让通知<公司内测>', subject: '债权转让通知<公司内测>',
text: `${Date.now()} 先生/女士, 您通过“信用钱包”签订的编号为“${Date.now()}”的《借款合同》(下称“合同”),因您逾期未还,我司已将合同项下债权依法转让给耒阳市润裕资产经营管理有限公司,根据我司与耒阳市润裕资产经营管理有限公司签订的《债权转让协议》,您应自收到本债转通知之日起向耒阳市润裕资产经营管理有限公司履行还款义务。`, text: `${Date.now()} 先生/女士, 您通过“信用钱包”签订的编号为“${Date.now()}”的《借款合同》(下称“合同”),因您逾期未还,我司已将合同项下债权依法转让给耒阳市润裕资产经营管理有限公司,根据我司与耒阳市润裕资产经营管理有限公司签订的《债权转让协议》,您应自收到本债转通知之日起向耒阳市润裕资产经营管理有限公司履行还款义务。`,
}; };
await sendEmail(message); await sendEmail(message);
ctx.logger.warn(`aliyun mail: 成功发送第${i + 1}封邮件`); ctx.logger.warn(`aliyun mail: 成功发送第${i + 1}封邮件 mail: ${userInfo[i].receiver}`);
// await wait(parseInt((Math.random() * 10 + 5) * 1000, 10)); await ctx.helper.wait(parseInt((Math.random() * 5 + 5) * 1000, 10));
} }
ctx.body = 'hi'; } catch (e) {
console.log('发送邮件异常', e || e.message);
} }
async getImage() { sendRealEmail = await service.mail.getImage(mails);
const { ctx } = this;
let cookie = fs.readFileSync(path.join(__dirname, cookiePath)).toString();
const browser = await puppeteer.launch(browserConfig);
const page = await browser.newPage();
if (cookie) await addCookies(JSON.parse(cookie), page);
ctx.logger.info('aliyun mail: 进入https://qiye.aliyun.com');
await page.goto('https://qiye.aliyun.com', { waitUntil: 'networkidle2' });
const loginPanelIframe = await page.$('.login_panel_iframe');
if (loginPanelIframe) {
const src = await page.$eval('.login_panel_iframe', el => el.src);
await page.goto(src);
const dingLoginFrame = await page.frames().find(f => f.name() === 'ding-login-iframe');
await dingLoginFrame.$eval('#username', input => { input.value = ''; });
await dingLoginFrame.type('#username', account);
await dingLoginFrame.type('#password', password);
await dingLoginFrame.click('#login_remember_check');
await dingLoginFrame.click('#login_submit_btn');
await page.waitFor(2500); if (sendRealEmail.length) {
let loginErrorLine = await dingLoginFrame.$('#login_checkcode_ico'); console.log('应该调接口改变状态了');
if (loginErrorLine) { console.log(sendRealEmail);
ctx.logger.warn('aliyun mail: 登录需要输入验证码!');
let j = 0;
while (loginErrorLine && j < 20) {
j++;
ctx.logger.warn(`aliyun mail: 第${j}次输入验证码!`);
await writeLoginCode(dingLoginFrame, ctx);
await page.waitFor(5000);
console.log(dingLoginFrame);
loginErrorLine = await page.$('.login_panel_iframe');
}
if (j === 20) throw new Error('验证码尝试过多');
}
cookie = await page.cookies('https://qiye.aliyun.com');
fs.writeFileSync(path.join(__dirname, cookiePath), JSON.stringify(cookie));
} }
ctx.logger.info('aliyun mail: 已登录');
// await page.waitFor('#sqm_126');
// await page.click('span[title="已发送"]');
await page.click('.e_textbox_input_wrap');
await page.click('.header_search_advanced');
await page.type('.criteria_receiver .e_entry_input', 'd1ajap1@163.com');
await page.click('.e_d_button_wrap .e_b');
await page.waitFor(100000);
} }
} }
......
/* global document */
'use strict';
module.exports = {
async addCookies(cookies, page) {
for (let j = 0; j < cookies.length; j++) {
await page.setCookie(cookies[j]);
}
},
async getCode(page, selector) {
const base64Img = await this.getBase64Image(page, selector);
return this.ctx.service.ocr.getCode(base64Img);
},
async writeLoginCode(page) {
const code = await this.getCode(page, '#login_checkcode_ico');
if (!code || code.length !== 4) {
await page.click('#login_checkcode_ico');
await page.waitFor(3000);
return this.writeLoginCode(page, this.ctx);
}
this.ctx.logger.info(`aliyun mail: 获取到的验证码是${code}`);
await page.$eval('#username', input => { input.value = ''; });
await page.type('#username', this.ctx.app.config.aliyun[0].account);
await page.type('#login_checkcode', code);
await page.type('#password', this.ctx.app.config.aliyun[0].password);
await page.waitFor(3000);
await page.click('#login_submit_btn');
},
async writeTecentLoginCode(page) {
const code = await this.getCode(page, '#vfcode');
if (!code) {
await page.click('#vfcode');
await page.waitFor(3000);
return this.writeTecentLoginCode(page);
}
this.ctx.logger.info(`tecent mail: 获取到的验证码是${code}`);
await page.type('#vc', code);
await page.click('#auto_login_in_five_days_pwd');
await page.click('#btlogin');
},
async getBase64Image(page, selector) {
return page.evaluate(selector => {
const img = document.querySelector(selector);
const element = document.createElement('canvas');
element.width = img.width;
element.height = img.height;
const ctx = element.getContext('2d');
ctx.drawImage(img, 0, 0, img.width, img.height);
const dataURL = element.toDataURL('image/png');
return dataURL.replace('data:image/png;base64,', '');
}, selector);
},
async wait(seconds) {
return new Promise(resolve => { setTimeout(resolve, seconds); });
},
};
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
module.exports = () => { module.exports = () => {
return async function amqplibHandler(ctx, next) { return async function amqplibHandler(ctx, next) {
try { try {
console.log('经过中间件'); // console.log('经过中间件');
await next(); await next();
console.log('结束中间件'); // console.log('结束中间件');
} catch (err) { } catch (err) {
console.log('中间件异常'); await ctx.service.dingTalk.push(err && err.message);
ctx.throw(err); ctx.logger.error(err);
} }
}; };
}; };
[{"name":"udtoken","value":"\"xyqb@liangkebang.net:32c61623663da03652e142c33c364703:7288521588123582671991\"","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":85,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_session_template_key","value":"v5","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":30,"httpOnly":false,"secure":true,"session":true},{"name":"at","value":"\"xyqb@liangkebang.netSTNn71588067755917\"","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":42,"httpOnly":false,"secure":true,"session":true},{"name":"CNZZDATA1253449413","value":"955559336-1588122978-https%253A%252F%252Fmailsso.mxhichina.com%252F%7C1588122978","domain":"qiye.aliyun.com","path":"/","expires":1603848380,"size":98,"httpOnly":false,"secure":false,"session":false},{"name":"core_heart_beat","value":"1588123579298","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":28,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_auth_session_key","value":"QXltU2Vzc2lvbi03NDcyMDgtT0pTY0I0RnBrQjZoczNaeHFjN3hwTGJ5SlhlcFIzejVDV25jOTZRbHN1TERtb1ZQd0w","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":115,"httpOnly":false,"secure":true,"session":true},{"name":"core_token","value":"9844e7d915274930b9a9b41808296e9e","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":42,"httpOnly":false,"secure":true,"session":true},{"name":"CNZZDATA1254123268","value":"167192923-1588121580-%7C1588121580","domain":"qiye.aliyun.com","path":"/","expires":1603848343,"size":52,"httpOnly":false,"secure":false,"session":false},{"name":"alimail_sid","value":"OM566T91-I3DEANJXVEVZ6FCRGPFS1-6M1RNK9K-VM0K","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":55,"httpOnly":true,"secure":false,"session":true},{"name":"_csrf_token_","value":"QXltVG9rZW4tOTk0NzUxMzMteGcyNUROVWFONmM5YXRKeElmRmMzQ2FpQ1Nic1p5T2JqS1RJU2ZMcXZvT2wxRFU1Wnc","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":103,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_init_lang","value":"zh_CN","domain":"qiye.aliyun.com","path":"/","expires":1619227580.275363,"size":22,"httpOnly":false,"secure":true,"session":false},{"name":"alimail_session_version_key","value":"5844326","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":34,"httpOnly":false,"secure":true,"session":true},{"name":"UM_distinctid","value":"171c38a270e961-01e2a4d092cfce-6a320379-13c680-171c38a2712626","domain":".aliyun.com","path":"/","expires":1603848343,"size":73,"httpOnly":false,"secure":false,"session":false},{"name":"alimail_core_session_key","value":"QXltU2Vzc2lvbi03NDcyMDctYko1NDcyTG9XZGNrN25PYjlSYW1Ca2loaXV5S29lQm9wa21qUllXa1VldXR6QzJqMDE","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":115,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_sdata0","value":"a24zos5gOAbHitWQr5w%2FAPjq%2FaZMjZdT7RTkQgZElDibJ%2FqPy80rLrbT1nluOHhShmJyohOTVQf6LCXCap4DWdrPgH6wl%2B3E8UC8di0tqJkMMupPD2bwZZHwLU74eYZufB7p2m2XU%2BhuP8QsmEO%2BzA%3D%3D","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":182,"httpOnly":true,"secure":false,"session":true},{"name":"alimail_browser_instance","value":"dC0xNzM4MjI3LXRPUkFrcQ9438","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":50,"httpOnly":false,"secure":true,"session":true}] [{"name":"udtoken","value":"\"xyqb@liangkebang.net:32c61623663da03652e142c33c364703:1410841588224877089193\"","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":85,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_session_template_key","value":"v5","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":30,"httpOnly":false,"secure":true,"session":true},{"name":"at","value":"\"xyqb@liangkebang.netSTNn71588067755917\"","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":42,"httpOnly":false,"secure":true,"session":true},{"name":"CNZZDATA1253449413","value":"955559336-1588122978-https%253A%252F%252Fmailsso.mxhichina.com%252F%7C1588221380","domain":"qiye.aliyun.com","path":"/","expires":1603949675,"size":98,"httpOnly":false,"secure":false,"session":false},{"name":"core_heart_beat","value":"1588224873160","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":28,"httpOnly":false,"secure":true,"session":true},{"name":"CNZZDATA1254123268","value":"167192923-1588121580-%7C1588223262","domain":"qiye.aliyun.com","path":"/","expires":1603949660,"size":52,"httpOnly":false,"secure":false,"session":false},{"name":"alimail_browser_instance","value":"dC0xNzM4MjI3LXRPUkFrcQ9438","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":50,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_sdata0","value":"a24zos5gOAbHitWQr5w%2FAPjq%2FaZMjZdT7RTkQgZElDibJ%2FqPy80rLrbT1nluOHhShmJyohOTVQf6LCXCap4DWdrPgH6wl%2B3E8UC8di0tqJkMMupPD2bwZZHwLU74eYZufB7p2m2XU%2BhuP8QsmEO%2BzA%3D%3D","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":182,"httpOnly":true,"secure":false,"session":true},{"name":"alimail_init_lang","value":"zh_CN","domain":"qiye.aliyun.com","path":"/","expires":1619328874.575212,"size":22,"httpOnly":false,"secure":true,"session":false},{"name":"alimail_session_version_key","value":"5844326","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":34,"httpOnly":false,"secure":true,"session":true},{"name":"UM_distinctid","value":"171c38a270e961-01e2a4d092cfce-6a320379-13c680-171c38a2712626","domain":".aliyun.com","path":"/","expires":1603848343,"size":73,"httpOnly":false,"secure":false,"session":false},{"name":"alimail_auth_session_key","value":"QXltU2Vzc2lvbi03ODA5OTkteGdjWXlFeGJEVms2dkxUcXJmY0EzU1pjOXpUbVI1R1Y1Yk1XQkdoTEczMFliV3JXWHE","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":115,"httpOnly":false,"secure":true,"session":true},{"name":"core_token","value":"1e92ad3607c642218b2e986209a640f4","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":42,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_core_session_key","value":"QXltU2Vzc2lvbi03ODA5OTgtVFBndllyYURLMkJVenpwWEVDTzR2ZEx3ZWdlY29HdzA1bExrTnoyQ2N1WWR3T1VUc1A","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":115,"httpOnly":false,"secure":true,"session":true},{"name":"_csrf_token_","value":"QXltVG9rZW4tMjA1NTk5MDAtM04wZDFtSUJYNFhZNHdJcEgyYkVRS2Zna0pLelgwY2FIdTA0VjRkSjJmdVpTZlBaVkU","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":103,"httpOnly":false,"secure":true,"session":true},{"name":"alimail_sid","value":"OM566T91-I3DEANJXVEVZ6FCRGPFS1-6M1RNK9K-VM0K","domain":"qiye.aliyun.com","path":"/","expires":-1,"size":55,"httpOnly":true,"secure":false,"session":true}]
\ No newline at end of file \ No newline at end of file
[{"name":"dm_login_weixin_rem","value":"","domain":".qq.com","path":"/","expires":1588130324,"size":19,"httpOnly":false,"secure":false,"session":false},{"name":"qylevel","value":"2","domain":".exmail.qq.com","path":"/","expires":-1,"size":8,"httpOnly":false,"secure":false,"session":true},{"name":"tinfo","value":"EXPIRED","domain":".exmail.qq.com","path":"/","expires":-1,"size":12,"httpOnly":false,"secure":false,"session":true},{"name":"pcache","value":"c5e41550a7adde6MTU5MDYzNTkyNQ@763349601@7","domain":".exmail.qq.com","path":"/","expires":1588475925.246343,"size":47,"httpOnly":false,"secure":false,"session":false},{"name":"username","value":"763349601&763349601","domain":".exmail.qq.com","path":"/","expires":-1,"size":27,"httpOnly":false,"secure":false,"session":true},{"name":"CCSHOW","value":"0000","domain":".exmail.qq.com","path":"/","expires":1603595925.24621,"size":10,"httpOnly":false,"secure":false,"session":false},{"name":"sid","value":"763349601&b5019e2d8082cc7fdf7489b60ace325a,cPNmPQ12v30M.","domain":".exmail.qq.com","path":"/","expires":-1,"size":59,"httpOnly":true,"secure":false,"session":true},{"name":"qm_sid","value":"b5019e2d8082cc7fdf7489b60ace325a,cPNmPQ12v30M.","domain":".exmail.qq.com","path":"/","expires":-1,"size":52,"httpOnly":true,"secure":false,"session":true},{"name":"qqmail_alias","value":"tiange.zeng@lkbang.com","domain":".exmail.qq.com","path":"/","expires":-1,"size":34,"httpOnly":false,"secure":false,"session":true},{"name":"qm_authimgs_id","value":"2","domain":".qq.com","path":"/","expires":-1,"size":15,"httpOnly":false,"secure":false,"session":true},{"name":"qm_username","value":"763349601","domain":".exmail.qq.com","path":"/","expires":-1,"size":20,"httpOnly":true,"secure":false,"session":true},{"name":"Hm_lpvt_bdfb0d7298c0c5a5a2475c291ac7aca2","value":"1588043920","domain":".exmail.qq.com","path":"/","expires":-1,"size":50,"httpOnly":false,"secure":false,"session":true},{"name":"","value":"0.4473179612768925","domain":"exmail.qq.com","path":"/","expires":-1,"size":18,"httpOnly":false,"secure":false,"session":true},{"name":"logout_page","value":"dm_loginpage","domain":".qq.com","path":"/","expires":1588130324,"size":23,"httpOnly":false,"secure":false,"session":false},{"name":"_gid","value":"GA1.3.474598782.1588043915","domain":".exmail.qq.com","path":"/","expires":1588130319,"size":30,"httpOnly":false,"secure":false,"session":false},{"name":"ssl_edition","value":"sail.qq.com","domain":".exmail.qq.com","path":"/","expires":-1,"size":22,"httpOnly":false,"secure":false,"session":true},{"name":"qm_flag","value":"3","domain":".exmail.qq.com","path":"/","expires":-1,"size":8,"httpOnly":false,"secure":false,"session":true},{"name":"_ga","value":"GA1.3.189918274.1588043915","domain":".exmail.qq.com","path":"/","expires":1651115919,"size":29,"httpOnly":false,"secure":false,"session":false},{"name":"biz_username","value":"763349601","domain":".exmail.qq.com","path":"/","expires":-1,"size":21,"httpOnly":false,"secure":false,"session":true},{"name":"qm_verifyimagesession","value":"h0111d059d2b9bed8e5e170a3a267e4bc2ac493ba818cbd1fde46be30e6e2f6623c856d58cc5037f93f","domain":".qq.com","path":"/","expires":-1,"size":104,"httpOnly":false,"secure":false,"session":true},{"name":"qm_ssum","value":"763349601&f3d7dfb11d3da0007d7346a5f6c989c7","domain":".exmail.qq.com","path":"/","expires":-1,"size":49,"httpOnly":false,"secure":false,"session":true},{"name":"_gat","value":"1","domain":".exmail.qq.com","path":"/","expires":1588043974,"size":5,"httpOnly":false,"secure":false,"session":false},{"name":"qm_sk","value":"763349601&yKamb4b5","domain":".exmail.qq.com","path":"/","expires":-1,"size":23,"httpOnly":false,"secure":false,"session":true},{"name":"Hm_lvt_bdfb0d7298c0c5a5a2475c291ac7aca2","value":"1588043915","domain":".exmail.qq.com","path":"/","expires":1619579919,"size":49,"httpOnly":false,"secure":false,"session":false}] [{"name":"tinfo","value":"1588757204.0000","domain":".exmail.qq.com","path":"/","expires":-1,"size":20,"httpOnly":false,"secure":false,"session":true},{"name":"pcache","value":"a3a1f8d65f4614dMTU5MTM0OTIwNA@763349601@7","domain":".exmail.qq.com","path":"/","expires":1589189204.193691,"size":47,"httpOnly":false,"secure":false,"session":false},{"name":"sid","value":"763349601&7d4cbf8ba7f343b1776e2e8abea94f0b,cPNmPQ2BR_CY.","domain":".exmail.qq.com","path":"/","expires":-1,"size":59,"httpOnly":true,"secure":false,"session":true},{"name":"qm_ssum","value":"763349601&990a6f905765aee00388594e5679dc90","domain":".exmail.qq.com","path":"/","expires":-1,"size":49,"httpOnly":false,"secure":false,"session":true},{"name":"qqmail_alias","value":"tiange.zeng@lkbang.com","domain":".exmail.qq.com","path":"/","expires":-1,"size":34,"httpOnly":false,"secure":false,"session":true},{"name":"qm_sid","value":"7d4cbf8ba7f343b1776e2e8abea94f0b,cPNmPQ2BR_CY.","domain":".exmail.qq.com","path":"/","expires":-1,"size":52,"httpOnly":true,"secure":false,"session":true},{"name":"_gat","value":"1","domain":".exmail.qq.com","path":"/","expires":1588757263,"size":5,"httpOnly":false,"secure":false,"session":false},{"name":"logout_page","value":"dm_loginpage","domain":".qq.com","path":"/","expires":1588843604,"size":23,"httpOnly":false,"secure":false,"session":false},{"name":"_gid","value":"GA1.3.1779487220.1588757204","domain":".exmail.qq.com","path":"/","expires":1588843603,"size":31,"httpOnly":false,"secure":false,"session":false},{"name":"qylevel","value":"2","domain":".exmail.qq.com","path":"/","expires":-1,"size":8,"httpOnly":false,"secure":false,"session":true},{"name":"dm_login_weixin_rem","value":"","domain":".qq.com","path":"/","expires":1588843604,"size":19,"httpOnly":false,"secure":false,"session":false},{"name":"qm_verifyimagesession","value":"h0105e45bb704bff20a3ec64e241b20afac0c9777b65a987cb0bb4b98bd8160ed878d4c443d7c4256bc","domain":".qq.com","path":"/","expires":-1,"size":104,"httpOnly":false,"secure":false,"session":true},{"name":"biz_username","value":"763349601","domain":".exmail.qq.com","path":"/","expires":-1,"size":21,"httpOnly":false,"secure":false,"session":true},{"name":"CCSHOW","value":"0000","domain":".exmail.qq.com","path":"/","expires":1604309204.193596,"size":10,"httpOnly":false,"secure":false,"session":false},{"name":"Hm_lpvt_bdfb0d7298c0c5a5a2475c291ac7aca2","value":"1588757204","domain":".exmail.qq.com","path":"/","expires":-1,"size":50,"httpOnly":false,"secure":false,"session":true},{"name":"qm_username","value":"763349601","domain":".exmail.qq.com","path":"/","expires":-1,"size":20,"httpOnly":false,"secure":false,"session":true},{"name":"qm_sk","value":"763349601&yKamb4b5","domain":".exmail.qq.com","path":"/","expires":-1,"size":23,"httpOnly":false,"secure":false,"session":true},{"name":"Hm_lvt_bdfb0d7298c0c5a5a2475c291ac7aca2","value":"1588043915","domain":".exmail.qq.com","path":"/","expires":1620293203,"size":49,"httpOnly":false,"secure":false,"session":false},{"name":"","value":"0.4473179612768925","domain":"exmail.qq.com","path":"/","expires":-1,"size":18,"httpOnly":false,"secure":false,"session":true},{"name":"ssl_edition","value":"sail.qq.com","domain":".exmail.qq.com","path":"/","expires":-1,"size":22,"httpOnly":false,"secure":false,"session":true},{"name":"qm_flag","value":"3","domain":".exmail.qq.com","path":"/","expires":-1,"size":8,"httpOnly":false,"secure":false,"session":true},{"name":"username","value":"763349601&763349601","domain":".exmail.qq.com","path":"/","expires":-1,"size":27,"httpOnly":false,"secure":false,"session":true},{"name":"_ga","value":"GA1.3.189918274.1588043915","domain":".exmail.qq.com","path":"/","expires":1651829203,"size":29,"httpOnly":false,"secure":false,"session":false},{"name":"qm_authimgs_id","value":"0","domain":".qq.com","path":"/","expires":-1,"size":15,"httpOnly":false,"secure":false,"session":true}]
\ No newline at end of file \ No newline at end of file
...@@ -6,13 +6,16 @@ ...@@ -6,13 +6,16 @@
module.exports = app => { module.exports = app => {
const { router, controller } = app; const { router, controller } = app;
// 测试腾讯企业邮 // 腾讯企业邮
router.get('/', controller.home.index); router.get('/excute', controller.home.index);
router.get('/ocr', controller.home.testOCR);
router.get('/publisher', controller.home.publisher); router.get('/publisher', controller.home.publisher);
router.get('/consumer', controller.home.consumer); router.get('/consumer', controller.home.consumer);
router.get('/testFdfs', controller.home.testFdfs);
router.get('/testDownload', controller.home.testDownload);
router.get('/testDing', controller.home.testDing);
router.get('/testGetMails', controller.home.testGetMails);
router.get('/testUpdateMails', controller.home.testUpdateMails);
// 测试阿里企业邮 // 阿里企业邮
router.get('/send-mail', controller.mail.index); router.get('/send-mail', controller.mail.index);
router.get('/get-image', controller.mail.getImage);
}; };
'use strict';
module.exports = {
schedule: {
cron: '*/1 * * * * *',
type: 'worker',
immediate: true,
},
async task(ctx) {
// ctx.logger.info('定时任务开始');
// await ctx.service.home.sendMail();
// ctx.logger.info('定时任务结束');
},
};
'use strict';
const Service = require('egg').Service;
class DingService extends Service {
async push(message) {
const webhook = 'https://oapi.dingtalk.com/robot/send?access_token=eb36b5a10ccd4da43e1bb93815fc44e3aab3ed6a68308dfad833792f1cf4b36e';
const data = {
msgtype: 'markdown',
markdown: {
title: '法催邮件异常',
text: `### 法催邮件异常 \n${message || '未知错误'}`,
},
};
return this.ctx.curl(webhook, {
contentType: 'json',
dataType: 'json',
method: 'POST',
data,
});
}
}
module.exports = DingService;
'use strict';
const Service = require('egg').Service;
const FdfsClient = require('fdfs');
const { fdfs: config } = require('../../config/config.default.js')({});
const fdfs = new FdfsClient(config);
class FDFSService extends Service {
async upload(...args) {
return fdfs.upload.apply(fdfs, args);
}
async download(...args) {
return fdfs.download.apply(fdfs, args);
}
}
module.exports = FDFSService;
'use strict'; 'use strict';
const qs = require('querystring');
const Service = require('egg').Service; const Service = require('egg').Service;
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const queueName = 'test'; const queueName = 'test';
const cookiePath = '../public/data/cookies.json';
const validate = result => {
if (result.code !== 2000) throw new Error(result && result.msg || '服务器异常');
return result.data;
};
class HomeService extends Service { class HomeService extends Service {
async getAccessToken() { async getMails() {
const param = qs.stringify({ const { ctx } = this;
grant_type: 'client_credentials', const limit = 150;
client_id: 'S20Ves9LBcNMUuGwhcboufcH', console.log(`${ctx.app.config.legal.host}/api/email/get/${limit}`);
client_secret: 'oHL4QWx0GG8aGGPBasOCIma39s7jry5W', const { data: result } = await ctx.curl(`${ctx.app.config.legal.host}/api/email/get/${limit}`, {
dataType: 'json',
method: 'POST',
}); });
const result = await this.ctx.curl(`https://aip.baidubce.com/oauth/2.0/token?${param}`, { dataType: 'json' });
if (!(result.data && result.data.access_token)) throw new Error(result.data && result.data.error_msg || '百度ocr验证码获取token失败'); return validate(result);
return result.data.access_token;
} }
async getCode(base64Img, access_token = '24.dd5c3d2b02e1f36cf576ab05b7d16772.2592000.1590288139.282335-19579288') { async updateStatus(mails) {
const param = { const { ctx } = this;
image: encodeURI(base64Img), console.log(`${ctx.app.config.legal.host}/api/email/callback`);
language_type: 'ENG', const { data: result } = await ctx.curl(`${ctx.app.config.legal.host}/api/email/callback`, {
}; contentType: 'json',
const result = await this.ctx.curl(`https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=${access_token}`, {
method: 'POST',
data: param,
dataType: 'json', dataType: 'json',
method: 'POST',
data: mails,
}); });
this.ctx.logger.warn(`tecent mail: 百度ocr返回结果 - ${JSON.stringify(result.data)}`);
if (result.data && result.data.words_result && result.data.words_result.length === 0) return ''; return validate(result);
if (!(result.data && result.data.words_result && result.data.words_result.length && result.data.words_result[0].words)) throw new Error(result.data && result.data.error_msg || '百度ocr验证码识别失败'); }
return result.data.words_result[0].words.replace(/\s/ig, '');
async sendMail(mails) {
const { ctx, service } = this;
const result = [];
const browserConfig = {
headless: false,
defaultViewport: {
width: 1024,
height: 1000,
},
};
let cookie = fs.readFileSync(path.join(__dirname, cookiePath)).toString();
try {
const browser = await puppeteer.launch(browserConfig);
const page = await browser.newPage();
if (cookie) await ctx.helper.addCookies(JSON.parse(cookie), page);
await page.goto('https://exmail.qq.com');
ctx.logger.info('tecent mail: 进入https://exmail.qq.com');
const btnlogin = await page.$('.index_topbar_btn_login');
const btlogin = await page.$('#btlogin');
// 未登录状态先进行登录
if (btnlogin || btlogin) {
ctx.logger.info('tecent mail: 未登录进行登录');
if (btnlogin) {
await page.goto('https://exmail.qq.com/login');
await page.click('.js_show_pwd_panel');
}
await page.$eval('#inputuin', input => { input.value = ''; });
await page.type('#inputuin', ctx.app.config.tecent.account);
await page.type('#pp', ctx.app.config.tecent.password);
await page.click('#auto_login_in_five_days_pwd');
await page.click('#btlogin');
await page.waitForNavigation({ waitUntil: 'load' }); // 等待页面加载出来,等同于window.onload
let VerifyArea = await page.$('#VerifyArea');
if (VerifyArea) {
let j = 0;
ctx.logger.warn('tecent mail: 登录需要输入验证码!');
while (VerifyArea && j < 100) {
j++;
ctx.logger.warn(`tecent mail: 第${j}次输入验证码!`);
await ctx.helper.writeTecentLoginCode(page);
await page.waitFor(5000);
VerifyArea = await page.$('#VerifyArea');
}
if (j === 100) throw new Error('验证码尝试过多');
}
cookie = await page.cookies('https://exmail.qq.com');
fs.writeFileSync(path.join(__dirname, cookiePath), JSON.stringify(cookie));
}
ctx.logger.info('tecent mail: 已登录');
for (let i = 0; i < mails.length; i++) {
const email = mails[i].email;
ctx.logger.info(`tecent mail: 准备发送第${i + 1}封邮件 mail: ${email}`);
await page.click('#composebtn');
const mainFrame = await page.frames().find(f => f.name() === 'mainFrame');
await mainFrame.waitFor(3000);
await mainFrame.waitFor('#subject');
await mainFrame.waitFor('.addr_text>input');
await mainFrame.type('.addr_text>input', email);
await mainFrame.type('#subject', mails[i].subject);
const bodyFrame = await mainFrame.childFrames()[2];
await bodyFrame.type('body', mails[i].content);
await mainFrame.click('input[name="sendbtn"]');
await mainFrame.waitFor(3000);
const isNeedCode = await page.$('#QMVerify_s_vfcode');
if (isNeedCode) throw new Error('发送邮件需要输入验证码!');
await mainFrame.waitFor('#readSendbox>a');
await mainFrame.click('#readSendbox>a');
await mainFrame.waitFor(5000);
const mailSendStatusFrame = await mainFrame.childFrames().find(f => f.name() === 'mailSendStatus');
await mailSendStatusFrame.waitFor('#statusbtn');
await mailSendStatusFrame.waitFor('#clickstu');
await mailSendStatusFrame.click('#clickstu');
let sendStatus = await mailSendStatusFrame.$eval('#statusbtn', el => el.innerHTML);
const receiver = await mailSendStatusFrame.$eval('.oneline', el => el.innerHTML);
if (sendStatus === '正在投递') {
await mailSendStatusFrame.waitFor(10000);
const clickStatus = await mailSendStatusFrame.$eval('#clickstu', el => el.innerHTML);
if (clickStatus === '[查看详情]') await mailSendStatusFrame.click('#clickstu');
await mailSendStatusFrame.click('#refreshbutton');
await mailSendStatusFrame.waitFor(2000);
sendStatus = await mailSendStatusFrame.$eval('#statusbtn', el => el.innerHTML);
}
if (!receiver.includes(email)) {
ctx.logger.error('收件箱不一致, 投递失败');
continue;
}
if (sendStatus !== '投递成功') {
ctx.logger.error(sendStatus || '投递失败');
continue;
}
await page.mouse.move(0, 0);
const mainFrameContainer = await page.$('#mainFrameContainer');
const imageName = `${email}_${Date.now()}.png`;
await mainFrameContainer.screenshot({ path: `./app/public/images/${imageName}` });
const imagePath = await service.fdfs.upload(path.join(__dirname, `../public/images/${imageName}`));
result.push({ id: mails[i].id, url: imagePath });
await mainFrame.waitFor(parseInt((Math.random() * 3 + 1) * 1000, 10));
}
await browser.close();
} catch (e) {
await service.dingTalk.push(e && e.message);
ctx.logger.error(e);
}
return result;
} }
async publisher() { async publisher() {
......
'use strict';
const Service = require('egg').Service;
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const cookiePath = '../public/data/ali-cookies.json';
const browserConfig = {
headless: false,
defaultViewport: {
width: 1024,
height: 768,
},
};
class MailService extends Service {
async getImage(mails) {
const { ctx } = this;
const result = [];
let cookie = fs.readFileSync(path.join(__dirname, cookiePath)).toString();
try {
const browser = await puppeteer.launch(browserConfig);
const page = await browser.newPage();
if (cookie) await ctx.helper.addCookies(JSON.parse(cookie), page);
ctx.logger.info('aliyun mail: 进入https://qiye.aliyun.com');
await page.goto('https://qiye.aliyun.com', { waitUntil: 'networkidle2' });
const loginPanelIframe = await page.$('.login_panel_iframe');
if (loginPanelIframe) {
const src = await page.$eval('.login_panel_iframe', el => el.src);
await page.goto(src);
const dingLoginFrame = await page.frames().find(f => f.name() === 'ding-login-iframe');
await dingLoginFrame.$eval('#username', input => { input.value = ''; });
await dingLoginFrame.type('#username', ctx.app.config.aliyun[0].account);
await dingLoginFrame.type('#password', ctx.app.config.aliyun[0].password);
await dingLoginFrame.click('#login_remember_check');
await dingLoginFrame.click('#login_submit_btn');
await page.waitFor(2500);
let loginErrorLine = await dingLoginFrame.$('#login_checkcode_ico');
if (loginErrorLine) {
ctx.logger.warn('aliyun mail: 登录需要输入验证码!');
let j = 0;
while (loginErrorLine && j < 50) {
j++;
ctx.logger.warn(`aliyun mail: 第${j}次输入验证码!`);
await ctx.helper.writeLoginCode(dingLoginFrame, ctx);
await page.waitFor(5000);
loginErrorLine = await page.$('.login_panel_iframe');
}
if (j === 50) throw new Error('验证码尝试过多');
}
cookie = await page.cookies('https://qiye.aliyun.com');
fs.writeFileSync(path.join(__dirname, cookiePath), JSON.stringify(cookie));
}
ctx.logger.info('aliyun mail: 已登录');
for (let i = 0; i < mails.length; i++) {
const receiver = mails[i].receiver;
await page.click('.e_textbox_input_wrap');
await page.click('.header_search_advanced');
await page.type('.criteria_receiver .e_entry_input', receiver);
await page.click('.e_d_button_wrap .e_b');
await page.waitFor(2500);
await page.click('.root_frame_wrap>div:nth-child(3) .cblist_virtual_block_wrap .maillist_item_wrap');
await page.waitFor(2500);
await page.click('.mailsession_view_wrap_b .mailheader_spread');
const receiverText = await page.$eval('div[_msdn="wrap"] .e_entry_label_wrap', el => el.innerHTML);
if (!receiverText || receiverText.trim() !== receiver.split('@')[0]) {
ctx.logger.warn(`未搜索到邮件. mail:${receiver}`);
continue;
}
const sendText = await page.$eval('.maildetail_header_wrap .maildetail_status_send_text', el => el.innerHTML);
if (sendText !== '发送成功,查看读信状态') {
ctx.logger.warn(`邮件截图失败. reason: ${sendText}, mail:${receiver}`);
continue;
}
const mailContainer = await page.$('.root_frame_wrap>div:nth-child(3) .maildetail_active');
await mailContainer.screenshot({ path: `./app/public/images/${receiver}.png` });
// const filePath = await this.service.fdfs.upload(path.join(__dirname, './app/public/images/${receiver}.png'));
result.push({ receiver, status: '上传成功' });
}
} catch (e) {
console.log('截图失败', e || e.message);
}
return result;
}
}
module.exports = MailService;
'use strict';
const qs = require('querystring');
const Service = require('egg').Service;
class OCRService extends Service {
async getAccessToken() {
const param = qs.stringify({
grant_type: 'client_credentials',
client_id: 'S20Ves9LBcNMUuGwhcboufcH',
client_secret: 'oHL4QWx0GG8aGGPBasOCIma39s7jry5W',
});
const result = await this.ctx.curl(`https://aip.baidubce.com/oauth/2.0/token?${param}`, { dataType: 'json' });
if (!(result.data && result.data.access_token)) throw new Error(result.data && result.data.error_msg || '百度ocr验证码获取token失败');
return result.data.access_token;
}
async getCode(base64Img) {
const param = {
image: encodeURI(base64Img),
language_type: 'ENG',
};
const access_token = await this.getAccessToken();
const result = await this.ctx.curl(`https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=${access_token}`, {
method: 'POST',
data: param,
dataType: 'json',
});
this.ctx.logger.warn(`tecent mail: 百度ocr返回结果 - ${JSON.stringify(result.data)}`);
if (result.data && result.data.words_result && result.data.words_result.length === 0) return '';
if (!(result.data && result.data.words_result && result.data.words_result.length && result.data.words_result[0].words)) throw new Error(result.data && result.data.error_msg || '百度ocr验证码识别失败');
return result.data.words_result[0].words.replace(/\s/ig, '');
}
}
module.exports = OCRService;
...@@ -44,8 +44,48 @@ module.exports = appInfo => { ...@@ -44,8 +44,48 @@ module.exports = appInfo => {
// myAppName: 'egg', // myAppName: 'egg',
}; };
const mailConfig = {
aliyun: [
{ account: 'xyqb@liangkebang.net', password: 'Ztg202020' },
],
tecent: { account: 'Tiange.zeng@lkbang.com', password: 'Ztg2020' },
smtp: {
host: 'smtp.mxhichina.com',
port: 465,
secure: true, // use SSL
auth: {
user: 'xyqb3@liangkebang.net',
pass: 'Ztg202020', // 这是邮箱的授权码不是登录密码。 安全登录的客户端专用密码:
},
},
legal: {
host: 'http://192.168.28.66:20585',
},
};
const fdfsConfig = {
fdfs: {
// tracker servers
trackers: [
{
host: 'tracker-fdfs1.quantgroups.com',
port: 22122,
},
],
// 默认超时时间10s
timeout: 10000,
// 默认后缀
// 当获取不到文件后缀时使用
defaultExt: 'png',
// charset默认utf8
charset: 'utf8',
},
};
return { return {
...config, ...config,
...userConfig, ...userConfig,
...mailConfig,
...fdfsConfig,
}; };
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment