前段时间研究了微信小微商户,地址:https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=19_11php
其接口操做中须要下载证书针对返回的密文用 AEAD_AES_256_GCM 算法解密git
其中用到了 string sodium_crypto_aead_aes256gcm_decrypt ( string $ciphertext , string $ad , string $nonce , string $key ) 这个函数github
可是这个函数可能调用的时候会报错,那是由于使用这个函数须要开启 libsodium 扩展才能使用算法
官方文档上面对该扩展的说明以下:windows
As of PHP 7.2.0 this extension is bundled with PHP. For older PHP versions this extension is available via PECL.api
从php 7.2.0开始,这个扩展与php捆绑在一块儿。对于旧的PHP版本,此扩展可经过pecl得到。微信
windows 安装方法函数
(PHP ≥ 7.2) 直接去 php.ini 开启扩展就行 ,extension=php_sodium.dll 。由于 PHP7.2 版本后 PHP core 中就整合加密库 Libsodium
(PHP < 7.2.0) 须要安装,libsodium PECL 地址 http://pecl.php.net/package/libsodium而后下载 DLL 文件测试
下载完成后解压,而后this
对于PHP 7如下版本windows上我测试了php 5.6,1.0.6 version 能安装可是不能使用 sodium_crypto_aead_aes256gcm_decrypt 函数。
由于5.6上支持的版本为1.0.6,而只有大于1.0.8的版本才支持此函数。
Sodium Compat PHP 类库,网上说旧的PHP上可使用这个类库实现。
Sodium Compat 是用于 Sodium 加密库(libsodium)的纯 PHP 填充,它是 PHP 7.2.0+ 的核心扩展,也可用于 PECL。
这个库 tentativeley 支持PHP 5.2.4 - 7.x(最新版),但官方只支持非 EOL 版本的 PHP。
若是安装了 PHP 扩展,Sodium Compat 将机会性地透明地使用 PHP 扩展而不是咱们的实现。
github 地址: https://github.com/paragonie/sodium_compat
实际证实没法实现,由于低于7.1版本的php_openssl,不支持AEAD_AES_256_GCM算法的加密和解密。
因此只能使用7.1以上的PHP版原本解决了。
外文链接:https://paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-libsodium
做者:旧旧的 <393210556@qq.com> 解决问题的方式,就是解决它一次