当前位置: 首页 > news >正文

vue 签名校验 md5 uuid

import CryptoJS from 'crypto-js'
import uuid from '@/utils/uuid'
import { SECRET_KEY } from '@/utils/config'
// 签名校验
const nonceStr = uuid.uuid()
const timestamp = new Date().getTime()
// const sign = CryptoJS.MD5('nonceStr=' + nonceStr + '&secretKey=' + SECRET_KEY + '&timestamp=' + timestamp).toString(CryptoJS.enc.Hex).toUpperCase()
const sign = CryptoJS.MD5('nonceStr=' + nonceStr + '&secretKey=' + SECRET_KEY + '&timestamp=' + timestamp).toString().toUpperCase()
// 发送请求
axios.post('http://localhost:xxx', {nonceStr,timestamp,sign
}).then(res => {console.log(res.data)
}).catch(() => {this.$alert('本地授权客户端连接失败', '提示', { type: 'error' })
})

uuid.js

/*** 生成UUID*/
export default {uuid() {const s = []const hexDigits = '0123456789abcdef'for (let i = 0; i < 36; i++) {s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)}s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01s[8] = s[13] = s[18] = s[23] = '-'return s.join('').replaceAll('-', '')}
}

config.js

/*** @description: 加密配置信息*/
// 签名校验
export const SECRET_KEY = 'xxx32bitxxx'

注:npm install crypto-js

axios.post 改为同步请求

          // 签名校验const nonceStr = uuid.uuid()const timestamp = new Date().getTime()const sign = CryptoJS.MD5('nonceStr=' + nonceStr + '&secretKey=' + SECRET_KEY + '&timestamp=' + timestamp).toString().toUpperCase()// 发送请求this.loading = trueconst resp = await axios.post('http://localhost:xxx', {nonceStr,timestamp,sign}).catch(() => {this.$alert('本地授权客户端连接失败', '提示', { type: 'error' })})this.loading = false// 请求结果异常if (!resp) {return}// 请求结果处理const res = resp.dataif (res.code !== 200) {this.$message.error(res.msg)return}

http://www.lryc.cn/news/504278.html

相关文章:

  • CSS系列(16)-- 架构与模式详解
  • 【go语言】reflect包与类型推断
  • 3.python运算符
  • 【竞技宝】CS2-上海major:spirit力克MOUZ niko梦碎
  • 【Leetcode 每日一题】3266. K 次乘运算后的最终数组 II
  • etcd集群常见日志
  • 【漫话机器学习系列】005.神经网络的结构(architecture on the neural network)
  • 基于 Couchbase 数据仓库元数据管理的可行性方案
  • SpringBoot:快速构建微服务应用
  • 汽车嵌入式软件构建高效技术团队的全面思考
  • 【跨库查询、多库查询】.NET开源 ORM 框架 SqlSugar 系列
  • 智能人体安全防护:3D 视觉技术原理、系统架构与代码实现剖析
  • 第24周:文献阅读
  • yolov8 转华为昇腾om脚本
  • 分布式事物XA、BASE、TCC、SAGA、AT
  • 域名信息收集(小迪网络安全笔记~
  • 力扣-图论-13【算法学习day.63】
  • 【设计模式】如何用C++实现观察者模式【发布订阅机制】
  • 【LC】2717. 半有序排列
  • AI智算-k8s部署大语言模型管理工具Ollama
  • CloudberryDB(二) 演化路线图
  • 《拉依达的嵌入式\驱动面试宝典》—C/CPP基础篇(二)
  • 实现canal监控binlog日志再通过消息队列异步处理
  • Linux DNS 协议概述
  • linux打包qt程序
  • 软考中级-软件设计师通过心路经验分享
  • safe area helper插件
  • 李宏毅机器学习-批次 (batch)和动量(momentum)
  • C# 网络编程--关于UDP 通信(二)
  • 【k8s集群应用】Kubernetes部署安装-二进制部署实例