npm.io
3.7.0 • Published 4 years ago

encrypt-axios

Licence
ISC
Version
3.7.0
Deps
2
Size
67 kB
Vulns
22
Weekly
0

安装

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);

  })

打包发布

npm install
npx microbundle
npm publish