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