Skip to content

Commit

Permalink
接口签名
Browse files Browse the repository at this point in the history
注释调整
  • Loading branch information
Coldairarrow committed Nov 30, 2020
1 parent 6f04f5e commit d2e299f
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -13,6 +14,7 @@ namespace Coldairarrow.Api.Controllers.Base_Manage
/// </summary>
/// <seealso cref="Coldairarrow.Api.BaseApiController" />
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("系统权限")]
public class Base_ActionController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -12,6 +13,7 @@ namespace Coldairarrow.Api.Controllers.Base_Manage
/// </summary>
/// <seealso cref="Coldairarrow.Api.BaseApiController" />
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("应用密钥")]
public class Base_AppSecretController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
/// <summary>
/// 应用密钥
/// 数据库连接
/// </summary>
/// <seealso cref="Coldairarrow.Api.BaseApiController" />
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("数据库连接")]
public class Base_DbLinkController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
/// <summary>
/// 部门
/// </summary>
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("部门")]
public class Base_DepartmentController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using Coldairarrow.Business.Base_Manage;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
/// <summary>
/// 应用密钥
/// 系统角色
/// </summary>
/// <seealso cref="Coldairarrow.Api.BaseApiController" />
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("系统角色")]
public class Base_RoleController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using Coldairarrow.Entity;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("系统用户")]
public class Base_UserController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("审计日志")]
public class Base_UserLogController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("代码生成")]
public class BuildCodeController : BaseApiController
{
#region DI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using NSwag.Annotations;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
Expand All @@ -17,6 +18,7 @@ namespace Coldairarrow.Api.Controllers.Base_Manage
/// 首页控制器
/// </summary>
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("主页")]
public class HomeController : BaseApiController
{
readonly IHomeBusiness _homeBus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using NSwag.Annotations;
using System;
using System.IO;
using System.Linq;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
[Route("/Base_Manage/[controller]/[action]")]
[OpenApiTag("上传")]
public class UploadController : BaseApiController
{
readonly IConfiguration _configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ namespace Coldairarrow.Api
3: 在header中携带上述的appId、time、guid、sign即可
详细使用Demo请看:
HttpHelper.SafeSignRequest
/Demo/ApiSignDemo
src\Coldairarrow.Web\src\utils\plugin\axios-plugin.js
*/
/// <summary>
/// 校验签名、十分严格
Expand Down
6 changes: 5 additions & 1 deletion src/Coldairarrow.Web/.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ VUE_APP_LocalRootUrl=http://localhost:5000
#接口超时时间ms
VUE_APP_ApiTimeout=10000
#本地开发启动端口
VUE_APP_DevPort=5001
VUE_APP_DevPort=5001
#接口签名appId
VUE_APP_AppId=PcAdmin
#接口签名appSecret
VUE_APP_AppSecret=wtMaiTRPTT3hrf5e
4 changes: 3 additions & 1 deletion src/Coldairarrow.Web/src/config/defaultSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ export default {
publishRootUrl: process.env.VUE_APP_PublishRootUrl,//发布后接口根地址
localRootUrl: process.env.VUE_APP_LocalRootUrl,//本地调试接口根地址
apiTimeout: parseInt(process.env.VUE_APP_ApiTimeout),//接口超时时间ms
devPort: parseInt(process.env.VUE_APP_DevPort) //本地开发启动端口
devPort: parseInt(process.env.VUE_APP_DevPort), //本地开发启动端口
appId: process.env.VUE_APP_AppId,
appSecret: process.env.VUE_APP_AppSecret
}
19 changes: 19 additions & 0 deletions src/Coldairarrow.Web/src/utils/plugin/axios-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import axios from 'axios'
import TokenCache from '@/utils/cache/TokenCache'
import defaultSettings from '@/config/defaultSettings'
import ProcessHelper from '@/utils/helper/ProcessHelper'
import moment from 'moment'
var uuid = require('node-uuid')
var md5 = require("md5")

const rootUrl = () => {
if (ProcessHelper.isProduction() || ProcessHelper.isPreview()) {
Expand All @@ -26,6 +29,22 @@ Axios.interceptors.request.use(config => {
// config.data = formData
// }

//CheckSign签名检验
let appId = defaultSettings.appId
let appSecret = defaultSettings.appSecret
let guid = uuid.v4()
let time = moment().format("YYYY-MM-DD HH:mm:ss")
let body = ''
if (config.data) {
body = JSON.stringify(config.data)
}
let sign = md5(appId + time + guid + body + appSecret)

config.headers.appId = appId;
config.headers.time = time;
config.headers.guid = guid;
config.headers.sign = sign;

//携带token
if (TokenCache.getToken()) {
config.headers.Authorization = 'Bearer ' + TokenCache.getToken()
Expand Down

0 comments on commit d2e299f

Please sign in to comment.