😎优化短信发送相关接口服务
This commit is contained in:
parent
a72a4095e9
commit
1a37ffb853
@ -28,9 +28,9 @@
|
||||
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
|
||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.1" Aliases="BouncyCastleV2" />
|
||||
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="9.0.6" />
|
||||
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.7.81" />
|
||||
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.7.81" />
|
||||
<PackageReference Include="Furion.Pure" Version="4.9.7.81" />
|
||||
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.7.82" />
|
||||
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.7.82" />
|
||||
<PackageReference Include="Furion.Pure" Version="4.9.7.82" />
|
||||
<PackageReference Include="Hardware.Info" Version="101.0.1.1" />
|
||||
<PackageReference Include="Hashids.net" Version="1.7.0" />
|
||||
<PackageReference Include="IPTools.China" Version="1.6.0" />
|
||||
|
||||
@ -32,15 +32,16 @@ public class SysSmsService : IDynamicApiController, ITransient
|
||||
/// 发送短信 📨
|
||||
/// </summary>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <param name="templateId">短信模板id</param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[DisplayName("发送短信")]
|
||||
public async Task SendSms([Required] string phoneNumber)
|
||||
public async Task SendSms([Required] string phoneNumber, string templateId = "0")
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_smsOptions.Aliyun.AccessKeyId) && !string.IsNullOrWhiteSpace(_smsOptions.Aliyun.AccessKeySecret))
|
||||
await AliyunSendSms(phoneNumber);
|
||||
await AliyunSendSms(phoneNumber, templateId);
|
||||
else
|
||||
await TencentSendSms(phoneNumber);
|
||||
await TencentSendSms(phoneNumber, templateId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -62,11 +63,12 @@ public class SysSmsService : IDynamicApiController, ITransient
|
||||
/// <summary>
|
||||
/// 阿里云发送短信 📨
|
||||
/// </summary>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <param name="phoneNumber">手机号</param>
|
||||
/// <param name="templateId">短信模板id</param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[DisplayName("阿里云发送短信")]
|
||||
public async Task AliyunSendSms([Required] string phoneNumber)
|
||||
public async Task AliyunSendSms([Required] string phoneNumber, string templateId = "0")
|
||||
{
|
||||
if (!phoneNumber.TryValidate(ValidationTypes.PhoneNumber).IsValid) throw Oops.Oh("请正确填写手机号码");
|
||||
|
||||
@ -80,7 +82,7 @@ public class SysSmsService : IDynamicApiController, ITransient
|
||||
};
|
||||
|
||||
var client = CreateAliyunClient();
|
||||
var template = _smsOptions.Aliyun.GetTemplate();
|
||||
var template = _smsOptions.Aliyun.GetTemplate(templateId);
|
||||
var sendSmsRequest = new SendSmsRequest
|
||||
{
|
||||
PhoneNumbers = phoneNumber, // 待发送手机号, 多个以逗号分隔
|
||||
@ -142,10 +144,11 @@ public class SysSmsService : IDynamicApiController, ITransient
|
||||
/// 腾讯云发送短信 📨
|
||||
/// </summary>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <param name="templateId">短信模板id</param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[DisplayName("腾讯云发送短信")]
|
||||
public async Task TencentSendSms([Required] string phoneNumber)
|
||||
public async Task TencentSendSms([Required] string phoneNumber, string templateId = "0")
|
||||
{
|
||||
if (!phoneNumber.TryValidate(ValidationTypes.PhoneNumber).IsValid) throw Oops.Oh("请正确填写手机号码");
|
||||
|
||||
@ -155,7 +158,7 @@ public class SysSmsService : IDynamicApiController, ITransient
|
||||
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
var client = new SmsClient(CreateTencentClient(), "ap-guangzhou", new ClientProfile() { HttpProfile = new HttpProfile() { Endpoint = ("sms.tencentcloudapi.com") } });
|
||||
var template = _smsOptions.Tencentyun.GetTemplate();
|
||||
var template = _smsOptions.Tencentyun.GetTemplate(templateId);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
var req = new TencentCloud.Sms.V20190711.Models.SendSmsRequest
|
||||
{
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.14.0" />
|
||||
<PackageReference Include="Rezero.Api" Version="1.8.22" />
|
||||
<PackageReference Include="Rezero.Api" Version="1.8.23" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -29,17 +29,23 @@ export const SysSmsApiAxiosParamCreator = function (configuration?: Configuratio
|
||||
/**
|
||||
*
|
||||
* @summary 阿里云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} phoneNumber 手机号
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
apiSysSmsAliyunSendSmsPhoneNumberPost: async (phoneNumber: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost: async (phoneNumber: string, templateId: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'phoneNumber' is not null or undefined
|
||||
if (phoneNumber === null || phoneNumber === undefined) {
|
||||
throw new RequiredError('phoneNumber','Required parameter phoneNumber was null or undefined when calling apiSysSmsAliyunSendSmsPhoneNumberPost.');
|
||||
throw new RequiredError('phoneNumber','Required parameter phoneNumber was null or undefined when calling apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost.');
|
||||
}
|
||||
const localVarPath = `/api/sysSms/aliyunSendSms/{phoneNumber}`
|
||||
.replace(`{${"phoneNumber"}}`, encodeURIComponent(String(phoneNumber)));
|
||||
// verify required parameter 'templateId' is not null or undefined
|
||||
if (templateId === null || templateId === undefined) {
|
||||
throw new RequiredError('templateId','Required parameter templateId was null or undefined when calling apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost.');
|
||||
}
|
||||
const localVarPath = `/api/sysSms/aliyunSendSms/{phoneNumber}/{templateId}`
|
||||
.replace(`{${"phoneNumber"}}`, encodeURIComponent(String(phoneNumber)))
|
||||
.replace(`{${"templateId"}}`, encodeURIComponent(String(templateId)));
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
|
||||
let baseOptions;
|
||||
@ -127,16 +133,22 @@ export const SysSmsApiAxiosParamCreator = function (configuration?: Configuratio
|
||||
*
|
||||
* @summary 发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
apiSysSmsSendSmsPhoneNumberPost: async (phoneNumber: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
apiSysSmsSendSmsPhoneNumberTemplateIdPost: async (phoneNumber: string, templateId: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'phoneNumber' is not null or undefined
|
||||
if (phoneNumber === null || phoneNumber === undefined) {
|
||||
throw new RequiredError('phoneNumber','Required parameter phoneNumber was null or undefined when calling apiSysSmsSendSmsPhoneNumberPost.');
|
||||
throw new RequiredError('phoneNumber','Required parameter phoneNumber was null or undefined when calling apiSysSmsSendSmsPhoneNumberTemplateIdPost.');
|
||||
}
|
||||
const localVarPath = `/api/sysSms/sendSms/{phoneNumber}`
|
||||
.replace(`{${"phoneNumber"}}`, encodeURIComponent(String(phoneNumber)));
|
||||
// verify required parameter 'templateId' is not null or undefined
|
||||
if (templateId === null || templateId === undefined) {
|
||||
throw new RequiredError('templateId','Required parameter templateId was null or undefined when calling apiSysSmsSendSmsPhoneNumberTemplateIdPost.');
|
||||
}
|
||||
const localVarPath = `/api/sysSms/sendSms/{phoneNumber}/{templateId}`
|
||||
.replace(`{${"phoneNumber"}}`, encodeURIComponent(String(phoneNumber)))
|
||||
.replace(`{${"templateId"}}`, encodeURIComponent(String(templateId)));
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
|
||||
let baseOptions;
|
||||
@ -176,16 +188,22 @@ export const SysSmsApiAxiosParamCreator = function (configuration?: Configuratio
|
||||
*
|
||||
* @summary 腾讯云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
apiSysSmsTencentSendSmsPhoneNumberPost: async (phoneNumber: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost: async (phoneNumber: string, templateId: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'phoneNumber' is not null or undefined
|
||||
if (phoneNumber === null || phoneNumber === undefined) {
|
||||
throw new RequiredError('phoneNumber','Required parameter phoneNumber was null or undefined when calling apiSysSmsTencentSendSmsPhoneNumberPost.');
|
||||
throw new RequiredError('phoneNumber','Required parameter phoneNumber was null or undefined when calling apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost.');
|
||||
}
|
||||
const localVarPath = `/api/sysSms/tencentSendSms/{phoneNumber}`
|
||||
.replace(`{${"phoneNumber"}}`, encodeURIComponent(String(phoneNumber)));
|
||||
// verify required parameter 'templateId' is not null or undefined
|
||||
if (templateId === null || templateId === undefined) {
|
||||
throw new RequiredError('templateId','Required parameter templateId was null or undefined when calling apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost.');
|
||||
}
|
||||
const localVarPath = `/api/sysSms/tencentSendSms/{phoneNumber}/{templateId}`
|
||||
.replace(`{${"phoneNumber"}}`, encodeURIComponent(String(phoneNumber)))
|
||||
.replace(`{${"templateId"}}`, encodeURIComponent(String(templateId)));
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
|
||||
let baseOptions;
|
||||
@ -281,12 +299,13 @@ export const SysSmsApiFp = function(configuration?: Configuration) {
|
||||
/**
|
||||
*
|
||||
* @summary 阿里云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} phoneNumber 手机号
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async apiSysSmsAliyunSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
|
||||
const localVarAxiosArgs = await SysSmsApiAxiosParamCreator(configuration).apiSysSmsAliyunSendSmsPhoneNumberPost(phoneNumber, options);
|
||||
async apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
|
||||
const localVarAxiosArgs = await SysSmsApiAxiosParamCreator(configuration).apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options);
|
||||
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
||||
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
|
||||
return axios.request(axiosRequestArgs);
|
||||
@ -310,11 +329,12 @@ export const SysSmsApiFp = function(configuration?: Configuration) {
|
||||
*
|
||||
* @summary 发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async apiSysSmsSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
|
||||
const localVarAxiosArgs = await SysSmsApiAxiosParamCreator(configuration).apiSysSmsSendSmsPhoneNumberPost(phoneNumber, options);
|
||||
async apiSysSmsSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
|
||||
const localVarAxiosArgs = await SysSmsApiAxiosParamCreator(configuration).apiSysSmsSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options);
|
||||
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
||||
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
|
||||
return axios.request(axiosRequestArgs);
|
||||
@ -324,11 +344,12 @@ export const SysSmsApiFp = function(configuration?: Configuration) {
|
||||
*
|
||||
* @summary 腾讯云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async apiSysSmsTencentSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
|
||||
const localVarAxiosArgs = await SysSmsApiAxiosParamCreator(configuration).apiSysSmsTencentSendSmsPhoneNumberPost(phoneNumber, options);
|
||||
async apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
|
||||
const localVarAxiosArgs = await SysSmsApiAxiosParamCreator(configuration).apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options);
|
||||
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
||||
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
|
||||
return axios.request(axiosRequestArgs);
|
||||
@ -360,12 +381,13 @@ export const SysSmsApiFactory = function (configuration?: Configuration, basePat
|
||||
/**
|
||||
*
|
||||
* @summary 阿里云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} phoneNumber 手机号
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async apiSysSmsAliyunSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(configuration).apiSysSmsAliyunSendSmsPhoneNumberPost(phoneNumber, options).then((request) => request(axios, basePath));
|
||||
async apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(configuration).apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
@ -381,21 +403,23 @@ export const SysSmsApiFactory = function (configuration?: Configuration, basePat
|
||||
*
|
||||
* @summary 发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async apiSysSmsSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(configuration).apiSysSmsSendSmsPhoneNumberPost(phoneNumber, options).then((request) => request(axios, basePath));
|
||||
async apiSysSmsSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(configuration).apiSysSmsSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary 腾讯云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async apiSysSmsTencentSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(configuration).apiSysSmsTencentSendSmsPhoneNumberPost(phoneNumber, options).then((request) => request(axios, basePath));
|
||||
async apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(configuration).apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
@ -420,13 +444,14 @@ export class SysSmsApi extends BaseAPI {
|
||||
/**
|
||||
*
|
||||
* @summary 阿里云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} phoneNumber 手机号
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof SysSmsApi
|
||||
*/
|
||||
public async apiSysSmsAliyunSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(this.configuration).apiSysSmsAliyunSendSmsPhoneNumberPost(phoneNumber, options).then((request) => request(this.axios, this.basePath));
|
||||
public async apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(this.configuration).apiSysSmsAliyunSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
/**
|
||||
*
|
||||
@ -443,23 +468,25 @@ export class SysSmsApi extends BaseAPI {
|
||||
*
|
||||
* @summary 发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof SysSmsApi
|
||||
*/
|
||||
public async apiSysSmsSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(this.configuration).apiSysSmsSendSmsPhoneNumberPost(phoneNumber, options).then((request) => request(this.axios, this.basePath));
|
||||
public async apiSysSmsSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(this.configuration).apiSysSmsSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @summary 腾讯云发送短信 📨
|
||||
* @param {string} phoneNumber
|
||||
* @param {string} templateId 短信模板id
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof SysSmsApi
|
||||
*/
|
||||
public async apiSysSmsTencentSendSmsPhoneNumberPost(phoneNumber: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(this.configuration).apiSysSmsTencentSendSmsPhoneNumberPost(phoneNumber, options).then((request) => request(this.axios, this.basePath));
|
||||
public async apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost(phoneNumber: string, templateId: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
|
||||
return SysSmsApiFp(this.configuration).apiSysSmsTencentSendSmsPhoneNumberTemplateIdPost(phoneNumber, templateId, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user