PHP7.2 下 微信支付Sdk中 mcrypt_module_open() 无法使用的解决方法

微信官方SDK在PHP7中提示:mcrypt_module_open() is deprecated,mcrypt已被OPENSSL代替 具体修改如下

1:WXBizDataCrypt.php

public function decryptData( $encryptedData, $iv, &$data )

{
    if (strlen($this->sessionKey) != 24) {
        return ErrorCode::$IllegalAesKey;
    }
    $aesKey=base64_decode($this->sessionKey);
    
    if (strlen($iv) != 24) {
        return ErrorCode::$IllegalIv;
    }
    $aesIV=base64_decode($iv);
    // $aesCipher=base64_decode($encryptedData);
    $aesCipher=$encryptedData;
    $pc = new Prpcrypt($aesKey);
    $result = $pc->decrypt($aesCipher,$aesIV);
    var_dump($result);
    if ($result[0] != 0) {
        return $result[0];
    }
 
    $dataObj=json_decode( $result[1] );
    if( $dataObj  == NULL )
    {
        return ErrorCode::$IllegalBuffer.'--';
    }
    if( $dataObj->watermark->appid != $this->appid )
    {
        return ErrorCode::$IllegalBuffer.';;';
    }
    $data = $result[1];
    return ErrorCode::$OK;
}

2:PKCS7Encoder.php

/**

 * 对密文进行解密
 * [@param](https://my.oschina.net/u/2303379) string $aesCipher 需要解密的密文
 * [@param](https://my.oschina.net/u/2303379) string $aesIV 解密的初始向量
 * [@return](https://my.oschina.net/u/556800) string 解密得到的明文
 */
public function decrypt( $aesCipher, $aesIV )
{
    try {
        
        // $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
        
        // mcrypt_generic_init($module, $this->key, $aesIV);
        // //解密
        // $decrypted = mdecrypt_generic($module, $aesCipher);
        // mcrypt_generic_deinit($module);
        // mcrypt_module_close($module);
        $decrypted = openssl_decrypt($aesCipher,'AES-128-CBC',$this->key,OPENSSL_ZERO_PADDING,$aesIV);
        // var_dump($decrypted);
    } catch (Exception $e) {
        return array(ErrorCode::$IllegalBuffer, null);
    }
    try {
        //去除补位字符
        $pkc_encoder = new PKCS7Encoder;
        $result = $pkc_encoder->decode($decrypted);
    } catch (Exception $e) {
        //print $e;
        return array(ErrorCode::$IllegalBuffer, null);
    }
    return array(0, $result);
}

转载于:https://my.oschina.net/kopa/blog/1786077

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值