@@ -1,6 +1,6 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
import DypnsClient, {
|
||||
import DypnsApiModule, {
|
||||
CheckSmsVerifyCodeRequest,
|
||||
SendSmsVerifyCodeRequest,
|
||||
} from '@alicloud/dypnsapi20170525';
|
||||
@@ -29,6 +29,30 @@ export type SmsVerificationService = {
|
||||
): Promise<void>;
|
||||
};
|
||||
|
||||
type DypnsClientInstance = InstanceType<typeof DypnsApiModule>;
|
||||
type DypnsClientConstructor = new (
|
||||
config: OpenApiClient.Config,
|
||||
) => DypnsClientInstance;
|
||||
|
||||
function resolveDypnsClientConstructor(): DypnsClientConstructor {
|
||||
const directExport = DypnsApiModule as unknown;
|
||||
if (typeof directExport === 'function') {
|
||||
return directExport as DypnsClientConstructor;
|
||||
}
|
||||
|
||||
// 兼容 CommonJS SDK 在 ESM/tsx 运行时被包一层 default 的情况。
|
||||
const nestedDefault = (
|
||||
DypnsApiModule as unknown as { default?: unknown }
|
||||
).default;
|
||||
if (typeof nestedDefault === 'function') {
|
||||
return nestedDefault as DypnsClientConstructor;
|
||||
}
|
||||
|
||||
throw new Error('阿里云短信 SDK Client 导出异常');
|
||||
}
|
||||
|
||||
const DypnsClient = resolveDypnsClientConstructor();
|
||||
|
||||
function isAliyunConfigMissing(config: AppConfig['smsAuth']) {
|
||||
return !config.accessKeyId || !config.accessKeySecret;
|
||||
}
|
||||
@@ -74,6 +98,7 @@ class AliyunSmsVerificationService implements SmsVerificationService {
|
||||
async sendLoginCode(phoneNumber: NormalizedPhoneNumber) {
|
||||
const templateParam = JSON.stringify({
|
||||
[this.config.templateParamKey]: '##code##',
|
||||
"min": this.config.validTimeSeconds,
|
||||
});
|
||||
const request = new SendSmsVerifyCodeRequest({
|
||||
phoneNumber: phoneNumber.nationalNumber,
|
||||
|
||||
Reference in New Issue
Block a user