encrypt-axios
v3.7.0
Published
axios二次开发的插件,配置需要加密的接口,会使用SM2进行加密解密
Readme
安装
npm install encrypt-axios --save用法
// 请求和响应拦截器中使用SM2加密解密
// ES6
import axiosDefine from 'encrypt-axios';
// axios实例
const client = axios.create({
baseURL,
timeout: 6000
});
// options 配置项
const options = {
baseURL: '', // baseURL 配置获取加密信息的公钥和token的请求地址
url: '' // url 请求路径
}
axiosDefine(client, options);
// 使用时请在需要加密传输的接口配置headers: { isEncrypt: true },true 加密,false 不加密,不配置isEncrypt默认false
client.post('/encrypt/login', {
type: 1,
content: '配置headers'
}, {
headers: {
isEncrypt: true // isEncrypt 数据是否加密传输
}
}).then(res => {
console.log(res);
})
client.get('/userInfo', {
id: 1
}, {
headers: {
isEncrypt: true // isEncrypt 数据是否加密传输
}
}).then(res => {
console.log(res);
})
