You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace LaneWeChat\Core\Aes; // 定义命名空间,用于组织代码
class PKCS7Encoder // 定义PKCS7Encoder类
{
public static $block_size = 32; // 定义PKCS7编码的块大小固定为32字节
// 编码方法用于对数据进行PKCS7填充
function encode($text)
{
$block_size = PKCS7Encoder::$block_size; // 获取块大小
$text_length = strlen($text); // 获取原始数据长度
// 计算需要填充的字节数,使数据长度成为块大小的整数倍
$amount_to_pad = PKCS7Encoder::$block_size - ($text_length % PKCS7Encoder::$block_size);
// 如果数据长度已经是块大小的整数倍,则需要填充一个块大小的字节
if ($amount_to_pad == 0) {
$amount_to_pad = PKCS7Encoder::block_size;
}
$pad_chr = chr($amount_to_pad); // 将需要填充的字节数转换为字符
$tmp = ""; // 初始化临时字符串,用于构建填充字符
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr; // 重复填充字符
}
// 返回填充后的数据
return $text . $tmp;
}
// 解码方法用于移除PKCS7填充
function decode($text)
{
$pad = ord(substr($text, -1)); // 获取最后一个字符的ASCII值即填充的字节数
// 如果填充的字节数不在1到32之间则认为没有填充
if ($pad < 1 || $pad > 32) {
$pad = 0;
}
// 返回移除填充后的数据
return substr($text, 0, (strlen($text) - $pad));
}
}
?>
命名空间声明namespace LaneWeChat\Core; 定义了类的命名空间表明这个类属于LaneWeChat模块的核心部分。
类定义class Menu 定义了一个用于管理微信自定义菜单的类。
setMenu方法用于创建自定义菜单。处理菜单数据将一维数组转换为树形结构支持子菜单并发送POST请求到微信服务器。
getMenu方法用于获取当前公众号的自定义菜单信息。发送GET请求到微信服务器。
delMenu方法用于删除当前公众号的自定义菜单。发送GET请求到微信服务器
命名空间声明namespace LaneWeChat\Core; 定义了类的命名空间表明这个类属于LaneWeChat模块的核心部分。
类定义class Menu 定义了一个用于管理微信自定义菜单的类。
setMenu方法用于创建自定义菜单。处理菜单数据将一维数组转换为树形结构支持子菜单并发送POST请求到微信服务器。
getMenu方法用于获取当前公众号的自定义菜单信息。发送GET请求到微信服务器。
delMenu方法用于删除当前公众号的自定义菜单。发送GET请求到微信服务器