实际开发中前端有时会用到接口调用,签名安全等问题,因此会经常使用MD5进行签名,js-md5就是一款MD5加密插件,下面具体介绍用法:
1. 使用流程
(1)安装
vue-cli项目中安装
"js-md5": "^0.7.3",
npm install js-md5@0.7.3 --save
(2)作为Vue实例的方式使用
在main.js入口文件中
//引入
import md5 from 'js-md5'
// 挂载全局
Vue.prototype.$md5 = md5 // MD5
在组件中使用
//请求URL参数签名
this.$router.push({
path: '/scm2erp/jxInputInvoice',
query: {
supplierNo: this.outParam.supplierNo,
sign: this.$md5('jxInputInvoice' + this.outParam.supplierNo + 'SCM2ERP'),
goods: this.goods,
outParam: this.outParam
}
})
//验证签名
mounted() {
this.url = window.location.ancestorOrigins[0] + '/erp2/cw/service/ERPII'
if (getUrlKey('sign') !== this.$md5('jxInputInvoice' + getUrlKey('supplierNo') + 'SCM2ERP')) {
this.$router.push({ name: '404' })
} else {
this.goodsForm.goods = this.$route.query.goods
this.outParam = this.$route.query.outParam
console.log(this.$route.query.goods)
}
}