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.
git-test/core/aes/wxbizmsgcrypt.lib.php

31 lines
1.1 KiB

2 months ago
<?php
namespace LaneWeChat\Core\Aes; // 定义命名空间,用于组织代码
2 months ago
class WXBizMsgCrypt // 定义WXBizMsgCrypt类
2 months ago
{
private $token; // 微信Token
private $encodingAesKey; // 微信EncodingAESKey
private $appId; // 微信AppId
2 months ago
// 类构造函数用于初始化Token、EncodingAESKey和AppId
2 months ago
public function __construct($token, $encodingAesKey, $appId)
{
$this->token = $token;
$this->encodingAesKey = $encodingAesKey;
$this->appId = $appId;
}
// 加密消息方法
2 months ago
public function encryptMsg($replyMsg, $timeStamp, $nonce, &$encryptMsg)
{
$pc = new Prpcrypt($this->encodingAesKey); // 实例化Prpcrypt类用于消息加密
$array = $pc->encrypt($replyMsg, $this->appId); // 调用encrypt方法进行消息加密
$ret = $array[0]; // 获取加密结果的状态码
2 months ago
if ($ret != 0) {
return $ret; // 如果加密失败,返回错误码
}
// 省略了后续代码,但通常这里会将加密后的消息、时间戳、随机数等信息
// 格式化为XML格式并赋值给$encryptMsg变量
}
}
?>