add clear
This commit is contained in:
@@ -16,6 +16,13 @@ class Account extends Miniprogarampage
|
||||
|
||||
private $savePath = __DIR__ . '/../../../';
|
||||
|
||||
|
||||
private $OK = 0;
|
||||
private $IllegalAesKey = -41001;
|
||||
private $IllegalIv = -41002;
|
||||
private $IllegalBuffer = -41003;
|
||||
private $DecodeBase64Error = -41004;
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*/
|
||||
@@ -42,6 +49,52 @@ class Account extends Miniprogarampage
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $encryptedData
|
||||
* @param $iv
|
||||
* @param $sessionKey
|
||||
* @param $asArray
|
||||
* @return object|array
|
||||
* @throws
|
||||
*
|
||||
* * <li>-41001: encodingAesKey 非法</li>
|
||||
* <li>-41003: aes 解密失败</li>
|
||||
* <li>-41004: 解密后得到的buffer非法</li>
|
||||
* <li>-41005: base64加密失败</li>
|
||||
* <li>-41016: base64解密失败</li>
|
||||
*/
|
||||
public function decode($encryptedData, $iv, $sessionKey, $asArray = false)
|
||||
{
|
||||
$config = Wx::getMiniProGaRamPage()->getConfig();
|
||||
if (strlen($sessionKey) != 24) {
|
||||
throw new \Exception('encodingAesKey 非法', $this->IllegalAesKey);
|
||||
}
|
||||
|
||||
$aesKey = base64_decode($sessionKey);
|
||||
if (strlen($iv) != 24) {
|
||||
throw new \Exception('base64解密失败', $this->IllegalIv);
|
||||
}
|
||||
|
||||
$aesIV = base64_decode($iv);
|
||||
$aesCipher = base64_decode($encryptedData);
|
||||
$result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, OPENSSL_RAW_DATA, $aesIV);
|
||||
if ($result === false) {
|
||||
throw new \Exception('aes 解密失败', $this->IllegalBuffer);
|
||||
}
|
||||
|
||||
$dataObj = json_decode($result);
|
||||
if ($dataObj->watermark->appid != $config->getAppid()) {
|
||||
throw new \Exception('aes 解密失败', $this->IllegalBuffer);
|
||||
}
|
||||
|
||||
if ($asArray) {
|
||||
return get_object_vars($dataObj);
|
||||
}
|
||||
|
||||
return $dataObj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
|
||||
Reference in New Issue
Block a user