You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
payment/app/Helper/Baofu/Tool.php

93 lines
2.6 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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;
}
}