如何使用window.btoa base64对接口数组进行加密处理
生活随笔
收集整理的這篇文章主要介紹了
如何使用window.btoa base64对接口数组进行加密处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大家好,我是孫叫獸,前端全棧工程師,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);打印一下。
這個不用轉成字符串的
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());?
總結
以上是生活随笔為你收集整理的如何使用window.btoa base64对接口数组进行加密处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: uniapp框架之如何修改接口传参的参数
- 下一篇: csdn个人主页下如何添加微信公众号及超