- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明 Made-with: Cursor
74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ScottPan Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace crmeb\services\wechat\util;
|
|
|
|
|
|
use Closure;
|
|
|
|
/**
|
|
* 帮助类
|
|
* Class Helper
|
|
* @author 等风来
|
|
* @email 136327134@qq.com
|
|
* @date 2023/9/18
|
|
* @package crmeb\services\wechat\util
|
|
*/
|
|
class Helper
|
|
{
|
|
/**
|
|
* 获取加密方式
|
|
* @param string $signType
|
|
* @param string $secretKey
|
|
* @return Closure|string
|
|
* @author 等风来
|
|
* @email 136327134@qq.com
|
|
* @date 2023/9/18
|
|
*/
|
|
public static function getEncryptMethod(string $signType, string $secretKey = ''): string|Closure
|
|
{
|
|
if ('HMAC-SHA256' === $signType) {
|
|
return function ($str) use ($secretKey) {
|
|
return hash_hmac('sha256', $str, $secretKey);
|
|
};
|
|
}
|
|
|
|
return 'md5';
|
|
}
|
|
|
|
/**
|
|
* 生成签名
|
|
* @param array $attributes
|
|
* @param string $key
|
|
* @param string $encryptMethod
|
|
* @return string
|
|
* @author 等风来
|
|
* @email 136327134@qq.com
|
|
* @date 2023/9/14
|
|
*/
|
|
public static function generateSign(array $attributes, string $key, string $encryptMethod = 'md5'): string
|
|
{
|
|
ksort($attributes);
|
|
|
|
$attributes['key'] = $key;
|
|
|
|
return strtoupper(call_user_func_array($encryptMethod, [urldecode(http_build_query($attributes))]));
|
|
}
|
|
|
|
/**
|
|
* 截取数据
|
|
* @param string $tel
|
|
* @return array|string|string[]
|
|
* @author 等风来
|
|
* @email 136327134@qq.com
|
|
* @date 2023/9/15
|
|
*/
|
|
public static function encryptTel(string $tel)
|
|
{
|
|
return substr_replace($tel, '****', 3, 4);
|
|
}
|
|
|
|
}
|