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.

28 lines
925 B

2 months ago
<?php
namespace LaneWeChat\Core\Aes; // 定义命名空间,用于组织代码
2 months ago
class SHA1 // 定义SHA1类
2 months ago
{
// getSHA1方法用于生成SHA1哈希值
2 months ago
public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
{
try {
// 创建一个数组包含加密消息、Token、时间戳和随机数
2 months ago
$array = array($encrypt_msg, $token, $timestamp, $nonce);
// 对数组元素进行字符串排序
2 months ago
sort($array, SORT_STRING);
// 将数组元素连接成一个字符串
2 months ago
$str = implode($array);
// 生成该字符串的SHA1哈希值并返回
2 months ago
return array(ErrorCode::$OK, sha1($str));
} catch (\Exception $e) {
// 如果发生异常返回错误码和null值
2 months ago
return array(ErrorCode::$ComputeSignatureError, null);
}
}
}
?>