Files
pgserver3.0/pgserver/application/util/BOCSign.php
annnj-company 130c1026c4 first commit
2026-04-17 18:29:53 +08:00

58 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\util;
use think\facade\Cache;
class BOCSign {
/**
* md5 加密
*/
public static function serPassword($data){
return md5($data,\config('api.password_pre_halt'));
}
/**
* 生成每次请求Sign字符串
*/
public static function setSign($data = []) {
// 按字段排序
\ksort($data);
//拼接字符串数据
$string = \http_build_query($data);
//通过 aes 来加密
$string = (new Aes(\config('api.aes_key')))->aesEn($string);
return $string;
}
/**
* 检测sign是否正常
*/
public static function checkSignPass($data) {
$str = (new Aes(\config('api.aes_key')))->aesDe($data);
// 判断解析出来的数据是否为空
if(empty($str)){
return false;
}
// 字符串转数组
parse_str($str,$arr);
// 判断是否是数组,数组内的字段是否正确
if(!\is_array($arr) || empty($arr['mg'])){
return false;
}
// 检测缓存,如果有缓存,说明这个sign已经被使用
if(Cache::get($data)){
return false;
}
return true;
}
/**
*'aes_key' =>[
* 'key' => 'reter4446fdfgdfgdfg', //加密key这个可以随便定义
* 'iv' => md5(time(). uniqid(),true), //保证偏移量为16位
* 'method' => 'AES-128-CBC' //加密方式 # AES-256-CBC等这个可以搭配的形式有很多具体的你可以去了解一下AES加密算法
* ],
*/
}