每次重新扫码;

dev/supplier-email-drawer
Lei OT 9 months ago
parent 913b88dc38
commit bec63bbfc2

@ -7,24 +7,24 @@ const { domain } = require('../../config').server;
exports.newConnect = async ctx => {
try {
const { phone } = ctx.query;
const findSession = await getConnection({ sesson_id: phone, connect_domain: domain });
// todo: 只有一条
if (!isEmpty(findSession)) {
const { sesson_id: sessonId, status } = findSession[0];
if (['open', 'connecting'].includes(status)) {
const sock = sessionService.getSession(sessonId);
if (!isEmpty(sock)) {
return sock;
}
}
}
// const findSession = await getConnection({ sesson_id: phone, connect_domain: domain });
// // todo: 只有一条
// if (!isEmpty(findSession)) {
// const { sesson_id: sessonId, status } = findSession[0];
// if (['open', 'connecting'].includes(status)) {
// const sock = sessionService.getSession(sessonId);
// if (!isEmpty(sock)) {
// return sock;
// }
// }
// }
const whatsApp1 = await createWhatsApp(phone);
const existsSession = sessionService.getSession(phone);
let qr;
if (isEmpty(existsSession)) {
qr = await whatsApp1.start();
const { sessionId } = sessionService.createSession(phone, whatsApp1);
}
// if (isEmpty(existsSession)) {
qr = await whatsApp1.start();
const { sessionId } = sessionService.createSession(phone, whatsApp1);
// }
ctx.assert(whatsApp1, 503, 'No available connections');
return { qr, phone, sessionId: phone };
} catch (error) {

@ -121,7 +121,7 @@ const createWhatsApp = async phone => {
status: 'online',
});
waEmitter.emit('connection:open', {
status: 'open', phone
status: 'open', whatsAppNo
});
} else if (qr !== undefined) {
// WebSocket 创建成功等待扫码,如果没有扫码会更新 qr

@ -55,7 +55,7 @@ const setupConnectionHandler = () => {
try {
await updateConnection(
{
...objectMapper(connectionData, { phone: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }),
...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }),
service_type: 'baileys',
},
{ connect_domain: domain },
@ -69,7 +69,7 @@ const setupConnectionHandler = () => {
try {
sessionService.removeSession(connectionData.sesson_id);
await updateConnection({
...objectMapper(connectionData, { phone: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }),
...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }),
service_type: 'baileys',
});
// todo: 通知前端: 重新扫码

Loading…
Cancel
Save