first commit
This commit is contained in:
57
pgserver/application/util/BOCSign.php
Normal file
57
pgserver/application/util/BOCSign.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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加密算法
|
||||
* ],
|
||||
*/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user