chore(addon): 添加线下支付及华为支付基本配置
This commit is contained in:
@@ -321,7 +321,6 @@ function date_to_time($date)
|
||||
|
||||
/**
|
||||
* 获取唯一随机字符串
|
||||
* 创建时间:2018年8月7日15:54:16
|
||||
*/
|
||||
function unique_random($len = 10)
|
||||
{
|
||||
@@ -375,6 +374,8 @@ function http($url, $timeout = 30, $header = array ())
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 关闭 SSL 证书校验
|
||||
|
||||
if (!empty($header)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||||
}
|
||||
@@ -423,9 +424,8 @@ function replace_array_element($array, $replace)
|
||||
|
||||
/**
|
||||
* 过滤特殊符号
|
||||
* 创建时间:2018年1月30日15:39:32
|
||||
* @param unknown $string
|
||||
* @return mixed
|
||||
* @param $string
|
||||
* @return array|string|string[]|null
|
||||
*/
|
||||
function ihtmlspecialchars($string)
|
||||
{
|
||||
@@ -693,13 +693,13 @@ function success($code = 0, $message = '', $data = '')
|
||||
|
||||
/**
|
||||
* 实例化Model
|
||||
*
|
||||
* @param string $name
|
||||
* Model名称
|
||||
* @param string $table
|
||||
* @param array $option
|
||||
* @return \app\model\Model
|
||||
*/
|
||||
function model($table = '')
|
||||
function model($table = '', $option = [])
|
||||
{
|
||||
return new \app\model\Model($table);
|
||||
return new \app\model\Model($table, $option);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1164,12 +1164,27 @@ function string_split($string, $delimiter, $value)
|
||||
* $str为要进行截取的字符串,$length为截取长度(汉字算一个字,字母算半个字
|
||||
* @param $str
|
||||
* @param int $length
|
||||
* @param bool $is_need_apostrophe
|
||||
* @param boolean $is_need_apostrophe 是否需要省略号
|
||||
* @param string $apostrophe_pos 省略号位置 end 结尾 center 中间
|
||||
* @return string
|
||||
*/
|
||||
function str_sub($str, $length = 10, $is_need_apostrophe = true)
|
||||
function str_sub($str, $length = 10, $is_need_apostrophe = false, $apostrophe_pos = 'end')
|
||||
{
|
||||
return mb_substr($str, 0, $length, 'UTF-8') . ( $is_need_apostrophe ? '...' : '' );
|
||||
$encoding = 'UTF-8';
|
||||
$res_str = $str;
|
||||
if(mb_strlen($str, $encoding) > $length){
|
||||
if($is_need_apostrophe){
|
||||
if($apostrophe_pos == 'end'){
|
||||
$res_str = mb_substr($str, 0, $length, $encoding) . '...';
|
||||
}else{
|
||||
$half_length = floor($length / 2);
|
||||
$res_str = mb_substr($str, 0, $half_length, $encoding) . '...' . mb_substr($str, mb_strlen($str, $encoding) - $half_length, $half_length, $encoding);
|
||||
}
|
||||
}else{
|
||||
$res_str = mb_substr($str, 0, $length, 'UTF-8');
|
||||
}
|
||||
}
|
||||
return $res_str;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1879,6 +1894,199 @@ function paramFilter($param)
|
||||
return preg_replace($filter_rule, '', $param);
|
||||
}
|
||||
|
||||
//最小公倍数
|
||||
function getLeastCommonMultiple($a, $b) {
|
||||
return $a * $b / getGreatestCommonDivisor($a, $b);
|
||||
}
|
||||
//最大公约数
|
||||
function getGreatestCommonDivisor($a, $b) {
|
||||
if ($b === 0) return $a;
|
||||
return getGreatestCommonDivisor($b, $a % $b);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联数组变为索引数组
|
||||
* @param array $list
|
||||
* @return array
|
||||
*/
|
||||
function keyArrToIndexArr($list, $child = 'children'){
|
||||
$list = array_values($list);
|
||||
foreach($list as $key=>$val){
|
||||
if(isset($val[$child]) && !empty($val[$child])){
|
||||
$list[$key][$child] = keyArrToIndexArr($val[$child], $child);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 索引数组变为关联数组
|
||||
* @param $list
|
||||
* @param $pk
|
||||
* @param string $child
|
||||
* @return array
|
||||
*/
|
||||
function indexArrToKeyArr($list, $pk, $child = 'children'){
|
||||
$new_list = [];
|
||||
foreach($list as $val){
|
||||
if(isset($val[$child]) && !empty($val[$child])){
|
||||
$val[$child] = indexArrToKeyArr($val[$child], $pk, $child);
|
||||
}
|
||||
if(isset($val[$pk])){
|
||||
$new_list[$val[$pk]] = $val;
|
||||
}
|
||||
}
|
||||
return $new_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树的末端节点
|
||||
* @param $list
|
||||
* @param $pk
|
||||
* @param $child
|
||||
* @return array
|
||||
*/
|
||||
function getTreeLeaf($list, $pk = 'id', $child = 'child')
|
||||
{
|
||||
$leaf_arr = [];
|
||||
foreach($list as $val){
|
||||
if(empty($val[$child])){
|
||||
$leaf_arr[] = $val[$pk];
|
||||
}else{
|
||||
$leaf_arr = array_merge($leaf_arr, getTreeLeaf($val[$child], $pk, $child));
|
||||
}
|
||||
}
|
||||
return $leaf_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖数据
|
||||
* @param $source_data
|
||||
* @param $target_data
|
||||
* @return mixed
|
||||
*/
|
||||
function assignData($source_data, $target_data)
|
||||
{
|
||||
if(is_array($target_data)){
|
||||
foreach($target_data as $key=>$val){
|
||||
if(isset($source_data[$key])){
|
||||
$target_data[$key] = assignData($source_data[$key], $val);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$target_data = $source_data;
|
||||
}
|
||||
return $target_data;
|
||||
}
|
||||
|
||||
//使用htmlpurifier防范xss攻击
|
||||
function removeXss($string)
|
||||
{
|
||||
//相对index.php入口文件,引入HTMLPurifier.auto.php核心文件
|
||||
//require_once './plugins/htmlpurifier/HTMLPurifier.auto.php';
|
||||
// 生成配置对象
|
||||
$cfg = HTMLPurifier_Config::createDefault();
|
||||
// 以下就是配置:
|
||||
$cfg->set('Core.Encoding', 'UTF-8');
|
||||
// 设置允许使用的HTML标签
|
||||
$cfg->set('HTML.Allowed', 'div,b,strong,i,em,a[href|title],ul,ol,li,br,p[style],span[style],img[width|height|alt|src],table,tbody,tr[class],th,td[width|valign|style]');
|
||||
// 设置允许出现的CSS样式属性
|
||||
//$cfg->set('CSS.AllowedProperties', 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align');
|
||||
// 设置a标签上是否允许使用target="_blank"
|
||||
$cfg->set('HTML.TargetBlank', TRUE);
|
||||
// 使用配置生成过滤用的对象
|
||||
$obj = new HTMLPurifier($cfg);
|
||||
// 过滤字符串
|
||||
$array = json_decode($string, true);
|
||||
if(is_array($array)){
|
||||
$array = recursiveDealWithArrayString($array, function ($str) use($obj){
|
||||
return $obj->purify($str);
|
||||
});
|
||||
$string = json_encode($array, JSON_UNESCAPED_UNICODE);
|
||||
}else{
|
||||
$string = $obj->purify($string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归处理数组中的字符串
|
||||
* @param $array
|
||||
* @param $callback
|
||||
* @return mixed
|
||||
*/
|
||||
function recursiveDealWithArrayString($array, $callback){
|
||||
foreach($array as $key=>$val){
|
||||
if(is_string($val)){
|
||||
$val = $callback($val);
|
||||
}else if(is_array($val)){
|
||||
$val = recursiveDealWithArrayString($val, $callback);
|
||||
}
|
||||
$array[$key] = $val;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
function exceptionData(\Exception $e){
|
||||
return [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
function getCertKey($str)
|
||||
{
|
||||
return require "extend/cert/".$str.".php";
|
||||
}
|
||||
|
||||
if(!function_exists('http_url')){
|
||||
function http_url($url,$data,$headers = [],$type = 'POST') {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36';
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); # 在HTTP请求中包含一个"User-Agent: "头的字符串,声明用什么浏览器来打开目标网页
|
||||
if(!empty($headers)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
if (1 == strpos("$".$url, "https://"))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
if($type == 'POST') {
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
if(is_array($data)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
}else {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // ssl 访问核心参数
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // ssl 访问核心参数
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function secondsToTime($seconds) {
|
||||
$hours = floor($seconds / 3600);
|
||||
$minutes = floor(($seconds % 3600) / 60);
|
||||
$seconds = $seconds % 60;
|
||||
|
||||
// 格式化为两位数
|
||||
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化数据为日志友好的字符串(保持中文可读性)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user