mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-06 22:19:25 +08:00
* feat(plugin-verification): add client config * feat(plugin-verification): add config ui * fix(plugin-verification): fix schema * refactor(plugin-verification): add default for verification providers * fix(plugin-users): fix initVerification in lifecycle * fix(plugin-users): fix initVerification in lifecycle * fix(plugin-verification): fix locale and default provider * fix(plugin-verification): fix test case * fix(plugin-verification): fix locale
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import DysmsApi, { SendSmsRequest } from '@alicloud/dysmsapi20170525';
|
|
import * as OpenApi from '@alicloud/openapi-client';
|
|
import { RuntimeOptions } from '@alicloud/tea-util';
|
|
|
|
import { Provider } from '.';
|
|
|
|
|
|
export default class extends Provider {
|
|
client: DysmsApi;
|
|
|
|
constructor(plugin, options) {
|
|
super(plugin, options);
|
|
|
|
const { accessKeyId, accessKeySecret, endpoint } = this.options;
|
|
|
|
let config = new OpenApi.Config({
|
|
// 您的 AccessKey ID
|
|
accessKeyId: accessKeyId,
|
|
// 您的 AccessKey Secret
|
|
accessKeySecret: accessKeySecret,
|
|
});
|
|
// 访问的域名
|
|
config.endpoint = endpoint;
|
|
|
|
this.client = new DysmsApi(config);
|
|
}
|
|
|
|
async send(phoneNumbers, data = {}) {
|
|
const request = new SendSmsRequest({
|
|
phoneNumbers,
|
|
signName: this.options.sign,
|
|
templateCode: this.options.template,
|
|
templateParam: JSON.stringify(data)
|
|
});
|
|
|
|
try {
|
|
const { body } = await this.client.sendSmsWithOptions(request, new RuntimeOptions({}));
|
|
let err = new Error(body.message);
|
|
switch (body.code) {
|
|
case 'OK':
|
|
break;
|
|
|
|
case 'isv.MOBILE_NUMBER_ILLEGAL':
|
|
err.name = 'InvalidReceiver';
|
|
return Promise.reject(err);
|
|
|
|
case 'isv.BUSINESS_LIMIT_CONTROL':
|
|
err.name = 'RateLimit';
|
|
console.error(body);
|
|
return Promise.reject(err);
|
|
|
|
// case 'isp.RAM_PERMISSION_DENY':
|
|
default:
|
|
// should not let user to know
|
|
console.error(body);
|
|
err.name = 'SendSMSFailed';
|
|
return Promise.reject(err);
|
|
}
|
|
} catch (error) {
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
}
|