我手上有两个版本的wxBizDataCrypt.php,都是2018年的,而官网下载的(较旧)根本用不成,用较新的也解密不出openGId,总是-41003,有没有可能是wxBizDataCrypt.php的问题?
class WXBizDataCrypt
{
private $appid;
private $sessionKey;
/**
* 鏋勯�鍑芥暟
* [@param](/user/param) $sessionKey string 鐢ㄦ埛鍦ㄥ皬绋嬪簭鐧诲綍鍚庤幏鍙栫殑浼氳瘽瀵嗛挜
* [@param](/user/param) $appid string 灏忕▼搴忕殑appid
*/
public function __construct( $appid, $sessionKey)
{
$this->sessionKey = $sessionKey;
$this->appid = $appid;
}
/**
* 妫�獙鏁版嵁鐨勭湡瀹炴�锛屽苟涓旇幏鍙栬В瀵嗗悗鐨勬槑鏂�
* [@param](/user/param) $encryptedData string 鍔犲瘑鐨勭敤鎴锋暟鎹�
* [@param](/user/param) $iv string 涓庣敤鎴锋暟鎹竴鍚岃繑鍥炵殑鍒濆鍚戦噺
* [@param](/user/param) $data string 瑙e瘑鍚庣殑鍘熸枃
*
* [@return](/user/return) int 鎴愬姛0锛屽け璐ヨ繑鍥炲搴旂殑閿欒鐮�
*/
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);//旧版用的是这个
$result=mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $aesKey, base64_decode($aesCipher), MCRYPT_MODE_CBC, $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;
}
}
这个文件有没有问题呢?