用官方微信的demo解密用户信息失败 41003
$appid = 'wx9fbecb7ad34400d9';
$encryptedData = '1pN4f9GuYPMq+VaKO4xSMn/nKJAUZaG0
saoSNEM+MKD6ScSeOKxIoxPeJ/6xRrkg
PwzK9eU1Olw35KgZUXxsU9wwzgwKhJvQ
vFwKqHsqN9CTuLjHqRsaa8XSkO03AX2j
br1rZ5CjjHj9QmqvPfk0WAiLE4WBa4Wb
EGT7HR/HVRFPpruP02LjMhI0mZe2tFsP
AuI1v/ClcYmA2RlY1OsVug==';
$iv = 'QctwyPwtqTHFAGYeaUZ4Kg==';
$session_key = '6OQ1d3NdlVp7ZgLJJIjWeg==';
$pc = new WXBizDataCrypt($appid, $session_key);
$errCode = $pc->decryptData($encryptedData, $iv, $data );
if ($errCode == 0) {
print($data . "\n");
} else {
print($errCode . "\n");
}
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);//这里解密出问题了,是乱码
$result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
$dataObj=json_decode( $result );
if( $dataObj == NULL )
{
return ErrorCode::$IllegalBuffer;
}
if( $dataObj->watermark->appid != $this->appid )
{
return ErrorCode::$IllegalBuffer;
}
$data = $result;
return ErrorCode::$OK;
}
乱码类似:"?x?`?*?V?;?R2?(?e????4C>0??I?8?H??'??F? ????5:\7?Q|lS?0? ??
本文网址:http://www.91bianli.com/weixinxiaochengxu/36944.html