基于小程序wx.request请求,使用SM2国密插件实现接口敏感数据的加密解密。
npm install miniprogram-encryptobash
npm install --save miniprogram-crypto
`
miniprogram-crypto
$3
#### 需要加密的接口使用miniprogram-crypto提供的request方法请求数据
`js
const request = require('miniprogram-encrypto').request
// 支持get和post请求
// options中除fetchPublicKeyUrl和fetchHeader,其余参数与小程序wx.request相同
interface options {
url,
data = {},
method = 'GET',
header,
timeout = 60000,
fetchPublicKeyUrl, // post请求时向服务器获取公钥和token的地址,get请求不传
fetchHeader, // post请求时向服务器获取公钥和token的接口的header,可用于鉴权,get请求不传
dataType,
responseType,
enableHttp2 = false,
enableQuic = false,
enableCache = false,
enableHttpDNS = false,
httpDNSServiceId,
enableChunked = false,
forceCellularNetwork = false
}
request(options).then(res => {
console.log(res); // res的值与小程序wx.request返回值相同
})
``