add clear
This commit is contained in:
+51
-33
@@ -7,56 +7,80 @@ namespace wchat\common;
|
||||
class Decode
|
||||
{
|
||||
|
||||
private $sessionKey;
|
||||
private $iv;
|
||||
private $encryptedData;
|
||||
private $appId;
|
||||
private string $sessionKey;
|
||||
private string $iv;
|
||||
private string $encryptedData;
|
||||
private string $appId;
|
||||
|
||||
|
||||
private $OK = 0;
|
||||
private $IllegalAesKey = -41001;
|
||||
private $IllegalIv = -41002;
|
||||
private $IllegalBuffer = -41003;
|
||||
private $DecodeBase64Error = -41004;
|
||||
private int $OK = 0;
|
||||
private int $IllegalAesKey = -41001;
|
||||
private int $IllegalIv = -41002;
|
||||
private int $IllegalBuffer = -41003;
|
||||
private int $DecodeBase64Error = -41004;
|
||||
|
||||
/**
|
||||
* @param mixed $sessionKey
|
||||
* @return Decode
|
||||
* @return string
|
||||
*/
|
||||
public function setSessionKey($sessionKey)
|
||||
public function getSessionKey(): string
|
||||
{
|
||||
return $this->sessionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sessionKey
|
||||
*/
|
||||
public function setSessionKey(string $sessionKey): void
|
||||
{
|
||||
$this->sessionKey = $sessionKey;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $iv
|
||||
* @return Decode
|
||||
* @return string
|
||||
*/
|
||||
public function setIv($iv)
|
||||
public function getIv(): string
|
||||
{
|
||||
return $this->iv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iv
|
||||
*/
|
||||
public function setIv(string $iv): void
|
||||
{
|
||||
$this->iv = $iv;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $encryptedData
|
||||
* @return Decode
|
||||
* @return string
|
||||
*/
|
||||
public function setEncryptedData($encryptedData)
|
||||
public function getEncryptedData(): string
|
||||
{
|
||||
return $this->encryptedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $encryptedData
|
||||
*/
|
||||
public function setEncryptedData(string $encryptedData): void
|
||||
{
|
||||
$this->encryptedData = $encryptedData;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $appId
|
||||
* @return Decode
|
||||
* @return string
|
||||
*/
|
||||
public function setAppId($appId)
|
||||
public function getAppId(): string
|
||||
{
|
||||
return $this->appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $appId
|
||||
*/
|
||||
public function setAppId(string $appId): void
|
||||
{
|
||||
$this->appId = $appId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +89,7 @@ class Decode
|
||||
* @return array|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function decode($asArray)
|
||||
public function decode($asArray): object|array
|
||||
{
|
||||
if (strlen($this->sessionKey) != 24) {
|
||||
throw new \Exception('encodingAesKey 非法', $this->IllegalAesKey);
|
||||
@@ -87,13 +111,7 @@ class Decode
|
||||
if ($dataObj->watermark->appid != $this->appId) {
|
||||
throw new \Exception('aes 解密失败', $this->IllegalBuffer);
|
||||
}
|
||||
|
||||
if ($asArray) {
|
||||
return get_object_vars($dataObj);
|
||||
}
|
||||
|
||||
return $dataObj;
|
||||
|
||||
return $asArray ? get_object_vars($dataObj) : $dataObj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user