微信小程序 WXBizDataCrypt 解密 报错

版权声明:转载请评论留言 https://blog.csdn.net/solocao/article/details/89762615

在使用微信官方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.
message: Illegal Buffer, stack: Error: Illegal Buffer at WXBizDataCrypt.decryptData

这种错误一定概率出现,一般出现在项目初始化的时候。
我一开始还以为是Buffer库的问题,使用了safer-buffer替换,还是没有解决。
网上还有人说需要encodeURIComponent对参数包裹,这也不能解决。

其实,最后的解决办法,就是在小程序端通过open-type="getUserInfo"获取参数之前,必须要wx.login
所以,重要的事情说三遍:

wx.login wx.login wx.login必须先执行。

猜你喜欢

转载自blog.csdn.net/solocao/article/details/89762615
今日推荐