From 0841725b982bdfcf2be6a10544afe3c97626270b Mon Sep 17 00:00:00 2001
From: pfspx4a7z <2942132918@qq.com>
Date: Wed, 8 Jan 2025 21:42:43 +0800
Subject: [PATCH] Update demo.php
---
core/aes/demo.php | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/core/aes/demo.php b/core/aes/demo.php
index 03ab358..f2f362a 100644
--- a/core/aes/demo.php
+++ b/core/aes/demo.php
@@ -10,16 +10,18 @@ $nonce = "xxxxxx";
$appId = "wxb11529c136998cb6";
$text = "1407743423";
-
+// 初始化WXBizMsgCrypt对象
$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
$encryptMsg = '';
+// 加密消息
$errCode = $pc->encryptMsg($text, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0) {
- print("加密后: " . $encryptMsg . "\n");
+ print("加密后: " . $encryptMsg . "\n");
} else {
- print($errCode . "\n");
+ print($errCode . "\n");
}
+// 解析加密后的XML消息
$xml_tree = new DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
@@ -27,19 +29,23 @@ $array_s = $xml_tree->getElementsByTagName('MsgSignature');
$encrypt = $array_e->item(0)->nodeValue;
$msg_sign = $array_s->item(0)->nodeValue;
+// 构造解密的XML格式
$format = "";
$from_xml = sprintf($format, $encrypt);
-// 第三方收到公众号平台发送的消息
+// 解密消息
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
- print("解密后: " . $msg . "\n");
+ print("解密后: " . $msg . "\n");
} else {
- print($errCode . "\n");
+ print($errCode . "\n");
}
-命名空间声明:namespace LaneWeChat\Core; 定义了类的命名空间,表明这个类属于LaneWeChat模块的核心部分。
-类定义:class Menu 定义了一个用于管理微信自定义菜单的类。
-setMenu方法:用于创建自定义菜单。处理菜单数据,将一维数组转换为树形结构,支持子菜单,并发送POST请求到微信服务器。
-getMenu方法:用于获取当前公众号的自定义菜单信息。发送GET请求到微信服务器。
-delMenu方法:用于删除当前公众号的自定义菜单。发送GET请求到微信服务器
+命名空间声明:namespace LaneWeChat\Core\Aes; 定义了类的命名空间,表明这个脚本属于LaneWeChat模块的Aes部分。
+引入类库:include_once "wxBizMsgCrypt.php"; 引入用于消息加密和解密的类库。
+初始化参数:定义了用于加密和解密的参数,包括 encodingAesKey、token、timeStamp、nonce 和 appId。
+初始化WXBizMsgCrypt对象:创建 WXBizMsgCrypt 对象,用于消息的加密和解密。
+加密消息:调用 encryptMsg 方法对消息进行加密,并输出加密后的结果。
+解析加密后的XML消息:使用 DOMDocument 解析加密后的XML消息,提取 Encrypt 和 MsgSignature 的值。
+构造解密的XML格式:构造用于解密的XML格式。
+解密消息:调用 decryptMsg 方法对消息进行解密,并输出解密后的结果。
\ No newline at end of file