|
|
<?php
|
|
|
|
|
|
namespace App\Helper\Baofu;
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
class Tool
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 生成时间戳
|
|
|
* @return int|false
|
|
|
*/
|
|
|
public static function getTransid()
|
|
|
{
|
|
|
return strtotime(date('Y-m-d H:i:s', time()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成四位随机数
|
|
|
* @return int
|
|
|
*/
|
|
|
public static function getRand4()
|
|
|
{
|
|
|
return rand(1000, 9999);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成四位随机数
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getTime()
|
|
|
{
|
|
|
return date('YmdHis', time());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 明文请求参数
|
|
|
* @return type
|
|
|
*/
|
|
|
public static function getPostParm($txnSubType, $encrypted)
|
|
|
{
|
|
|
if($txnSubType == null || $txnSubType == ''){
|
|
|
throw new Exception('方法:getPostParm,参数:txn_sub_type 异常为空!');
|
|
|
}
|
|
|
if($encrypted == null || $encrypted == ''){
|
|
|
throw new Exception('方法:getPostParm,参数:encrypted 异常为空!');
|
|
|
}
|
|
|
|
|
|
$data = [];
|
|
|
$data['version'] = $GLOBALS['version'];
|
|
|
$data['member_id'] = $GLOBALS['member_id'];
|
|
|
$data['terminal_id'] = $GLOBALS['terminal_id'];
|
|
|
$data['txn_type'] = $GLOBALS['txn_type'];
|
|
|
$data['txn_sub_type'] = $txnSubType;
|
|
|
$data['data_type'] = $GLOBALS['data_type'];
|
|
|
$data['data_content'] = $encrypted;
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取待加密串
|
|
|
* @param string $paramStr
|
|
|
* @param array $paramList
|
|
|
* @param array $signData
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public static function getSignStr($paramStr, $paramList, $signData, $action = 'request')
|
|
|
{
|
|
|
foreach($paramList as $value) {
|
|
|
if (empty($signData[$value]) || $signData[$value] == 'null') {
|
|
|
if($action == 'request'){ // 请求
|
|
|
$paramStr = str_replace($value, '', $paramStr);
|
|
|
} else { // 响应
|
|
|
$paramStr = str_replace($value . '|', '', $paramStr);
|
|
|
$paramStr = str_replace('|' .$value, '', $paramStr);
|
|
|
}
|
|
|
continue;
|
|
|
}elseif (!array_key_exists($value, $signData)){
|
|
|
throw new Exception('缺少['.$value.']参数!');
|
|
|
}
|
|
|
|
|
|
if (is_array($signData[$value])){
|
|
|
$signData[$value] = json_encode($signData[$value]);
|
|
|
}
|
|
|
|
|
|
$paramStr = str_replace($value, $signData[$value], $paramStr);
|
|
|
}
|
|
|
return $paramStr;
|
|
|
}
|
|
|
}
|
|
|
|