在使用微信官方WXBizDataCrypt.js解密encryptedData獲取敏感數據的時候,偶爾會報錯。 DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(),Buffer.allocUnsafe(), or Buffer.from() methods instead. 1 2 message: Illegal Buffer, stack: Error: Illegal Buffer at WXBizDataCrypt.decryptData 1 這種錯誤一定概率出現,一般出現在項目初始化的時候。 我一開始還以為是Buffer庫的問題,使用了safer-buffer替換,還是沒有解決。 網上還有人說需要encodeURIComponent對參數包裹,這也不能解決。 其實,最后的解決辦法,就是在小程序端通過open-type="getUserInfo"獲取參數之前,必須要wx.login。