如何使用window.btoa base64对接口数组进行加密处理

网友投稿 929 2022-05-29

大家好,我是孙叫兽,前端全栈工程师,uniapp技术交流群:1149933135

项目采用uniapp+uView开发;

uiapp官方文档:https://uniapp.dcloud.io/

uview官方文档:http://uviewui.com/components/intro.html

接口传参的操作步骤请参考我上一篇文章——>uniapp框架之如何修改接口传参的参数

我这个显示的是加密过的,这里只演示过程。

window.btoa base64加密 一般格式是:window.btoa(‘123456’);

这个不支持数组直接加密的,因此我们需要将数组转换成字符串,如果后端处理了,我们就不用转成字符串啦,具体可以使用console.log(this.personId.attendees);打印一下。

如何使用window.btoa base64对接口数组进行加密处理

这个不用转成字符串的

this.personId.attendees = window.btoa(this.personId.attendees);

this.personId.charge = window.btoa(this.personId.charge);

转成字符串的

this.personId.attendees = window.btoa(this.personId.attendees.toString());

this.personId.charge = window.btoa(this.personId.attendees.toString());

因为上面的对一个数组四个人一起加密处理的,后台解密需要解密四次,我们可以将数组拆分成4个分开加密(有多少人分割成多少个数组再加密)。

var result = [];

for(var i=1;i<=this.personId.attendees.length;i++){

result.push(this.personId.attendees.slice(i,i+1));

}

return result;

// console.log(result);

//对参与人进行加密(可以多个人)

this.personId.attendees = window.btoa(result);

// console.log(this.personId.attendees);

//对主责人进行加密处理(只能选一个人)

this.personId.charge = window.btoa(this.personId.attendees.toString());

数据结构

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何查看python对象的属性或方法
下一篇:MarkDown语法
相关文章