后臺返回一個(gè)鏈接地址imageUrl瓣颅,需要我們用這個(gè)地址發(fā)送請求春塌,然后返回arrayBuffer文件流寝姿,我們需要做的就是將buffer文件流轉(zhuǎn)換成base64
1儡毕、小程序處理圖形驗(yàn)證碼(如果返回的是http的鏈接 const?imageUrl?=kaptcha.replace('http','https') 要這樣處理一下)
wx.request({
????????url:imageUrl, //返回的鏈接地址(一定要是https的也切,http的不行)
????????responseType:?'arraybuffer',?
????????method:'post',
????????header:{
??????????'content-type':?'application/x-www-form-urlencoded',
??????????'Origin':?'http://www.4pis.cn'
????????},
????????success(res){
??????????let?base64?=?wx.arrayBufferToBase64(res.data)
??????????_self.imgSrc?='data:image/png;base64,'+base64.replace(/[\r\n]/g,?"")
????????}
??????})
2、h5處理圖形驗(yàn)證碼)
?axios.get(url,{?responseType:?"arraybuffer"}).then(res=>{let?path?=?'data:image/png;base64,'?+?btoa(new?Uint8Array(res.data).reduce((data,?byte)?=>?data?+?String.fromCharCode(byte),?''))
? ? ? ? _self.imageUrl?=?path??????
? ? ? ?})