Oct1a

win32_load:could not load the shared library

淦,今天终于把这个问题解决了,之前一直很奇怪的bug,只要在window系统上涉及到加密这一块,总会出现这个问题,例如crypto,微信支付,支付宝支付..google也找不到任何答案,但在部署到linux上就没问题,所以后面操作都是同步到服务器上进行修改,这次又遇到这个问题就想给他解决掉。

错误信息:

Error: error:25078067:DSO support routines:win32_load:could not load the shared library

Error: error:25078067:DSO support routines:win32_load:could not load the shared library
    at Sign.sign (node:internal/crypto/sig:131:29)
    at Pay.sha256WithRsa (xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:144:71)
    at Pay.getSignature (xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:107:21)
    at Pay.init (xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:198:30)
    at Pay.<anonymous> (xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:332:46)
    at step (xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:44:23)
    at Object.next (xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:25:53)
    at xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:19:71
    at new Promise (<anonymous>)
    at __awaiter (xxxxxxxx\node_modules\wechatpay-node-v3\dist\index.js:15:12) {
  opensslErrorStack: [
    'error:0E076071:configuration file routines:module_run:unknown module name',
    'error:0E07506E:configuration file routines:module_load_dso:error loading dso',
    'error:25070067:DSO support routines:DSO_load:could not load the shared library'
  ],
  library: 'DSO support routines',
  function: 'win32_load',
  reason: 'could not load the shared library',
  code: 'ERR_OSSL_DSO_COULD_NOT_LOAD_THE_SHARED_LIBRARY'
}

为何发生错误:

因为我早期需要打包密钥文件,从官网下载了openssl的安装包进行安装,但后面没用到了,就扔在那了,也没去卸载

因为接入的支付宝和微信支付都会用到crypto这个库,这个库会调用系统的openssl进行编译?但我自行安装的可能有点问题或者就是无法版本不对,导致无法调用。

解决方法:

  1. 如果系统上已经有安装了openssl,如何判断已经有安装?卸载掉,或者删除系统环境变量(找到openssl)
  2. 安装git(一般程序员系统都自带这个了,可忽略)
  3. 添加系统环境变量(Path)
    git的安装目录\usr\bin 例如:D:\System\Git\usr\bin
    
    测试命令操作符窗口中输入openssl,查看是否可以使用

这样就可以了,这样我们就是直接调用git自带的openssl,就不用自己手动安装,免得出各种问题。如果也能帮到你的话,记得赏我杯咖啡…

参考资料:
ssl - How to install OpenSSL in windows 10? - Stack Overflow

本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可。