实现md5加密
程序员文章站
2024-03-19 10:59:10
...
md5加密请求,可配合 上篇文章封装Vue的请求一起看:https://blog.csdn.net/zi114323/article/details/106856505
一、md5的js文件百度网盘取,src/until:
复制这段内容后打开百度网盘手机App,链接:https://pan.baidu.com/s/1nmTyqSHLh9RtKl2ZczZeQg 提取码:7p26
二、在base.js里写加密方法,src/interface/base.js
import md5 from '@/util/md5';
const Base= {};
Base.key='test';
//多态加密方法
function Encrypt(){
function Zero(){
let sign=Base.key;
return md5(sign);
}
function Solo(param){
let sign=param+Base.key;
return md5(sign);
}
function Duet(param1,param2){
let sign=param1+param2+Base.key;
return md5(sign);
}
function Trio(param1,param2,param3){
let sign=param1+param2+param3+Base.key;
return md5(sign);
}
function Quartet(param1,param2,param3,param4){
let sign=param1+param2+param3+param4+Base.key;
return md5(sign);
}
this.md5=function(){
let arg=arguments;
let len=arg.length;
switch(len){
case 0:
return Zero();
case 1:
return Solo(arg[0]);
case 2:
return Duet(arg[0],arg[1]);
case 3:
return Trio(arg[0],arg[1],arg[2]);
case 4:
return Quartet(arg[0],arg[1],arg[2],arg[3]);
default:
return '参数太多';
}
}
}
let encrypt=new Encrypt();
//文件加密
Base.encrypt=encrypt;
export default Base;
三、在接口请求时使用使用,interface/user.js
//系统一些自带的 请求
import tool from '../util/tool';
import base from './base';
const User = {}
User.url = window.url;
function error(view,res) {
base.Error(res, view)
}
const register={};
register.title='注册';
register.url=User.url+'user/userRigiseter';
register.post=function(data,view){
let _this = this;
base.request.init(data,view);
data.sign=base.encrypt.md5(data.phoneNumber,data.SmsCode);//这里写入传入的参数,注意顺序与后台相同
base.request.log(data,_this.url,_this.title);
return tool.post(_this.url,data,view,_this.success,error,_this.title);
}
register.success=function(res, view) {
base.Success(res, view,this.title)
if(res.code=='200'){
view.registerSuccess(res);
}else{
view.registerError(res);
}
}
User.register=register;