test:function(){ wx.request({ url: this.data.url, data:{ id:6 }, header:{ token:登录令牌, }, method: ‘post‘, responseType: "arraybuffer", //此处是请求文件流,必须带入的属性 success: function (res) { if(res.statusCode === 200){ var imgSrc = wx.arrayBufferToBase64(res.data);//二进制流转为base64编码 var save = wx.getFileSystemManager(); var number = Math.random(); save.writeFile({ filePath: wx.env.USER_DATA_PATH + ‘/pic‘ + number + ‘.png‘, data: imgSrc, encoding: ‘base64‘, success: res => { wx.saveImageToPhotosAlbum({ //保存为png格式到相册 filePath: wx.env.USER_DATA_PATH + ‘/pic‘ + number + ‘.png‘, success: function (res) { wx.showToast({ title: ‘下载成功‘, icon: ‘none‘, duration: 2000, //提示的延迟时间,单位毫秒,默认:1500 }) }, fail: function (err) { console.log(err) } }) }, fail: err => { console.log(err) } }) } }, fail: function (error) { console.log(error); } }); },
做个记录,免得忘了