如何使用window.btoa base64對接口數(shù)組進(jìn)行加密處理
大家好,我是孫叫獸,前端全棧工程師,uniapp技術(shù)交流群:1149933135
項(xiàng)目采用uniapp+uView開發(fā);
uiapp官方文檔:https://uniapp.dcloud.io/
uview官方文檔:http://uviewui.com/components/intro.html
接口傳參的操作步驟請參考我上一篇文章——>uniapp框架之如何修改接口傳參的參數(shù)
我這個(gè)顯示的是加密過的,這里只演示過程。
window.btoa base64加密?一般格式是:window.btoa(‘123456’);
這個(gè)不支持?jǐn)?shù)組直接加密的,因此我們需要將數(shù)組轉(zhuǎn)換成字符串,如果后端處理了,我們就不用轉(zhuǎn)成字符串啦,具體可以使用console.log(this.personId.attendees);打印一下。
這個(gè)不用轉(zhuǎn)成字符串的
this.personId.attendees = window.btoa(this.personId.attendees);
this.personId.charge = window.btoa(this.personId.charge);
轉(zhuǎn)成字符串的
this.personId.attendees = window.btoa(this.personId.attendees.toString());
this.personId.charge = window.btoa(this.personId.attendees.toString());
因?yàn)樯厦娴膶σ粋€(gè)數(shù)組四個(gè)人一起加密處理的,后臺解密需要解密四次,我們可以將數(shù)組拆分成4個(gè)分開加密(有多少人分割成多少個(gè)數(shù)組再加密)。
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);
//對參與人進(jìn)行加密(可以多個(gè)人)
this.personId.attendees = window.btoa(result);
// console.log(this.personId.attendees);
//對主責(zé)人進(jìn)行加密處理(只能選一個(gè)人)
this.personId.charge = window.btoa(this.personId.attendees.toString());
數(shù)據(jù)結(jié)構(gòu)
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。