diff --git a/core/aes/pkcs7encoder.lib.php b/core/aes/pkcs7encoder.lib.php index 513b3ae..173d263 100644 --- a/core/aes/pkcs7encoder.lib.php +++ b/core/aes/pkcs7encoder.lib.php @@ -1,32 +1,40 @@ 32) { $pad = 0; } + // 返回移除填充后的数据 return substr($text, 0, (strlen($text) - $pad)); } -} \ No newline at end of file +} +?> \ No newline at end of file diff --git a/core/aes/sha1.lib.php b/core/aes/sha1.lib.php index 753d8fe..06cf6a3 100644 --- a/core/aes/sha1.lib.php +++ b/core/aes/sha1.lib.php @@ -1,17 +1,27 @@ \ No newline at end of file diff --git a/core/aes/wxbizmsgcrypt.lib.php b/core/aes/wxbizmsgcrypt.lib.php index 3e6f63c..77f4e73 100644 --- a/core/aes/wxbizmsgcrypt.lib.php +++ b/core/aes/wxbizmsgcrypt.lib.php @@ -1,12 +1,13 @@ token = $token; @@ -14,11 +15,17 @@ class WXBizMsgCrypt $this->appId = $appId; } + // 加密消息方法 public function encryptMsg($replyMsg, $timeStamp, $nonce, &$encryptMsg) { - $pc = new Prpcrypt($this->encodingAesKey); - $array = $pc->encrypt($replyMsg, $this->appId); - $ret = $array[0]; + $pc = new Prpcrypt($this->encodingAesKey); // 实例化Prpcrypt类,用于消息加密 + $array = $pc->encrypt($replyMsg, $this->appId); // 调用encrypt方法进行消息加密 + $ret = $array[0]; // 获取加密结果的状态码 if ($ret != 0) { - return $ret; - \ No newline at end of file + return $ret; // 如果加密失败,返回错误码 + } + // 省略了后续代码,但通常这里会将加密后的消息、时间戳、随机数等信息 + // 格式化为XML格式,并赋值给$encryptMsg变量 + } +} +?> \ No newline at end of file diff --git a/core/aes/xmlparse.lib.php b/core/aes/xmlparse.lib.php index 4d56da8..9a1c164 100644 --- a/core/aes/xmlparse.lib.php +++ b/core/aes/xmlparse.lib.php @@ -1,31 +1,43 @@ loadXML($xmltext); + $xml = new \DOMDocument(); // 创建DOMDocument对象 + $xml->loadXML($xmltext); // 加载XML文本 + + // 使用DOMDocument对象的getElementsByTagName方法获取Encrypt和ToUserName标签 $array_e = $xml->getElementsByTagName('Encrypt'); $array_a = $xml->getElementsByTagName('ToUserName'); + + // 获取Encrypt标签的文本内容和ToUserName标签的文本内容 $encrypt = $array_e->item(0)->nodeValue; $tousername = $array_a->item(0)->nodeValue; + + // 返回提取结果,包括状态码0(表示成功),加密信息和接收方账号 return array(0, $encrypt, $tousername); } catch (\Exception $e) { + // 如果发生异常,返回错误码和null值 return array(ErrorCode::$ParseXmlError, null, null); } } + // 生成方法,用于生成XML格式的响应消息 public function generate($encrypt, $signature, $timestamp, $nonce) { + // 定义XML格式的字符串模板,使用CDATA区包含加密信息和其他参数 $format = " %s "; + + // 使用sprintf函数格式化XML字符串模板,插入加密信息和其他参数 return sprintf($format, $encrypt, $signature, $timestamp, $nonce); } }