添加cos
This commit is contained in:
parent
4b63f22993
commit
b0884a56d7
|
|
@ -43,7 +43,15 @@ export default class TImageConfigService {
|
|||
static findForm(id?: string | undefined) {
|
||||
return Http.get(`${this.urlPrefix}/findForm${(id ? '/' + id : '')}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传key
|
||||
*
|
||||
* @param
|
||||
* @returns
|
||||
*/
|
||||
static getCosSign() {
|
||||
return Http.get(`${this.urlPrefix}/GetCosSign`)
|
||||
}
|
||||
/**
|
||||
* 保存表单数据
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ import { reactive, ref } from "vue";
|
|||
import { FormInstance } from "ant-design-vue";
|
||||
import Tools from "@/core/utils/Tools";
|
||||
import TImageConfigService from "@/services/apps/T_Image_Configs/TImageConfigService";
|
||||
import { UploadOutlined } from '@ant-design/icons-vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
import type { UploadProps } from 'ant-design-vue';
|
||||
|
||||
|
||||
//定义组件事件
|
||||
const props = defineProps<{ onSuccess: () => void }>();
|
||||
|
|
@ -59,6 +63,24 @@ function save() {
|
|||
}
|
||||
});
|
||||
}
|
||||
const fileList = ref<UploadProps['fileList']>([]);
|
||||
const uploading = ref<boolean>(false);
|
||||
|
||||
const handleRemove: UploadProps['onRemove'] = file => {
|
||||
const index = fileList.value.indexOf(file);
|
||||
const newFileList = fileList.value.slice();
|
||||
newFileList.splice(index, 1);
|
||||
fileList.value = newFileList;
|
||||
};
|
||||
|
||||
const beforeUpload: UploadProps['beforeUpload'] = file => {
|
||||
fileList.value = [...(fileList.value || []), file];
|
||||
console.log(fileList.value);
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -90,6 +112,21 @@ function save() {
|
|||
<a-input v-model:value="state.vm.form.url" placeholder="请输入" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col>
|
||||
|
||||
<a-upload-dragger
|
||||
:file-list="fileList" :before-upload="beforeUpload" @remove="handleRemove"
|
||||
name="file"
|
||||
:multiple="false"
|
||||
|
||||
>
|
||||
<p class="ant-upload-drag-icon">
|
||||
<inbox-outlined></inbox-outlined>
|
||||
</p>
|
||||
<p class="ant-upload-text">点击上传文件</p>
|
||||
|
||||
</a-upload-dragger>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
</a-spin>
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||
.editorconfig = .editorconfig
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiaoYu.Core.Cos", "MiaoYu.Core.Cos\MiaoYu.Core.Cos.csproj", "{3FBBDE5E-2D2C-428B-A2BF-298499ABA5A7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -126,6 +128,10 @@ Global
|
|||
{39C765DB-41E7-4BC6-B75E-2A90CFF3A8EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{39C765DB-41E7-4BC6-B75E-2A90CFF3A8EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{39C765DB-41E7-4BC6-B75E-2A90CFF3A8EF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3FBBDE5E-2D2C-428B-A2BF-298499ABA5A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3FBBDE5E-2D2C-428B-A2BF-298499ABA5A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3FBBDE5E-2D2C-428B-A2BF-298499ABA5A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3FBBDE5E-2D2C-428B-A2BF-298499ABA5A7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -148,6 +154,7 @@ Global
|
|||
{75959B17-A901-49E1-A5E7-667349DC4203} = {DC7A7E4A-B4DC-4958-BAA5-2BBB1A153B5F}
|
||||
{925EF035-4A41-42E4-A3A4-B8E9AE52F6B7} = {DC7A7E4A-B4DC-4958-BAA5-2BBB1A153B5F}
|
||||
{39C765DB-41E7-4BC6-B75E-2A90CFF3A8EF} = {451BE0BB-26ED-47ED-ABC7-23001D21410C}
|
||||
{3FBBDE5E-2D2C-428B-A2BF-298499ABA5A7} = {DB46F54A-9F53-44EC-80F8-9E53F0B871CF}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E3C61955-46C1-4D06-994F-C86A72B2B0E2}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using MiaoYu.Core.Cos;
|
||||
|
||||
namespace MiaoYu.Api.Admin;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -11,7 +13,8 @@ namespace MiaoYu.Api.Admin;
|
|||
AdminRepositoryStartup,
|
||||
ChatAdminRepositoryStartup,
|
||||
CoreSwaggerJwtStartup,
|
||||
SharedAdminStartup>]
|
||||
SharedAdminStartup,
|
||||
CoreCosStartup>]
|
||||
public class ApiAdminStartup : AppStartupBase<ApiAdminStartup>
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
using IdGen;
|
||||
|
||||
using MiaoYu.Core.Cos.Services;
|
||||
using MiaoYu.Repository.ChatAI.Admin.Entities;
|
||||
|
||||
using NPOI.SS.Formula.Functions;
|
||||
namespace MiaoYu.Api.Admin.ApplicationServices.Apps;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -8,10 +11,12 @@ namespace MiaoYu.Api.Admin.ApplicationServices.Apps;
|
|||
/// </summary>
|
||||
public class TImageConfigService : ApplicationService<IRepository<T_Image_Config>>
|
||||
{
|
||||
public TImageConfigService(IRepository<T_Image_Config> defaultRepository)
|
||||
private ICodeCosService codeCosService;
|
||||
public TImageConfigService(IRepository<T_Image_Config> defaultRepository,
|
||||
ICodeCosService codeCosService)
|
||||
: base(defaultRepository)
|
||||
{
|
||||
|
||||
this.codeCosService = codeCosService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -121,6 +126,14 @@ public class TImageConfigService : ApplicationService<IRepository<T_Image_Config
|
|||
return ExcelUtil.ExportExcelByPagingView(tableViewModel, null, "Id");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取签名
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetCosSign() {
|
||||
var (sign,ex) = codeCosService.GenerateSignURL(new MiaoYu.Core.Cos.Models.CosGenerateSign());
|
||||
return sign;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -94,7 +94,17 @@ public class TImageConfigController : AdminControllerBase<TImageConfigService>
|
|||
base.HttpContext.DownLoadFile(data, Tools.GetFileContentType[".xls"].ToStr(), name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ActionDescriptor(DisplayName = "获取cos加密")]
|
||||
public string GetCosSign()
|
||||
{
|
||||
return this._defaultService.GetCosSign();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MiaoYu.Core.Cos\MiaoYu.Core.Cos.csproj" />
|
||||
<ProjectReference Include="..\MiaoYu.Core.Identity\MiaoYu.Core.Identity.csproj" />
|
||||
<ProjectReference Include="..\MiaoYu.Core.Quartz\MiaoYu.Core.Quartz.csproj" />
|
||||
<ProjectReference Include="..\MiaoYu.Core.Razor\MiaoYu.Core.Razor.csproj" />
|
||||
|
|
|
|||
|
|
@ -209,6 +209,12 @@
|
|||
<param name="pagingSearchInput"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:MiaoYu.Api.Admin.ApplicationServices.Apps.TImageConfigService.GetCosSign">
|
||||
<summary>
|
||||
获取签名
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:MiaoYu.Api.Admin.ApplicationServices.Apps.T_CharacterService">
|
||||
<summary>
|
||||
人物表 服务 T_CharacterService
|
||||
|
|
@ -1519,6 +1525,12 @@
|
|||
<param name="pagingSearchInput"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:MiaoYu.Api.Admin.Controllers.Apps.TImageConfigController.GetCosSign">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:MiaoYu.Api.Admin.Controllers.Apps.T_CharacterController">
|
||||
<summary>
|
||||
人物表 控制器
|
||||
|
|
|
|||
|
|
@ -7,25 +7,25 @@
|
|||
// pi计算 数据库管理
|
||||
"AdminRepositoryOptions": {
|
||||
//默认数据库类型 SqlServer 、MySql 、PostgreSql、Oracle
|
||||
"DefaultDatabaseType": "MySql",
|
||||
"DefaultDatabaseType": "SqlServer",
|
||||
//是否监控EFCore程序
|
||||
"IsMonitorEFCore": false,
|
||||
"IsMonitorEFCore": true,
|
||||
// 连接字符串 - mysql
|
||||
"ConnectionString": "Server=localhost; port=3306; Database=hzy_admin_mysql_20230227; uid=root; pwd=123456; Convert Zero Datetime=False"
|
||||
//"ConnectionString": "Server=localhost; port=3306; Database=hzy_admin_mysql_20230227; uid=root; pwd=123456; Convert Zero Datetime=False"
|
||||
//// 连接字符串 - sqlserver
|
||||
//"ConnectionString": "Server=.;Database=hzy_microservices_sqlserver_20230227;User ID=sa;Password=123456;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;",
|
||||
//"ConnectionString": "Server=192.168.195.2;Database=MiaoYu;User ID=zpc;Password=zpc;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;",
|
||||
"ConnectionString": "Server=192.168.195.2;Database=HZY;User ID=zpc;Password=zpc;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;"
|
||||
//// 连接字符串 - postgresql
|
||||
//"ConnectionString": "User ID=postgres;Password=123456;Host=localhost;Port=5432;Database=hzy_microservices_pgsql_20230227;Pooling=true;TimeZone=Asia/Shanghai",
|
||||
//// 连接字符串 - oracle
|
||||
//"ConnectionString": "user id=hzy_admin_oracle_20221213;password=123456; data source=//127.0.0.1:1521/orcl;Pooling=true;Min Pool Size=1"
|
||||
},
|
||||
"ChatAdminRepositoryOptions": {
|
||||
//默认数据库类型 SqlServer 、MySql 、PostgreSql、Oracle
|
||||
"DefaultDatabaseType": "SqlServer",
|
||||
//是否监控EFCore程序
|
||||
"IsMonitorEFCore": true,
|
||||
"ConnectionString": "Server=192.168.195.2;Database=MiaoYu;User ID=zpc;Password=zpc;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -41,5 +41,31 @@
|
|||
"MaxFileSizeLimit": "1gb",
|
||||
// 设置允许上传文件格式 | 分割
|
||||
"AllowExtensions": ".png|.jpg"
|
||||
},
|
||||
//腾讯云配置
|
||||
"TencentCloud": {
|
||||
"SecretId": "AKIDLbhdP0Vs57yd7QZWu8A2jFbno8JKBUp6",
|
||||
"SecretKey": "MlP5tcUG6mdj7TwOpDWnZNFGIrJY8eH4",
|
||||
"AppId": "1308826010",
|
||||
"SMSCode": {
|
||||
//请求方式
|
||||
"ReqMethod": "POST",
|
||||
//超时时间
|
||||
"Timeout": 30,
|
||||
//短信应用ID:
|
||||
"SmsSdkAppId": "1400923253",
|
||||
//签名
|
||||
"SignName": "上海寰梦科技发展",
|
||||
//模板编号
|
||||
"TemplateId": "2209122"
|
||||
},
|
||||
"CosConfig": {
|
||||
"AppId": "1308826010",
|
||||
"SecretId": "AKIDLbhdP0Vs57yd7QZWu8A2jFbno8JKBUp6",
|
||||
"SecretKey": "MlP5tcUG6mdj7TwOpDWnZNFGIrJY8eH4",
|
||||
"DurationSecond": "300",
|
||||
"Region": "ap-shanghai",
|
||||
"Bucket": "miaoyu"
|
||||
}
|
||||
}
|
||||
}
|
||||
25
admin-server/MiaoYu.Core.Cos/Configs/TencentBaseConfig.cs
Normal file
25
admin-server/MiaoYu.Core.Cos/Configs/TencentBaseConfig.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiaoYu.Core.Cos.Configs
|
||||
{
|
||||
public class TencentBaseConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 腾讯云id
|
||||
/// </summary>
|
||||
public string SecretId { get; set; }
|
||||
/// <summary>
|
||||
/// 密钥
|
||||
/// </summary>
|
||||
public string SecretKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应用Id
|
||||
/// </summary>
|
||||
public string AppId { get; set; }
|
||||
}
|
||||
}
|
||||
19
admin-server/MiaoYu.Core.Cos/Configs/TencentConfig.cs
Normal file
19
admin-server/MiaoYu.Core.Cos/Configs/TencentConfig.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiaoYu.Core.Cos.Configs
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class TencentConfig:TencentBaseConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// cos
|
||||
/// </summary>
|
||||
public TencentCosConfig CosConfig { get; set; }
|
||||
}
|
||||
}
|
||||
30
admin-server/MiaoYu.Core.Cos/Configs/TencentCosConfig.cs
Normal file
30
admin-server/MiaoYu.Core.Cos/Configs/TencentCosConfig.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiaoYu.Core.Cos.Configs
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 对象存储
|
||||
/// </summary>
|
||||
public class TencentCosConfig:TencentBaseConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 最大超时时间
|
||||
/// </summary>
|
||||
public long DurationSecond { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 区域
|
||||
/// </summary>
|
||||
public string Region { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Bucket { get; set; }
|
||||
}
|
||||
}
|
||||
59
admin-server/MiaoYu.Core.Cos/CoreCosStartup.cs
Normal file
59
admin-server/MiaoYu.Core.Cos/CoreCosStartup.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using HZY.Framework.Core.AspNetCore;
|
||||
|
||||
using MiaoYu.Core.Cos.Configs;
|
||||
using MiaoYu.Core.Cos.Services;
|
||||
using MiaoYu.Core.Cos.Services.Impl;
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiaoYu.Core.Cos
|
||||
{
|
||||
/// <summary>
|
||||
/// cos
|
||||
/// </summary>
|
||||
public class CoreCosStartup : StartupModule<CoreCosStartup>
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务配置
|
||||
/// </summary>
|
||||
/// <param name="webApplicationBuilder"></param>
|
||||
public override void ConfigureServices(WebApplicationBuilder webApplicationBuilder)
|
||||
{
|
||||
var tencentConfig = webApplicationBuilder.Configuration.GetSection("TencentCloud").Get<TencentConfig>();
|
||||
if (tencentConfig == null)
|
||||
{
|
||||
tencentConfig = new TencentConfig();
|
||||
}
|
||||
if (tencentConfig.CosConfig == null)
|
||||
{
|
||||
tencentConfig.CosConfig = new TencentCosConfig() { };
|
||||
}
|
||||
if (string.IsNullOrEmpty(tencentConfig.CosConfig.SecretId))
|
||||
{
|
||||
tencentConfig.CosConfig.SecretId = tencentConfig.SecretId;
|
||||
}
|
||||
if (string.IsNullOrEmpty(tencentConfig.CosConfig.SecretKey))
|
||||
{
|
||||
tencentConfig.CosConfig.SecretKey = tencentConfig.SecretKey;
|
||||
}
|
||||
//注册一个验证码的服务
|
||||
webApplicationBuilder.Services.AddSingleton<TencentConfig>(tencentConfig);
|
||||
//webApplicationBuilder.Services.AddScoped<ICodeCosService, TencentCodeCosService>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用服务
|
||||
/// </summary>
|
||||
/// <param name="webApplication"></param>
|
||||
public override void Configure(WebApplication webApplication)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
3
admin-server/MiaoYu.Core.Cos/FodyWeavers.xml
Normal file
3
admin-server/MiaoYu.Core.Cos/FodyWeavers.xml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<Rougamo />
|
||||
</Weavers>
|
||||
26
admin-server/MiaoYu.Core.Cos/FodyWeavers.xsd
Normal file
26
admin-server/MiaoYu.Core.Cos/FodyWeavers.xsd
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
|
||||
<xs:element name="Weavers">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Rougamo" minOccurs="0" maxOccurs="1" type="xs:anyType" />
|
||||
</xs:all>
|
||||
<xs:attribute name="VerifyAssembly" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="GenerateXsd" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
19
admin-server/MiaoYu.Core.Cos/MiaoYu.Core.Cos.csproj
Normal file
19
admin-server/MiaoYu.Core.Cos/MiaoYu.Core.Cos.csproj
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Tencent.QCloud.Cos.Sdk" Version="5.4.38" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MiaoYu.Core.EntityFramework\MiaoYu.Core.EntityFramework.csproj" />
|
||||
<ProjectReference Include="..\MiaoYu.Core\MiaoYu.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
using MiaoYu.Core.Cos.Configs;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiaoYu.Core.Cos.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成签名
|
||||
/// </summary>
|
||||
public class CosGenerateSign: TencentCosConfig
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
16
admin-server/MiaoYu.Core.Cos/Services/ICodeCosService.cs
Normal file
16
admin-server/MiaoYu.Core.Cos/Services/ICodeCosService.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
namespace MiaoYu.Core.Cos.Services;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface ICodeCosService:ISingletonDependency //:ITransientDependency: IScopedDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回签名地址
|
||||
/// </summary>
|
||||
/// <param name="cosGenerateSign"></param>
|
||||
/// <returns>sign签名值,过期时间</returns>
|
||||
(string sign, int expiredSeconds) GenerateSignURL(CosGenerateSign cosGenerateSign);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
using COSXML.Model.Object;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using COSXML.Auth;
|
||||
using MiaoYu.Core.Cos.Configs;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
|
||||
namespace MiaoYu.Core.Cos.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// 腾讯云 TencentCosXmlConfig
|
||||
/// </summary>
|
||||
public class TencentCodeCosService : ICodeCosService//ISingletonDependency //: IScopedDependency//: ITransientDependency
|
||||
{
|
||||
//public TencentCodeCosService() { }
|
||||
private CosXml cosXml;
|
||||
private TencentCosConfig tencentCosConfig;
|
||||
private TencentConfig tencentConfig;
|
||||
CosXmlConfig config = null;
|
||||
public TencentCodeCosService(TencentConfig tencentConfig)
|
||||
{
|
||||
this.tencentConfig = tencentConfig;
|
||||
this.tencentCosConfig = tencentConfig.CosConfig;
|
||||
if (config == null)
|
||||
{
|
||||
config = new CosXmlConfig.Builder()
|
||||
//.SetRegion("COS_REGION") // 设置默认的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
|
||||
.Build();
|
||||
}
|
||||
string secretId = tencentCosConfig.SecretId; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi
|
||||
string secretKey = tencentCosConfig.SecretKey; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi
|
||||
long durationSecond = tencentCosConfig.DurationSecond; //每次请求签名有效时长,单位为秒
|
||||
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,
|
||||
secretKey, durationSecond);
|
||||
|
||||
this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);
|
||||
}
|
||||
public (string sign, int expiredSeconds) GenerateSignURL(CosGenerateSign cosGenerateSign)
|
||||
{
|
||||
try
|
||||
{
|
||||
PreSignatureStruct preSignatureStruct = new PreSignatureStruct();
|
||||
// APPID 获取参考 https://console.cloud.tencent.com/developer
|
||||
preSignatureStruct.appid = tencentCosConfig.AppId;
|
||||
|
||||
// 存储桶所在地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
|
||||
preSignatureStruct.region = tencentCosConfig.Region;
|
||||
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
|
||||
preSignatureStruct.bucket = tencentCosConfig.Bucket + "-" + tencentCosConfig.AppId;// "examplebucket-1250000000";
|
||||
preSignatureStruct.key = "exampleobject"; //对象键
|
||||
preSignatureStruct.httpMethod = "PUT"; //HTTP 请求方法
|
||||
preSignatureStruct.isHttps = true; //生成 HTTPS 请求 URL
|
||||
preSignatureStruct.signDurationSecond = tencentCosConfig.DurationSecond; //请求签名时间为 600s
|
||||
preSignatureStruct.headers = null;//签名中需要校验的 header
|
||||
preSignatureStruct.queryParameters = null; //签名中需要校验的 URL 中请求参数
|
||||
|
||||
//上传预签名 URL (使用永久密钥方式计算的签名 URL)
|
||||
string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);
|
||||
|
||||
return new(requestSignURL, (int)tencentCosConfig.DurationSecond);
|
||||
}
|
||||
catch (COSXML.CosException.CosClientException clientEx)
|
||||
{
|
||||
//请求失败
|
||||
Console.WriteLine("CosClientException: " + clientEx);
|
||||
}
|
||||
catch (COSXML.CosException.CosServerException serverEx)
|
||||
{
|
||||
//请求失败
|
||||
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
admin-server/MiaoYu.Core.Cos/Usings.cs
Normal file
7
admin-server/MiaoYu.Core.Cos/Usings.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
global using HZY.Framework.Core.AspNetCore;
|
||||
global using HZY.Framework.DependencyInjection.Attributes;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using HZY.Framework.DependencyInjection;
|
||||
global using MiaoYu.Core.Cos.Models;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user