diff --git a/wx/Account.php b/wx/Account.php
index 3513e1a..fdf9549 100644
--- a/wx/Account.php
+++ b/wx/Account.php
@@ -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
+ *
+ * *
-41001: encodingAesKey 非法
+ * -41003: aes 解密失败
+ * -41004: 解密后得到的buffer非法
+ * -41005: base64加密失败
+ * -41016: base64解密失败
+ */
+ 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
diff --git a/wx/Help.php b/wx/Help.php
index 0c6ddf8..a084675 100644
--- a/wx/Help.php
+++ b/wx/Help.php
@@ -6,58 +6,7 @@ namespace wchat;
class Help extends Miniprogarampage
{
- public static $OK = 0;
- public static $IllegalAesKey = -41001;
- public static $IllegalIv = -41002;
- public static $IllegalBuffer = -41003;
- public static $DecodeBase64Error = -41004;
-
- /**
- * @param $encryptedData
- * @param $iv
- * @param $sessionKey
- * @param $asArray
- * @return object|array
- * @throws
- *
- * * -41001: encodingAesKey 非法
- * -41003: aes 解密失败
- * -41004: 解密后得到的buffer非法
- * -41005: base64加密失败
- * -41016: base64解密失败
- */
- public static function decode($encryptedData, $iv, $sessionKey, $asArray = false)
- {
- $config = Wx::getMiniProGaRamPage()->getConfig();
- if (strlen($sessionKey) != 24) {
- throw new \Exception('encodingAesKey 非法', self::$IllegalAesKey);
- }
-
- $aesKey = base64_decode($sessionKey);
- if (strlen($iv) != 24) {
- throw new \Exception('base64解密失败', self::$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 解密失败', self::$IllegalBuffer);
- }
-
- $dataObj = json_decode($result);
- if ($dataObj->watermark->appid != $config->getAppid()) {
- throw new \Exception('aes 解密失败', self::$IllegalBuffer);
- }
-
- if ($asArray) {
- return get_object_vars($dataObj);
- }
-
- return $dataObj;
- }
-
-
+
/**
* @param array $data
* @return string