This commit is contained in:
wenjiarui 2023-11-30 18:10:52 +08:00
parent 2aba9ccf55
commit 87f05426ab
11 changed files with 95 additions and 70 deletions

View File

@ -1,11 +1,11 @@
import Dysmsapi20170525, * as $Dysmsapi20170525 from '@alicloud/dysmsapi20170525';
type SendSmsRequest = {
PhoneNumbers: string[];
TemplateCode: string;
SignName: string;
TemplateParam?: Record<string, string>;
SmsUpExtendCode?: string;
OutId?: string;
phoneNumbers: string[];
templateCode: string;
signName: string;
templateParam?: Record<string, string>;
smsUpExtendCode?: string;
outId?: string;
};
export declare class AliSmsInstance {
accessKeyId: string;
@ -13,6 +13,6 @@ export declare class AliSmsInstance {
endpoint: string;
client: Dysmsapi20170525;
constructor(accessKeyId: string, accessKeySecret: string, endpoint?: string);
sendSms(params: SendSmsRequest): Promise<$Dysmsapi20170525.SendSmsResponse>;
sendSms(params: SendSmsRequest): Promise<$Dysmsapi20170525.SendSmsResponseBody>;
}
export {};

View File

@ -20,16 +20,20 @@ export class AliSmsInstance {
this.client = new Dysmsapi20170525(config);
}
async sendSms(params) {
const { PhoneNumbers, TemplateParam = {}, TemplateCode, SignName, } = params;
const { phoneNumbers, templateParam = {}, templateCode, signName, } = params;
let sendSmsRequest = new $Dysmsapi20170525.SendSmsRequest({
PhoneNumbers: PhoneNumbers.join(','),
TemplateParam: JSON.stringify(TemplateParam),
TemplateCode: TemplateCode,
SignName: SignName,
phoneNumbers: (phoneNumbers instanceof Array) ? phoneNumbers.join(',') : phoneNumbers,
templateParam: JSON.stringify(templateParam),
templateCode: templateCode,
signName: signName,
});
try {
const data = await this.client.sendSmsWithOptions(sendSmsRequest, new $Util.RuntimeOptions({}));
return data;
const { statusCode, body } = data;
if (statusCode != 200) {
throw new Error(`ali.sendSms接口返回状态码错误${statusCode}`);
}
return body;
}
catch (error) {
throw error;

View File

@ -1,5 +1,5 @@
import { Client } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_client';
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
import { SendSmsRequest, SendSmsResponse, DescribeSmsTemplateListRequest, DescribeSmsTemplateListResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
export declare class TencentSmsInstance {
secretId: string;
secretKey: string;
@ -8,4 +8,5 @@ export declare class TencentSmsInstance {
client: Client;
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
syncTemplate(params: DescribeSmsTemplateListRequest): Promise<DescribeSmsTemplateListResponse>;
}

View File

@ -27,15 +27,19 @@ export class TencentSmsInstance {
this.client = new SmsClient(clientConfig);
}
async sendSms(params) {
// const params: SendSmsRequest = {
// PhoneNumberSet: [],
// TemplateParamSet: [],
// SmsSdkAppId: '',
// TemplateId: '',
// };
try {
const data = await this.client.SendSms(params);
return data;
const result = await this.client.SendSms(params);
return result;
}
catch (err) {
console.error(err);
throw err;
}
}
async syncTemplate(params) {
try {
const result = await this.client.DescribeSmsTemplateList(params);
return result;
}
catch (err) {
console.error(err);

View File

@ -1,11 +1,11 @@
import Dysmsapi20170525, * as $Dysmsapi20170525 from '@alicloud/dysmsapi20170525';
type SendSmsRequest = {
PhoneNumbers: string[];
TemplateCode: string;
SignName: string;
TemplateParam?: Record<string, string>;
SmsUpExtendCode?: string;
OutId?: string;
phoneNumbers: string[];
templateCode: string;
signName: string;
templateParam?: Record<string, string>;
smsUpExtendCode?: string;
outId?: string;
};
export declare class AliSmsInstance {
accessKeyId: string;
@ -13,6 +13,6 @@ export declare class AliSmsInstance {
endpoint: string;
client: Dysmsapi20170525;
constructor(accessKeyId: string, accessKeySecret: string, endpoint?: string);
sendSms(params: SendSmsRequest): Promise<$Dysmsapi20170525.SendSmsResponse>;
sendSms(params: SendSmsRequest): Promise<$Dysmsapi20170525.SendSmsResponseBody>;
}
export {};

View File

@ -24,16 +24,20 @@ class AliSmsInstance {
this.client = new dysmsapi20170525_1.default(config);
}
async sendSms(params) {
const { PhoneNumbers, TemplateParam = {}, TemplateCode, SignName, } = params;
const { phoneNumbers, templateParam = {}, templateCode, signName, } = params;
let sendSmsRequest = new $Dysmsapi20170525.SendSmsRequest({
PhoneNumbers: PhoneNumbers.join(','),
TemplateParam: JSON.stringify(TemplateParam),
TemplateCode: TemplateCode,
SignName: SignName,
phoneNumbers: (phoneNumbers instanceof Array) ? phoneNumbers.join(',') : phoneNumbers,
templateParam: JSON.stringify(templateParam),
templateCode: templateCode,
signName: signName,
});
try {
const data = await this.client.sendSmsWithOptions(sendSmsRequest, new $Util.RuntimeOptions({}));
return data;
const { statusCode, body } = data;
if (statusCode != 200) {
throw new Error(`ali.sendSms接口返回状态码错误${statusCode}`);
}
return body;
}
catch (error) {
throw error;

View File

@ -1,5 +1,5 @@
import { Client } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_client';
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
import { SendSmsRequest, SendSmsResponse, DescribeSmsTemplateListRequest, DescribeSmsTemplateListResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
export declare class TencentSmsInstance {
secretId: string;
secretKey: string;
@ -8,4 +8,5 @@ export declare class TencentSmsInstance {
client: Client;
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
syncTemplate(params: DescribeSmsTemplateListRequest): Promise<DescribeSmsTemplateListResponse>;
}

View File

@ -30,15 +30,19 @@ class TencentSmsInstance {
this.client = new SmsClient(clientConfig);
}
async sendSms(params) {
// const params: SendSmsRequest = {
// PhoneNumberSet: [],
// TemplateParamSet: [],
// SmsSdkAppId: '',
// TemplateId: '',
// };
try {
const data = await this.client.SendSms(params);
return data;
const result = await this.client.SendSms(params);
return result;
}
catch (err) {
console.error(err);
throw err;
}
}
async syncTemplate(params) {
try {
const result = await this.client.DescribeSmsTemplateList(params);
return result;
}
catch (err) {
console.error(err);

View File

@ -31,7 +31,7 @@
"cheerio": "^1.0.0-rc.12",
"isomorphic-fetch": "^3.0.0",
"oak-domain": "file:../oak-domain",
"tencentcloud-sdk-nodejs": "^4.0.686",
"tencentcloud-sdk-nodejs": "^4.0.746",
"ts-md5": "^1.3.1"
}
}
}

View File

@ -4,12 +4,12 @@ import Util, * as $Util from '@alicloud/tea-util';
import * as $tea from '@alicloud/tea-typescript';
type SendSmsRequest = {
PhoneNumbers: string[];
TemplateCode: string;
SignName: string;
TemplateParam?: Record<string, string>;
SmsUpExtendCode?: string;
OutId?: string;
phoneNumbers: string[];
templateCode: string;
signName: string;
templateParam?: Record<string, string>;
smsUpExtendCode?: string;
outId?: string;
};
type SendSmsResponse = {
@ -45,20 +45,24 @@ export class AliSmsInstance {
async sendSms(params: SendSmsRequest) {
const {
PhoneNumbers,
TemplateParam = {},
TemplateCode,
SignName,
phoneNumbers,
templateParam = {},
templateCode,
signName,
} = params;
let sendSmsRequest = new $Dysmsapi20170525.SendSmsRequest({
PhoneNumbers: PhoneNumbers.join(','),
TemplateParam: JSON.stringify(TemplateParam),
TemplateCode: TemplateCode,
SignName: SignName,
phoneNumbers: (phoneNumbers instanceof Array) ? phoneNumbers.join(',') : phoneNumbers,
templateParam: JSON.stringify(templateParam),
templateCode: templateCode,
signName: signName,
});
try {
const data = await this.client.sendSmsWithOptions(sendSmsRequest, new $Util.RuntimeOptions({}));
return data;
const { statusCode, body } = data;
if (statusCode != 200) {
throw new Error(`ali.sendSms接口返回状态码错误${statusCode}`);
}
return body;
} catch (error) {
throw error;
}

View File

@ -1,5 +1,5 @@
import { Client } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_client';
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
import { SendSmsRequest, SendSmsResponse, DescribeSmsTemplateListRequest, DescribeSmsTemplateListResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
const SmsClient = Client;
@ -39,15 +39,18 @@ export class TencentSmsInstance {
}
async sendSms(params: SendSmsRequest) {
// const params: SendSmsRequest = {
// PhoneNumberSet: [],
// TemplateParamSet: [],
// SmsSdkAppId: '',
// TemplateId: '',
// };
try {
const data: SendSmsResponse = await this.client.SendSms(params);
return data;
const result: SendSmsResponse = await this.client.SendSms(params);
return result;
} catch (err) {
console.error(err);
throw err;
}
}
async syncTemplate(params: DescribeSmsTemplateListRequest) {
try {
const result: DescribeSmsTemplateListResponse = await this.client.DescribeSmsTemplateList(params);
return result
} catch (err) {
console.error(err);
throw err;