decode() public method

对解密后的明文进行补位删除
public decode ( string $text ) : string
$text string 解密后的明文
return string 删除填充补位后的明文
 /**
  * 对密文进行解密
  * @param string $encrypted 需要解密的密文
  * @return string 解密得到的明文
  */
 public function decrypt($encrypted, $appid)
 {
     try {
         //使用BASE64对需要解密的字符串进行解码
         $ciphertext_dec = base64_decode($encrypted);
         $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
         $iv = substr($this->key, 0, 16);
         mcrypt_generic_init($module, $this->key, $iv);
         //解密
         $decrypted = mdecrypt_generic($module, $ciphertext_dec);
         mcrypt_generic_deinit($module);
         mcrypt_module_close($module);
     } catch (Exception $e) {
         @error_log('Decrypt AES Error: ' . $e->getMessage(), 0);
         return FALSE;
     }
     try {
         //去除补位字符
         $pkc_encoder = new Pkcs7Encoder();
         $result = $pkc_encoder->decode($decrypted);
         //去除16位随机字符串,网络字节序和AppId
         if (strlen($result) < 16) {
             return "";
         }
         $content = substr($result, 16, strlen($result));
         $len_list = unpack("N", substr($content, 0, 4));
         $xml_len = $len_list[1];
         $xml_content = substr($content, 4, $xml_len);
         $from_appid = substr($content, $xml_len + 4);
     } catch (Exception $e) {
         @error_log('Illegal Buffer: ' . $e->getMessage(), 0);
         return FALSE;
     }
     if ($from_appid != $appid) {
         @error_log('Validate Appid Error: ' . $e->getMessage(), 0);
         return FALSE;
     }
     return $xml_content;
 }