66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|
import { sendSms } from '../sms';
|
|
export const smsHandler = async (notification, context) => {
|
|
const { data, data1, id } = notification;
|
|
const [messageSystem] = await context.select('messageSystem', {
|
|
data: {
|
|
id: 1,
|
|
message: {
|
|
id: 1,
|
|
type: 1,
|
|
},
|
|
},
|
|
filter: {
|
|
id: notification.messageSystemId,
|
|
}
|
|
}, { dontCollect: true });
|
|
const { message } = messageSystem;
|
|
const { type } = message;
|
|
try {
|
|
const result = await sendSms({
|
|
messageType: type,
|
|
templateParam: data.params,
|
|
mobile: data1.mobile,
|
|
}, context);
|
|
if (result?.success === true) {
|
|
await context.operate('notification', {
|
|
id: await generateNewIdAsync(),
|
|
action: 'succeed',
|
|
data: {
|
|
data2: {
|
|
res: result?.res || {}
|
|
}
|
|
},
|
|
filter: {
|
|
id,
|
|
}
|
|
}, { dontCollect: true });
|
|
}
|
|
else {
|
|
await context.operate('notification', {
|
|
id: await generateNewIdAsync(),
|
|
action: 'fail',
|
|
data: {
|
|
data2: {
|
|
res: result?.res || {}
|
|
}
|
|
},
|
|
filter: {
|
|
id,
|
|
}
|
|
}, { dontCollect: true });
|
|
}
|
|
}
|
|
catch (err) {
|
|
await context.operate('notification', {
|
|
id: await generateNewIdAsync(),
|
|
action: 'fail',
|
|
data: {},
|
|
filter: {
|
|
id,
|
|
}
|
|
}, { dontCollect: true });
|
|
console.warn('发短信消息失败', err);
|
|
}
|
|
};
|