feat: 短信注入函数registSms改为registerSms,项目引用需适配,短信模版列表支持传入pageIndex和pageSize
This commit is contained in:
parent
edbeb63cc1
commit
257f7669fc
|
|
@ -653,6 +653,8 @@ export type AspectDict<ED extends EntityDict> = {
|
|||
syncSmsTemplate: (params: {
|
||||
systemId: string;
|
||||
origin: EntityDict['smsTemplate']['Schema']['origin'];
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BackendRuntimeContext<ED>) => Promise<void>;
|
||||
/**
|
||||
* 获取应用的登录方式配置列表
|
||||
|
|
|
|||
|
|
@ -3,4 +3,6 @@ import { BRC } from '../types/RuntimeCxt';
|
|||
export declare function syncSmsTemplate<ED extends EntityDict>(params: {
|
||||
origin: EntityDict['smsTemplate']['Schema']['origin'];
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BRC<ED>): Promise<void>;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||
import { getSms } from '../utils/sms/index';
|
||||
export async function syncSmsTemplate(params, context) {
|
||||
const { origin, systemId } = params;
|
||||
const { origin, systemId, pageIndex, pageSize } = params;
|
||||
const Sms = getSms(origin);
|
||||
const templateFormalData = await Sms.syncTemplate(systemId, context);
|
||||
const templateFormalData = await Sms.syncTemplate({
|
||||
systemId: systemId,
|
||||
pageIndex,
|
||||
pageSize
|
||||
}, context);
|
||||
const existTemplateList = await context.select('smsTemplate', {
|
||||
data: {
|
||||
id: 1,
|
||||
|
|
|
|||
|
|
@ -2575,8 +2575,8 @@ export async function refreshToken(params, context) {
|
|||
// 只有server模式去刷新token
|
||||
// 'development' | 'production' | 'staging'
|
||||
const intervals = {
|
||||
development: 7200 * 1000, // 2小时
|
||||
staging: 600 * 1000, // 十分钟
|
||||
development: 7200 * 1000,
|
||||
staging: 600 * 1000,
|
||||
production: 600 * 1000, // 十分钟
|
||||
};
|
||||
let applicationId = token.applicationId;
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ declare const _default: <ED2 extends EntityDict & BaseEntityDict, T2 extends key
|
|||
type?: ButtonProps['type'] | AmButtonProps['type'];
|
||||
executeText?: string | undefined;
|
||||
buttonProps?: (ButtonProps & {
|
||||
color?: "success" | "default" | "warning" | "primary" | "danger" | undefined;
|
||||
color?: "default" | "success" | "primary" | "warning" | "danger" | undefined;
|
||||
fill?: "none" | "solid" | "outline" | undefined;
|
||||
size?: "small" | "middle" | "large" | "mini" | undefined;
|
||||
size?: "small" | "large" | "middle" | "mini" | undefined;
|
||||
block?: boolean | undefined;
|
||||
loading?: boolean | "auto" | undefined;
|
||||
loadingText?: string | undefined;
|
||||
|
|
@ -27,7 +27,7 @@ declare const _default: <ED2 extends EntityDict & BaseEntityDict, T2 extends key
|
|||
type?: "reset" | "submit" | "button" | undefined;
|
||||
shape?: "default" | "rounded" | "rectangular" | undefined;
|
||||
children?: import("react").ReactNode;
|
||||
} & Pick<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement>, "id" | "onMouseDown" | "onMouseUp" | "onTouchEnd" | "onTouchStart"> & {
|
||||
} & Pick<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement>, "id" | "onMouseUp" | "onMouseDown" | "onTouchStart" | "onTouchEnd"> & {
|
||||
className?: string | undefined;
|
||||
style?: (import("react").CSSProperties & Partial<Record<"--text-color" | "--background-color" | "--border-radius" | "--border-width" | "--border-style" | "--border-color", string>>) | undefined;
|
||||
tabIndex?: number | undefined;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// import { registerMessageNotificationConverters } from './triggers/message';
|
||||
// import { registerWeChatPublicEventCallback } from './endpoints';
|
||||
export * from './types/Exception';
|
||||
export * from './types/Message';
|
||||
export * from './types/RuntimeCxt';
|
||||
|
|
|
|||
|
|
@ -35,6 +35,6 @@ registerNotificationHandler,
|
|||
* 例如: 在其他渠道失败后自动发送短信通知
|
||||
*/
|
||||
registerNotificationFailureHandler, } from './utils/notification';
|
||||
export { registSms, } from './utils/sms';
|
||||
export { registerSms, } from './utils/sms';
|
||||
export { registerCosBackend, } from './utils/cos/index.backend';
|
||||
export { registerOauthUserinfoHandler, } from './utils/oauth/index';
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ registerNotificationHandler,
|
|||
registerNotificationFailureHandler, } from './utils/notification';
|
||||
export {
|
||||
// 注册短信服务商实现
|
||||
registSms, } from './utils/sms';
|
||||
registerSms, } from './utils/sms';
|
||||
export {
|
||||
// 注册对象存储服务商实现(后端)
|
||||
registerCosBackend, } from './utils/cos/index.backend';
|
||||
|
|
|
|||
|
|
@ -8,11 +8,19 @@ export default interface Sms<ED extends EntityDict> {
|
|||
/**
|
||||
* 是否支持模板同步
|
||||
*/
|
||||
syncTemplate(systemId: string, context: BRC<ED>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
international?: 0 | 1;
|
||||
}, context: BRC<ED>): Promise<{
|
||||
templateName: string;
|
||||
templateCode: string;
|
||||
templateContent: string;
|
||||
}[]>;
|
||||
/**
|
||||
* 短信发送
|
||||
*/
|
||||
sendSms(params: {
|
||||
mobile: string;
|
||||
templateParam?: Record<string, any>;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,4 @@ export declare function getOrigin(): string[];
|
|||
export declare function sendEmail<ED extends EntityDict>(options: EmailOptions, context: BRC<ED>): Promise<{
|
||||
success: boolean;
|
||||
error?: string | undefined;
|
||||
} | {
|
||||
success: boolean;
|
||||
error: unknown;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export async function sendEmail(options, context) {
|
|||
catch (err) {
|
||||
return {
|
||||
success: false,
|
||||
error: err,
|
||||
error: err?.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export default class Nodemailer implements Email<EntityDict> {
|
|||
error?: undefined;
|
||||
} | {
|
||||
success: boolean;
|
||||
error: any;
|
||||
error: string | undefined;
|
||||
info?: undefined;
|
||||
}>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ export const wechatMpHandler = async (notification, context) => {
|
|||
action: 'fail',
|
||||
data: {
|
||||
data2: {
|
||||
res: err.message
|
||||
res: err?.message
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ export const wechatPublicHandler = async (notification, context) => {
|
|||
action: 'fail',
|
||||
data: {
|
||||
data2: {
|
||||
res: err.message
|
||||
res: err?.message
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ export default class Ali implements Sms<EntityDict> {
|
|||
config: AliSmsConfig;
|
||||
mockSend: boolean | undefined;
|
||||
}>;
|
||||
syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
templateCode: string;
|
||||
templateName: string;
|
||||
templateContent: string;
|
||||
|
|
|
|||
|
|
@ -34,13 +34,14 @@ export default class Ali {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId, context) {
|
||||
async syncTemplate(options, context) {
|
||||
const { systemId, pageIndex, pageSize } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { accessKeyId, accessKeySecret, endpoint, apiVersion } = config;
|
||||
const aliInstance = SDK.getInstance('ali', accessKeyId, accessKeySecret, endpoint, undefined, apiVersion);
|
||||
const result = await aliInstance.syncTemplate({
|
||||
pageIndex: 1,
|
||||
pageSize: 50
|
||||
pageIndex: pageIndex || 1,
|
||||
pageSize: pageSize || 50
|
||||
});
|
||||
const { smsTemplateList } = result;
|
||||
if (smsTemplateList) {
|
||||
|
|
@ -64,7 +65,7 @@ export default class Ali {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await aliInstance.sendSms({
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ export default class CTYun implements Sms<EntityDict> {
|
|||
config: CTYunSmsConfig;
|
||||
mockSend: boolean | undefined;
|
||||
}>;
|
||||
syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
templateCode: string;
|
||||
templateName: string;
|
||||
templateContent: string;
|
||||
|
|
|
|||
|
|
@ -32,13 +32,14 @@ export default class CTYun {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId, context) {
|
||||
async syncTemplate(options, context) {
|
||||
const { systemId, pageIndex, pageSize } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { accessKey, securityKey, endpoint } = config;
|
||||
const ctyunInstance = SDK.getInstance('ctyun', accessKey, securityKey, endpoint);
|
||||
const result = await ctyunInstance.syncTemplate({
|
||||
pageIndex: 1,
|
||||
pageSize: 50, // pageSize必须小于或等于50
|
||||
pageIndex: pageIndex || 1,
|
||||
pageSize: pageSize || 50, // pageSize必须小于或等于50
|
||||
});
|
||||
const { data } = result;
|
||||
if (data) {
|
||||
|
|
@ -62,7 +63,7 @@ export default class CTYun {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await ctyunInstance.sendSms({
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import Sms from '../../types/Sms';
|
|||
* 注入一个其它发送短信类
|
||||
* @param clazz
|
||||
*/
|
||||
export declare function registSms<ED extends EntityDict>(clazz: new () => Sms<ED>): void;
|
||||
export declare function registerSms<ED extends EntityDict>(clazz: new () => Sms<ED>): void;
|
||||
export declare function getSms<ED extends EntityDict>(origin: string): Sms<ED>;
|
||||
export declare function getOrigin(): string[];
|
||||
export declare function sendSms<ED extends EntityDict>(options: {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const SmsDict = {};
|
|||
* 注入一个其它发送短信类
|
||||
* @param clazz
|
||||
*/
|
||||
export function registSms(clazz) {
|
||||
export function registerSms(clazz) {
|
||||
const instance = new clazz();
|
||||
SmsDict[instance.name] = instance;
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ export async function sendSms(options, context) {
|
|||
if (!smsTemplate) {
|
||||
return {
|
||||
success: false,
|
||||
res: `${origin}渠道的${templateName}短信模板未配置`,
|
||||
res: `${origin}短信渠道未配置「${templateName}」模板`,
|
||||
};
|
||||
}
|
||||
try {
|
||||
|
|
@ -49,7 +49,7 @@ export async function sendSms(options, context) {
|
|||
catch (err) {
|
||||
return {
|
||||
success: false,
|
||||
res: err,
|
||||
res: err?.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -97,14 +97,14 @@ export async function sendSms(options, context) {
|
|||
}
|
||||
catch (err) {
|
||||
Object.assign(resList, {
|
||||
[messageTypeSmsTemplate.template.origin]: err,
|
||||
[messageTypeSmsTemplate.template.origin]: err?.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
res: {
|
||||
message: '所有短信渠道均发送失败',
|
||||
message: `所有短信渠道发送「${messageType}」模板均失败`,
|
||||
errorList: resList,
|
||||
},
|
||||
};
|
||||
|
|
@ -112,7 +112,7 @@ export async function sendSms(options, context) {
|
|||
else {
|
||||
return {
|
||||
success: false,
|
||||
res: `短信未配置${messageType}模板`,
|
||||
res: `所有短信渠道未配置「${messageType}」模板`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,12 @@ export default class Tencent implements Sms<EntityDict> {
|
|||
config: TencentSmsConfig;
|
||||
mockSend: boolean | undefined;
|
||||
}>;
|
||||
syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
international?: number;
|
||||
}, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
templateCode: string;
|
||||
templateName: string;
|
||||
templateContent: string;
|
||||
|
|
|
|||
|
|
@ -35,14 +35,15 @@ export default class Tencent {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId, context) {
|
||||
async syncTemplate(options, context) {
|
||||
const { systemId, pageIndex, pageSize, international } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { secretId, secretKey, region, endpoint } = config;
|
||||
const tencentInstance = SDK.getInstance('tencent', secretId, secretKey, endpoint, region);
|
||||
const result = await tencentInstance.syncTemplate({
|
||||
International: 0,
|
||||
Limit: 100,
|
||||
Offset: 0,
|
||||
International: international || 0,
|
||||
Offset: pageIndex && pageIndex >= 1 ? pageIndex - 1 : 0,
|
||||
Limit: pageSize || 100,
|
||||
});
|
||||
const { DescribeTemplateStatusSet } = result;
|
||||
if (DescribeTemplateStatusSet) {
|
||||
|
|
@ -78,7 +79,7 @@ export default class Tencent {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await tencentInstance.sendSms({
|
||||
|
|
|
|||
|
|
@ -653,6 +653,8 @@ export type AspectDict<ED extends EntityDict> = {
|
|||
syncSmsTemplate: (params: {
|
||||
systemId: string;
|
||||
origin: EntityDict['smsTemplate']['Schema']['origin'];
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BackendRuntimeContext<ED>) => Promise<void>;
|
||||
/**
|
||||
* 获取应用的登录方式配置列表
|
||||
|
|
|
|||
|
|
@ -3,4 +3,6 @@ import { BRC } from '../types/RuntimeCxt';
|
|||
export declare function syncSmsTemplate<ED extends EntityDict>(params: {
|
||||
origin: EntityDict['smsTemplate']['Schema']['origin'];
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BRC<ED>): Promise<void>;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,13 @@ exports.syncSmsTemplate = void 0;
|
|||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||||
const index_1 = require("../utils/sms/index");
|
||||
async function syncSmsTemplate(params, context) {
|
||||
const { origin, systemId } = params;
|
||||
const { origin, systemId, pageIndex, pageSize } = params;
|
||||
const Sms = (0, index_1.getSms)(origin);
|
||||
const templateFormalData = await Sms.syncTemplate(systemId, context);
|
||||
const templateFormalData = await Sms.syncTemplate({
|
||||
systemId: systemId,
|
||||
pageIndex,
|
||||
pageSize
|
||||
}, context);
|
||||
const existTemplateList = await context.select('smsTemplate', {
|
||||
data: {
|
||||
id: 1,
|
||||
|
|
|
|||
|
|
@ -1,28 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.setUpTokenAndUser = setUpTokenAndUser;
|
||||
exports.loadTokenInfo = loadTokenInfo;
|
||||
exports.loginByMobile = loginByMobile;
|
||||
exports.verifyPassword = verifyPassword;
|
||||
exports.loginByAccount = loginByAccount;
|
||||
exports.loginByEmail = loginByEmail;
|
||||
exports.bindByMobile = bindByMobile;
|
||||
exports.bindByEmail = bindByEmail;
|
||||
exports.setUserAvatarFromWechat = setUserAvatarFromWechat;
|
||||
exports.refreshWechatPublicUserInfo = refreshWechatPublicUserInfo;
|
||||
exports.loginByWechat = loginByWechat;
|
||||
exports.loginWechatNative = loginWechatNative;
|
||||
exports.loginWechat = loginWechat;
|
||||
exports.loginWechatMp = loginWechatMp;
|
||||
exports.syncUserInfoWechatMp = syncUserInfoWechatMp;
|
||||
exports.sendCaptchaByMobile = sendCaptchaByMobile;
|
||||
exports.sendCaptchaByEmail = sendCaptchaByEmail;
|
||||
exports.switchTo = switchTo;
|
||||
exports.getWechatMpUserPhoneNumber = getWechatMpUserPhoneNumber;
|
||||
exports.logout = logout;
|
||||
exports.wakeupParasite = wakeupParasite;
|
||||
exports.refreshToken = refreshToken;
|
||||
exports.loginWebByMpToken = loginWebByMpToken;
|
||||
exports.loginWebByMpToken = exports.refreshToken = exports.wakeupParasite = exports.logout = exports.getWechatMpUserPhoneNumber = exports.switchTo = exports.sendCaptchaByEmail = exports.sendCaptchaByMobile = exports.syncUserInfoWechatMp = exports.loginWechatMp = exports.loginWechat = exports.loginWechatNative = exports.loginByWechat = exports.refreshWechatPublicUserInfo = exports.setUserAvatarFromWechat = exports.bindByEmail = exports.bindByMobile = exports.loginByEmail = exports.loginByAccount = exports.verifyPassword = exports.loginByMobile = exports.loadTokenInfo = exports.setUpTokenAndUser = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||||
const WechatSDK_1 = tslib_1.__importDefault(require("oak-external-sdk/lib/WechatSDK"));
|
||||
|
|
@ -402,6 +380,7 @@ createData, user) {
|
|||
}
|
||||
}
|
||||
}
|
||||
exports.setUpTokenAndUser = setUpTokenAndUser;
|
||||
async function setupMobile(mobile, env, context) {
|
||||
const result2 = await context.select('mobile', {
|
||||
data: {
|
||||
|
|
@ -465,6 +444,7 @@ async function loadTokenInfo(tokenValue, context) {
|
|||
},
|
||||
}, {});
|
||||
}
|
||||
exports.loadTokenInfo = loadTokenInfo;
|
||||
async function loginByMobile(params, context) {
|
||||
const { mobile, captcha, env, disableRegister } = params;
|
||||
const loginLogic = async (isRoot) => {
|
||||
|
|
@ -560,6 +540,7 @@ async function loginByMobile(params, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginByMobile = loginByMobile;
|
||||
async function verifyPassword(params, context) {
|
||||
const { password } = params;
|
||||
const systemId = context.getSystemId();
|
||||
|
|
@ -624,6 +605,7 @@ async function verifyPassword(params, context) {
|
|||
}
|
||||
}, {});
|
||||
}
|
||||
exports.verifyPassword = verifyPassword;
|
||||
async function loginByAccount(params, context) {
|
||||
const { account, password, env } = params;
|
||||
let needUpdatePassword = false;
|
||||
|
|
@ -976,6 +958,7 @@ async function loginByAccount(params, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginByAccount = loginByAccount;
|
||||
async function loginByEmail(params, context) {
|
||||
const { email, captcha, env, disableRegister } = params;
|
||||
const loginLogic = async () => {
|
||||
|
|
@ -1046,6 +1029,7 @@ async function loginByEmail(params, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginByEmail = loginByEmail;
|
||||
async function bindByMobile(params, context) {
|
||||
const { mobile, captcha, env, } = params;
|
||||
const userId = context.getCurrentUserId();
|
||||
|
|
@ -1157,6 +1141,7 @@ async function bindByMobile(params, context) {
|
|||
await bindLogic();
|
||||
closeRootMode();
|
||||
}
|
||||
exports.bindByMobile = bindByMobile;
|
||||
async function bindByEmail(params, context) {
|
||||
const { email, captcha, env, } = params;
|
||||
const userId = context.getCurrentUserId();
|
||||
|
|
@ -1269,6 +1254,7 @@ async function bindByEmail(params, context) {
|
|||
await bindLogic();
|
||||
closeRootMode();
|
||||
}
|
||||
exports.bindByEmail = bindByEmail;
|
||||
async function setupLoginName(name, env, context) {
|
||||
const result2 = await context.select('loginName', {
|
||||
data: {
|
||||
|
|
@ -1509,6 +1495,7 @@ async function setUserAvatarFromWechat(params, context) {
|
|||
}, {});
|
||||
}
|
||||
}
|
||||
exports.setUserAvatarFromWechat = setUserAvatarFromWechat;
|
||||
async function tryRefreshWechatPublicUserInfo(wechatUserId, context) {
|
||||
const [wechatUser] = await context.select('wechatUser', {
|
||||
data: {
|
||||
|
|
@ -1611,6 +1598,7 @@ async function refreshWechatPublicUserInfo({}, context) {
|
|||
(0, assert_1.assert)(token.entityId);
|
||||
return await tryRefreshWechatPublicUserInfo(token.entityId, context);
|
||||
}
|
||||
exports.refreshWechatPublicUserInfo = refreshWechatPublicUserInfo;
|
||||
// 用户在微信端授权登录后,在web端触发该方法
|
||||
async function loginByWechat(params, context) {
|
||||
const { wechatLoginId, env } = params;
|
||||
|
|
@ -1640,6 +1628,7 @@ async function loginByWechat(params, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginByWechat = loginByWechat;
|
||||
async function loginFromWechatEnv(code, env, context, wechatLoginId) {
|
||||
const application = context.getApplication();
|
||||
const { type, config, systemId } = application;
|
||||
|
|
@ -1984,6 +1973,7 @@ async function loginWechatNative({ code, env, }, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginWechatNative = loginWechatNative;
|
||||
/**
|
||||
* 公众号授权登录
|
||||
* @param param0
|
||||
|
|
@ -2014,6 +2004,7 @@ async function loginWechat({ code, env, wechatLoginId, }, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginWechat = loginWechat;
|
||||
/**
|
||||
* 小程序授权登录
|
||||
* @param param0
|
||||
|
|
@ -2027,6 +2018,7 @@ async function loginWechatMp({ code, env, }, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginWechatMp = loginWechatMp;
|
||||
/**
|
||||
* 同步从wx.getUserProfile拿到的用户信息
|
||||
* @param param0
|
||||
|
|
@ -2080,6 +2072,7 @@ async function syncUserInfoWechatMp({ nickname, avatarUrl, encryptedData, iv, si
|
|||
// 实测发现解密出来的和userInfo完全一致……
|
||||
await setUserInfoFromWechat(user, { nickname, avatar: avatarUrl }, context);
|
||||
}
|
||||
exports.syncUserInfoWechatMp = syncUserInfoWechatMp;
|
||||
async function sendCaptchaByMobile({ mobile, env, type: captchaType, }, context) {
|
||||
const { type } = env;
|
||||
let visitorId = mobile;
|
||||
|
|
@ -2253,6 +2246,7 @@ async function sendCaptchaByMobile({ mobile, env, type: captchaType, }, context)
|
|||
return '验证码发送失败';
|
||||
}
|
||||
}
|
||||
exports.sendCaptchaByMobile = sendCaptchaByMobile;
|
||||
async function sendCaptchaByEmail({ email, env, type: captchaType, }, context) {
|
||||
const { type } = env;
|
||||
let visitorId = email;
|
||||
|
|
@ -2405,6 +2399,7 @@ async function sendCaptchaByEmail({ email, env, type: captchaType, }, context) {
|
|||
return '验证码发送失败';
|
||||
}
|
||||
}
|
||||
exports.sendCaptchaByEmail = sendCaptchaByEmail;
|
||||
async function switchTo({ userId }, context) {
|
||||
const reallyRoot = context.isReallyRoot();
|
||||
if (!reallyRoot) {
|
||||
|
|
@ -2426,6 +2421,7 @@ async function switchTo({ userId }, context) {
|
|||
},
|
||||
}, {});
|
||||
}
|
||||
exports.switchTo = switchTo;
|
||||
async function getWechatMpUserPhoneNumber({ code, env }, context) {
|
||||
const application = context.getApplication();
|
||||
const { type, config, systemId } = application;
|
||||
|
|
@ -2441,6 +2437,7 @@ async function getWechatMpUserPhoneNumber({ code, env }, context) {
|
|||
closeRootMode();
|
||||
return reuslt;
|
||||
}
|
||||
exports.getWechatMpUserPhoneNumber = getWechatMpUserPhoneNumber;
|
||||
async function logout(params, context) {
|
||||
const { tokenValue } = params;
|
||||
if (tokenValue) {
|
||||
|
|
@ -2463,6 +2460,7 @@ async function logout(params, context) {
|
|||
closeRootMode();
|
||||
}
|
||||
}
|
||||
exports.logout = logout;
|
||||
/**
|
||||
* 创建一个当前parasite上的token
|
||||
* @param params
|
||||
|
|
@ -2529,6 +2527,7 @@ async function wakeupParasite(params, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.wakeupParasite = wakeupParasite;
|
||||
/**
|
||||
* todo 检查登录环境一致性,同一个token不能跨越不同设备
|
||||
* @param env1
|
||||
|
|
@ -2601,8 +2600,8 @@ async function refreshToken(params, context) {
|
|||
// 只有server模式去刷新token
|
||||
// 'development' | 'production' | 'staging'
|
||||
const intervals = {
|
||||
development: 7200 * 1000, // 2小时
|
||||
staging: 600 * 1000, // 十分钟
|
||||
development: 7200 * 1000,
|
||||
staging: 600 * 1000,
|
||||
production: 600 * 1000, // 十分钟
|
||||
};
|
||||
let applicationId = token.applicationId;
|
||||
|
|
@ -2675,6 +2674,7 @@ async function refreshToken(params, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.refreshToken = refreshToken;
|
||||
/**
|
||||
* 使用微信小程序中的token登录web
|
||||
* @param tokenValue
|
||||
|
|
@ -2742,3 +2742,4 @@ async function loginWebByMpToken(params, context) {
|
|||
closeRootMode();
|
||||
return tokenValue;
|
||||
}
|
||||
exports.loginWebByMpToken = loginWebByMpToken;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
"use strict";
|
||||
// import { registerMessageNotificationConverters } from './triggers/message';
|
||||
// import { registerWeChatPublicEventCallback } from './endpoints';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./types/Exception"), exports);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,6 @@ registerNotificationHandler,
|
|||
* 例如: 在其他渠道失败后自动发送短信通知
|
||||
*/
|
||||
registerNotificationFailureHandler, } from './utils/notification';
|
||||
export { registSms, } from './utils/sms';
|
||||
export { registerSms, } from './utils/sms';
|
||||
export { registerCosBackend, } from './utils/cos/index.backend';
|
||||
export { registerOauthUserinfoHandler, } from './utils/oauth/index';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* 如需要注入,请在routine中编写注册逻辑,使用此处提供的注册方法进行注册
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.registerOauthUserinfoHandler = exports.registerCosBackend = exports.registSms = exports.registerNotificationFailureHandler = exports.registerNotificationHandler = exports.registerMessageHandler = exports.registerMessageNotificationConverters = exports.registerWeChatPublicEventCallback = exports.registerMessageType = void 0;
|
||||
exports.registerOauthUserinfoHandler = exports.registerCosBackend = exports.registerSms = exports.registerNotificationFailureHandler = exports.registerNotificationHandler = exports.registerMessageHandler = exports.registerMessageNotificationConverters = exports.registerWeChatPublicEventCallback = exports.registerMessageType = void 0;
|
||||
var template_1 = require("./aspects/template");
|
||||
/**
|
||||
* 注册消息类型
|
||||
|
|
@ -42,7 +42,7 @@ Object.defineProperty(exports, "registerNotificationHandler", { enumerable: true
|
|||
Object.defineProperty(exports, "registerNotificationFailureHandler", { enumerable: true, get: function () { return notification_1.registerNotificationFailureHandler; } });
|
||||
var sms_1 = require("./utils/sms");
|
||||
// 注册短信服务商实现
|
||||
Object.defineProperty(exports, "registSms", { enumerable: true, get: function () { return sms_1.registSms; } });
|
||||
Object.defineProperty(exports, "registerSms", { enumerable: true, get: function () { return sms_1.registerSms; } });
|
||||
var index_backend_1 = require("./utils/cos/index.backend");
|
||||
// 注册对象存储服务商实现(后端)
|
||||
Object.defineProperty(exports, "registerCosBackend", { enumerable: true, get: function () { return index_backend_1.registerCosBackend; } });
|
||||
|
|
|
|||
|
|
@ -8,11 +8,19 @@ export default interface Sms<ED extends EntityDict> {
|
|||
/**
|
||||
* 是否支持模板同步
|
||||
*/
|
||||
syncTemplate(systemId: string, context: BRC<ED>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
international?: 0 | 1;
|
||||
}, context: BRC<ED>): Promise<{
|
||||
templateName: string;
|
||||
templateCode: string;
|
||||
templateContent: string;
|
||||
}[]>;
|
||||
/**
|
||||
* 短信发送
|
||||
*/
|
||||
sendSms(params: {
|
||||
mobile: string;
|
||||
templateParam?: Record<string, any>;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,4 @@ export declare function getOrigin(): string[];
|
|||
export declare function sendEmail<ED extends EntityDict>(options: EmailOptions, context: BRC<ED>): Promise<{
|
||||
success: boolean;
|
||||
error?: string | undefined;
|
||||
} | {
|
||||
success: boolean;
|
||||
error: unknown;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.registerEmail = registerEmail;
|
||||
exports.getEmail = getEmail;
|
||||
exports.getOrigin = getOrigin;
|
||||
exports.sendEmail = sendEmail;
|
||||
exports.sendEmail = exports.getOrigin = exports.getEmail = exports.registerEmail = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const assert_1 = require("oak-domain/lib/utils/assert");
|
||||
const node_mailer_1 = tslib_1.__importDefault(require("./node-mailer"));
|
||||
|
|
@ -18,13 +15,16 @@ function registerEmail(clazz) {
|
|||
const instance = new clazz();
|
||||
EmailDict[instance.name] = instance;
|
||||
}
|
||||
exports.registerEmail = registerEmail;
|
||||
function getEmail(origin) {
|
||||
(0, assert_1.assert)(EmailDict.hasOwnProperty(origin));
|
||||
return EmailDict[origin];
|
||||
}
|
||||
exports.getEmail = getEmail;
|
||||
function getOrigin() {
|
||||
return Object.keys(EmailDict);
|
||||
}
|
||||
exports.getOrigin = getOrigin;
|
||||
async function sendEmail(options, context) {
|
||||
try {
|
||||
const instance = getEmail('nodemailer');
|
||||
|
|
@ -34,7 +34,8 @@ async function sendEmail(options, context) {
|
|||
catch (err) {
|
||||
return {
|
||||
success: false,
|
||||
error: err,
|
||||
error: err?.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.sendEmail = sendEmail;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export default class Nodemailer implements Email<EntityDict> {
|
|||
error?: undefined;
|
||||
} | {
|
||||
success: boolean;
|
||||
error: any;
|
||||
error: string | undefined;
|
||||
info?: undefined;
|
||||
}>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ const wechatMpHandler = async (notification, context) => {
|
|||
action: 'fail',
|
||||
data: {
|
||||
data2: {
|
||||
res: err.message
|
||||
res: err?.message
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ const wechatPublicHandler = async (notification, context) => {
|
|||
action: 'fail',
|
||||
data: {
|
||||
data2: {
|
||||
res: err.message
|
||||
res: err?.message
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ export default class Ali implements Sms<EntityDict> {
|
|||
config: AliSmsConfig;
|
||||
mockSend: boolean | undefined;
|
||||
}>;
|
||||
syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
templateCode: string;
|
||||
templateName: string;
|
||||
templateContent: string;
|
||||
|
|
|
|||
|
|
@ -37,13 +37,14 @@ class Ali {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId, context) {
|
||||
async syncTemplate(options, context) {
|
||||
const { systemId, pageIndex, pageSize } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { accessKeyId, accessKeySecret, endpoint, apiVersion } = config;
|
||||
const aliInstance = SmsSdk_1.default.getInstance('ali', accessKeyId, accessKeySecret, endpoint, undefined, apiVersion);
|
||||
const result = await aliInstance.syncTemplate({
|
||||
pageIndex: 1,
|
||||
pageSize: 50
|
||||
pageIndex: pageIndex || 1,
|
||||
pageSize: pageSize || 50
|
||||
});
|
||||
const { smsTemplateList } = result;
|
||||
if (smsTemplateList) {
|
||||
|
|
@ -67,7 +68,7 @@ class Ali {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await aliInstance.sendSms({
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ export default class CTYun implements Sms<EntityDict> {
|
|||
config: CTYunSmsConfig;
|
||||
mockSend: boolean | undefined;
|
||||
}>;
|
||||
syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
}, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
templateCode: string;
|
||||
templateName: string;
|
||||
templateContent: string;
|
||||
|
|
|
|||
|
|
@ -35,13 +35,14 @@ class CTYun {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId, context) {
|
||||
async syncTemplate(options, context) {
|
||||
const { systemId, pageIndex, pageSize } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { accessKey, securityKey, endpoint } = config;
|
||||
const ctyunInstance = SmsSdk_1.default.getInstance('ctyun', accessKey, securityKey, endpoint);
|
||||
const result = await ctyunInstance.syncTemplate({
|
||||
pageIndex: 1,
|
||||
pageSize: 50, // pageSize必须小于或等于50
|
||||
pageIndex: pageIndex || 1,
|
||||
pageSize: pageSize || 50, // pageSize必须小于或等于50
|
||||
});
|
||||
const { data } = result;
|
||||
if (data) {
|
||||
|
|
@ -65,7 +66,7 @@ class CTYun {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await ctyunInstance.sendSms({
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import Sms from '../../types/Sms';
|
|||
* 注入一个其它发送短信类
|
||||
* @param clazz
|
||||
*/
|
||||
export declare function registSms<ED extends EntityDict>(clazz: new () => Sms<ED>): void;
|
||||
export declare function registerSms<ED extends EntityDict>(clazz: new () => Sms<ED>): void;
|
||||
export declare function getSms<ED extends EntityDict>(origin: string): Sms<ED>;
|
||||
export declare function getOrigin(): string[];
|
||||
export declare function sendSms<ED extends EntityDict>(options: {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.registSms = registSms;
|
||||
exports.getSms = getSms;
|
||||
exports.getOrigin = getOrigin;
|
||||
exports.sendSms = sendSms;
|
||||
exports.sendSms = exports.getOrigin = exports.getSms = exports.registerSms = void 0;
|
||||
const assert_1 = require("oak-domain/lib/utils/assert");
|
||||
const SmsDict = {};
|
||||
/**
|
||||
* 注入一个其它发送短信类
|
||||
* @param clazz
|
||||
*/
|
||||
function registSms(clazz) {
|
||||
function registerSms(clazz) {
|
||||
const instance = new clazz();
|
||||
SmsDict[instance.name] = instance;
|
||||
}
|
||||
exports.registerSms = registerSms;
|
||||
function getSms(origin) {
|
||||
(0, assert_1.assert)(SmsDict.hasOwnProperty(origin));
|
||||
return SmsDict[origin];
|
||||
}
|
||||
exports.getSms = getSms;
|
||||
function getOrigin() {
|
||||
return Object.keys(SmsDict);
|
||||
}
|
||||
exports.getOrigin = getOrigin;
|
||||
async function sendSms(options, context) {
|
||||
const { messageType, origin, templateName, mobile, templateParam } = options;
|
||||
(0, assert_1.assert)(messageType || (origin && templateName));
|
||||
|
|
@ -40,7 +40,7 @@ async function sendSms(options, context) {
|
|||
if (!smsTemplate) {
|
||||
return {
|
||||
success: false,
|
||||
res: `${origin}渠道的${templateName}短信模板未配置`,
|
||||
res: `${origin}短信渠道未配置「${templateName}」模板`,
|
||||
};
|
||||
}
|
||||
try {
|
||||
|
|
@ -55,7 +55,7 @@ async function sendSms(options, context) {
|
|||
catch (err) {
|
||||
return {
|
||||
success: false,
|
||||
res: err,
|
||||
res: err?.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -103,14 +103,14 @@ async function sendSms(options, context) {
|
|||
}
|
||||
catch (err) {
|
||||
Object.assign(resList, {
|
||||
[messageTypeSmsTemplate.template.origin]: err,
|
||||
[messageTypeSmsTemplate.template.origin]: err?.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
res: {
|
||||
message: '所有短信渠道均发送失败',
|
||||
message: `所有短信渠道发送「${messageType}」模板均失败`,
|
||||
errorList: resList,
|
||||
},
|
||||
};
|
||||
|
|
@ -118,8 +118,9 @@ async function sendSms(options, context) {
|
|||
else {
|
||||
return {
|
||||
success: false,
|
||||
res: `短信未配置${messageType}模板`,
|
||||
res: `所有短信渠道未配置「${messageType}」模板`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.sendSms = sendSms;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,12 @@ export default class Tencent implements Sms<EntityDict> {
|
|||
config: TencentSmsConfig;
|
||||
mockSend: boolean | undefined;
|
||||
}>;
|
||||
syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
syncTemplate(options: {
|
||||
systemId: string;
|
||||
pageIndex?: number;
|
||||
pageSize?: number;
|
||||
international?: number;
|
||||
}, context: BackendRuntimeContext<EntityDict>): Promise<{
|
||||
templateCode: string;
|
||||
templateName: string;
|
||||
templateContent: string;
|
||||
|
|
|
|||
|
|
@ -38,14 +38,15 @@ class Tencent {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId, context) {
|
||||
async syncTemplate(options, context) {
|
||||
const { systemId, pageIndex, pageSize, international } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { secretId, secretKey, region, endpoint } = config;
|
||||
const tencentInstance = SmsSdk_1.default.getInstance('tencent', secretId, secretKey, endpoint, region);
|
||||
const result = await tencentInstance.syncTemplate({
|
||||
International: 0,
|
||||
Limit: 100,
|
||||
Offset: 0,
|
||||
International: international || 0,
|
||||
Offset: pageIndex && pageIndex >= 1 ? pageIndex - 1 : 0,
|
||||
Limit: pageSize || 100,
|
||||
});
|
||||
const { DescribeTemplateStatusSet } = result;
|
||||
if (DescribeTemplateStatusSet) {
|
||||
|
|
@ -81,7 +82,7 @@ class Tencent {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await tencentInstance.sendSms({
|
||||
|
|
|
|||
|
|
@ -895,6 +895,8 @@ export type AspectDict<ED extends EntityDict> = {
|
|||
params: {
|
||||
systemId: string;
|
||||
origin: EntityDict['smsTemplate']['Schema']['origin'];
|
||||
pageIndex?: number,
|
||||
pageSize?: number
|
||||
},
|
||||
context: BackendRuntimeContext<ED>
|
||||
) => Promise<void>;
|
||||
|
|
|
|||
|
|
@ -8,14 +8,20 @@ export async function syncSmsTemplate<ED extends EntityDict>(
|
|||
params: {
|
||||
origin: EntityDict['smsTemplate']['Schema']['origin'];
|
||||
systemId: string;
|
||||
pageIndex?: number,
|
||||
pageSize?: number
|
||||
},
|
||||
context: BRC<ED>
|
||||
) {
|
||||
const { origin, systemId } = params;
|
||||
const { origin, systemId, pageIndex, pageSize } = params;
|
||||
const Sms = getSms(origin);
|
||||
const templateFormalData = await Sms.syncTemplate(
|
||||
systemId!,
|
||||
context as any
|
||||
{
|
||||
systemId: systemId!,
|
||||
pageIndex,
|
||||
pageSize
|
||||
},
|
||||
context as any,
|
||||
);
|
||||
const existTemplateList = await context.select(
|
||||
'smsTemplate',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
// import { registerMessageNotificationConverters } from './triggers/message';
|
||||
// import { registerWeChatPublicEventCallback } from './endpoints';
|
||||
|
||||
export type { FeatureDict } from './features';
|
||||
export type { AspectDict } from './aspects/AspectDict';
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ export {
|
|||
|
||||
export {
|
||||
// 注册短信服务商实现
|
||||
registSms,
|
||||
registerSms,
|
||||
} from './utils/sms';
|
||||
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -9,16 +9,27 @@ export default interface Sms<ED extends EntityDict> {
|
|||
/**
|
||||
* 是否支持模板同步
|
||||
*/
|
||||
syncTemplate(systemId: string, context: BRC<ED>): Promise<{
|
||||
syncTemplate(
|
||||
options: {
|
||||
systemId: string,
|
||||
pageIndex?: number, // 不传默认1
|
||||
pageSize?: number, // 不传默认50
|
||||
international?: 0 | 1, // 0:国内 1:国际 只对腾讯短信生效
|
||||
},
|
||||
context: BRC<ED>
|
||||
): Promise<{
|
||||
templateName: string,
|
||||
templateCode: string,
|
||||
templateContent: string
|
||||
}[]>;
|
||||
sendSms(params: {
|
||||
|
||||
/**
|
||||
* 短信发送
|
||||
*/
|
||||
sendSms(
|
||||
params: {
|
||||
mobile: string,
|
||||
templateParam?: Record<string, any>,
|
||||
smsTemplate: Partial<ED['smsTemplate']['Schema']>
|
||||
}, context: BRC<ED>): Promise<{ success: boolean, res: any }>;
|
||||
/**
|
||||
*/
|
||||
},context: BRC<ED>): Promise<{ success: boolean, res: any }>;
|
||||
}
|
||||
|
|
@ -35,10 +35,10 @@ export async function sendEmail<ED extends EntityDict>(
|
|||
const instance = getEmail<ED>('nodemailer');
|
||||
const result = await instance.sendEmail(options, context);
|
||||
return result;
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: err,
|
||||
error: err?.message as string | undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -99,13 +99,13 @@ export default class Nodemailer implements Email<EntityDict> {
|
|||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error?.message,
|
||||
error: error?.message as string | undefined,
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error?.message,
|
||||
error: error?.message as string | undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ import { EntityDict } from '../../oak-app-domain';
|
|||
import { BRC } from '../../types/RuntimeCxt';
|
||||
import { sendEmail } from '../email';
|
||||
import { NotificationHandler } from './index';
|
||||
import { EmailOptions } from '../../types/Email';
|
||||
|
||||
export const emailHandler: NotificationHandler = async (notification, context) => {
|
||||
const { data, id } = notification;
|
||||
|
||||
try {
|
||||
const result = await sendEmail(data as any, context);
|
||||
const result = await sendEmail(data as EmailOptions, context);
|
||||
if (result?.success) {
|
||||
await context.operate(
|
||||
'notification',
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ export const wechatMpHandler: NotificationHandler = async (notification, context
|
|||
action: 'fail',
|
||||
data: {
|
||||
data2: {
|
||||
res: err.message
|
||||
res: err?.message
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ export const wechatPublicHandler: NotificationHandler = async (notification, con
|
|||
action: 'fail',
|
||||
data: {
|
||||
data2: {
|
||||
res: err.message
|
||||
res: err?.message
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,12 @@ export default class Ali implements Sms<EntityDict> {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>) {
|
||||
async syncTemplate(options: {
|
||||
systemId: string,
|
||||
pageIndex?: number,
|
||||
pageSize?: number
|
||||
}, context: BackendRuntimeContext<EntityDict>) {
|
||||
const { systemId, pageIndex, pageSize } = options;
|
||||
const { config, mockSend } = await this.getConfig(
|
||||
context,
|
||||
systemId
|
||||
|
|
@ -58,8 +63,8 @@ export default class Ali implements Sms<EntityDict> {
|
|||
apiVersion
|
||||
) as AliSmsInstance;
|
||||
const result = await aliInstance.syncTemplate({
|
||||
pageIndex: 1,
|
||||
pageSize: 50
|
||||
pageIndex: pageIndex || 1,
|
||||
pageSize: pageSize || 50
|
||||
});
|
||||
|
||||
const { smsTemplateList } = result;
|
||||
|
|
@ -96,7 +101,7 @@ export default class Ali implements Sms<EntityDict> {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await aliInstance.sendSms({
|
||||
|
|
|
|||
|
|
@ -45,7 +45,12 @@ export default class CTYun implements Sms<EntityDict> {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>) {
|
||||
async syncTemplate(options: {
|
||||
systemId: string,
|
||||
pageIndex?: number,
|
||||
pageSize?: number
|
||||
}, context: BackendRuntimeContext<EntityDict>) {
|
||||
const { systemId, pageIndex, pageSize } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { accessKey, securityKey, endpoint } = config;
|
||||
const ctyunInstance = SDK.getInstance(
|
||||
|
|
@ -55,8 +60,8 @@ export default class CTYun implements Sms<EntityDict> {
|
|||
endpoint
|
||||
) as CTYunSmsInstance;
|
||||
const result = await ctyunInstance.syncTemplate({
|
||||
pageIndex: 1,
|
||||
pageSize: 50, // pageSize必须小于或等于50
|
||||
pageIndex: pageIndex || 1,
|
||||
pageSize: pageSize || 50, // pageSize必须小于或等于50
|
||||
});
|
||||
|
||||
const { data } = result;
|
||||
|
|
@ -97,7 +102,7 @@ export default class CTYun implements Sms<EntityDict> {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const SmsDict: Record<string, any> = {
|
|||
* 注入一个其它发送短信类
|
||||
* @param clazz
|
||||
*/
|
||||
export function registSms<ED extends EntityDict>(clazz: new () => Sms<ED>) {
|
||||
export function registerSms<ED extends EntityDict>(clazz: new () => Sms<ED>) {
|
||||
const instance = new clazz();
|
||||
SmsDict[instance.name] = instance;
|
||||
}
|
||||
|
|
@ -36,8 +36,7 @@ export async function sendSms<ED extends EntityDict>(
|
|||
},
|
||||
context: BRC<ED>
|
||||
) {
|
||||
const { messageType, origin, templateName, mobile, templateParam } =
|
||||
options;
|
||||
const { messageType, origin, templateName, mobile, templateParam } = options;
|
||||
assert(messageType || (origin && templateName));
|
||||
if (origin && templateName) {
|
||||
const [smsTemplate] = await context.select(
|
||||
|
|
@ -59,7 +58,7 @@ export async function sendSms<ED extends EntityDict>(
|
|||
if (!smsTemplate) {
|
||||
return {
|
||||
success: false,
|
||||
res: `${origin}渠道的${templateName}短信模板未配置`,
|
||||
res: `${origin}短信渠道未配置「${templateName}」模板`,
|
||||
};
|
||||
}
|
||||
try {
|
||||
|
|
@ -73,10 +72,10 @@ export async function sendSms<ED extends EntityDict>(
|
|||
context
|
||||
);
|
||||
return result;
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
return {
|
||||
success: false,
|
||||
res: err,
|
||||
res: err?.message,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
|
|
@ -129,23 +128,23 @@ export async function sendSms<ED extends EntityDict>(
|
|||
res: resList,
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
Object.assign(resList, {
|
||||
[messageTypeSmsTemplate.template!.origin!]: err,
|
||||
[messageTypeSmsTemplate.template!.origin!]: err?.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
res: {
|
||||
message: '所有短信渠道均发送失败',
|
||||
message: `所有短信渠道发送「${messageType}」模板均失败`,
|
||||
errorList: resList,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
res: `短信未配置${messageType}模板`,
|
||||
res: `所有短信渠道未配置「${messageType}」模板`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,13 @@ export default class Tencent implements Sms<EntityDict> {
|
|||
mockSend
|
||||
};
|
||||
}
|
||||
async syncTemplate(systemId: string, context: BackendRuntimeContext<EntityDict>) {
|
||||
async syncTemplate(options: {
|
||||
systemId: string,
|
||||
pageIndex?: number,
|
||||
pageSize?: number,
|
||||
international?: number,
|
||||
}, context: BackendRuntimeContext<EntityDict>) {
|
||||
const { systemId, pageIndex, pageSize, international } = options;
|
||||
const { config, mockSend } = await this.getConfig(context, systemId);
|
||||
const { secretId, secretKey, region, endpoint } = config;
|
||||
const tencentInstance = SDK.getInstance(
|
||||
|
|
@ -56,9 +62,9 @@ export default class Tencent implements Sms<EntityDict> {
|
|||
region
|
||||
) as TencentSmsInstance;
|
||||
const result = await tencentInstance.syncTemplate({
|
||||
International: 0,
|
||||
Limit: 100,
|
||||
Offset: 0,
|
||||
International: international || 0,
|
||||
Offset: pageIndex && pageIndex >= 1 ? pageIndex - 1 : 0,
|
||||
Limit: pageSize || 100,
|
||||
})
|
||||
const { DescribeTemplateStatusSet } = result;
|
||||
if (DescribeTemplateStatusSet) {
|
||||
|
|
@ -108,7 +114,7 @@ export default class Tencent implements Sms<EntityDict> {
|
|||
console.log(`当前模拟发送短信,不会实际调用API`);
|
||||
return {
|
||||
success: true,
|
||||
res: '模拟发送短信成功',
|
||||
res: '模拟短信发送成功',
|
||||
};
|
||||
}
|
||||
const result = await tencentInstance.sendSms({
|
||||
|
|
|
|||
Loading…
Reference in New Issue