" . htmlspecialchars($output, ENT_QUOTES).""; echo $output; if ($exit) { exit(); } } } if (!function_exists('dehtml')) { /** * 把HTML实体转换为HTML可视标签 */ function dehtml($str) { return htmlspecialchars_decode($str); } } if (!function_exists('is_wechat')) { /** * 判断是否在微信中打开 * @return boolean */ function is_wechat() { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) { return true; } return false; } } if (!function_exists('en_phone')) { /** * 隐藏手机号中间四位 * @param [type] $phone * @return 从第三个字符隐藏4个字符 */ function en_phone($phone,$s = 3,$d = 4) { return substr_replace($phone, '****',$s,$d); } } if (!function_exists('money')) { /** * 格式化钱保留小数点 * @param float $amount */ function money($amount) { $amount = round($amount,2); return sprintf("%01.2f", $amount); } } if (!function_exists('uuid')) { /** * 获取唯一ID * * @param intege $type 类型 * @param intege $data 要计算的KEY数据 * @param Boolean $hex 返回的字符是否带-风格符 * @return void */ function uuid(int $type = 0, $hex = true, $data = null) { switch ($type) { case 1: //基于散列的MD5 $uuid = CreateUuid::uuid4(); break; case 2: //基于散列的MD5 $uuid = CreateUuid::uuid3(CreateUuid::NAMESPACE_DNS, $data); break; case 3: //基于SHA1 $uuid = CreateUuid::uuid5(CreateUuid::NAMESPACE_DNS, $data); break; default: //基于时间 $uuid = CreateUuid::uuid1(); break; } return $hex ? $uuid->getHex() : $uuid->toString(); } } if (!function_exists('order_no')) { /** * 订单号 */ function order_no($pre = '') { return $pre.\uuid\Intuuid::generateParticle(); } } if (!function_exists('getcode')) { /** * 生成随机数 * @param int $limit 要生成的随机数长度 **/ function getcode($limit=6) { $rand_array = range(0, 9); shuffle($rand_array); //调用现成的数组随机排列函数 $str = array_slice($rand_array, 0, $limit);//截取前$limit个 return implode(null, $str); } } if (!function_exists('create_code')) { /** * 生成邀请码 * @param int $id 要加密换算的ID * */ function create_code($id) { static $source_string = 'E5FCDG3HQA4B1NOPIJ2RSTUV67MWX89KLYZ'; $num = $id; $code = ''; while ($num > 0) { $mod = $num % 35; $num = ($num - $mod) / 35; $code = $source_string[$mod].$code; } if (empty($code[3])) { $code = str_pad($code, 4, '0', STR_PAD_LEFT); } return $code; } } if (!function_exists('de_code')) { /** * 解密邀请码 * @param string $code 要解密经过create_code函数加密ID */ function de_code($code) { static $source_string = 'E5FCDG3HQA4B1NOPIJ2RSTUV67MWX89KLYZ'; if (strrpos($code, '0') !== false) { $code = substr($code, strrpos($code, '0')+1); } $len = strlen($code); $code = strrev($code); $num = 0; for ($i=0; $i < $len; $i++) { $num += strpos($source_string, $code[$i]) * pow(35, $i); } return $num; } } if (!function_exists('ids')) { /** * Ids 参数强制转换为整形 * @param string|array $array 要强制转换的参数是字符串1,2,3还是数组[1,2,3] * @param bool $is_ary 返回是字符串1,2,3还是数组[1,2,3] * @return string */ function ids($ids,$is_ary = false) { if(empty($ids)){ return $is_ary ? [] : ''; } if (is_array($ids)) { $ids_ary = $ids; } else { $ids_ary = explode(',', trim($ids, ',')); } $id_array = []; foreach ($ids_ary as $key => $value) { $id_array[$key] = abs(intval($value)); } return $is_ary ? $id_array : implode(',', $id_array); } } if (!function_exists('array_values_unset')) { /** * 删除数组中指定键值 * @param array $arr 要删除的数组 * @return array */ function array_values_unset(string $values, array $ary) { $ary_key = array_search($values, $ary); if ($ary_key !== false) { unset($ary[$ary_key]); } return $ary; } } if (!function_exists('sbc2Dbc')) { /** * 全角转半角 * @param string $str * @return string **/ function sbc2Dbc($str) { $arr = array( '0'=>'0', '1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4','5'=>'5', '6'=>'6', '7'=>'7', '8'=>'8', '9'=>'9', 'A'=>'A', 'B'=>'B', 'C'=>'C', 'D'=>'D', 'E'=>'E','F'=>'F', 'G'=>'G', 'H'=>'H', 'I'=>'I', 'J'=>'J', 'K'=>'K', 'L'=>'L', 'M'=>'M', 'N'=>'N', 'O'=>'O','P'=>'P', 'Q'=>'Q', 'R'=>'R', 'S'=>'S', 'T'=>'T', 'U'=>'U', 'V'=>'V', 'W'=>'W', 'X'=>'X', 'Y'=>'Y','Z'=>'Z', 'a'=>'a', 'b'=>'b', 'c'=>'c', 'd'=>'d', 'e'=>'e', 'f'=>'f', 'g'=>'g', 'h'=>'h', 'i'=>'i','j'=>'j', 'k'=>'k', 'l'=>'l', 'm'=>'m', 'n'=>'n', 'o'=>'o', 'p'=>'p', 'q'=>'q', 'r'=>'r', 's'=>'s', 't'=>'t', 'u'=>'u', 'v'=>'v', 'w'=>'w', 'x'=>'x', 'y'=>'y', 'z'=>'z', '('=>'(', ')'=>')', '〔'=>'(', '〕'=>')', '【'=>'[','】'=>']', '〖'=>'[', '〗'=>']', '“'=>'"', '”'=>'"', '‘'=>'\'', '’'=>'\'', '{'=>'{', '}'=>'}', '《'=>'<','》'=>'>','%'=>'%', '+'=>'+', '—'=>'-', '-'=>'-', '~'=>'~',':'=>':', '。'=>'.', '、'=>',', ','=>',', '、'=>',', ';'=>';', '?'=>'?', '!'=>'!', '…'=>'-', '‖'=>'|', '”'=>'"', '’'=>'`', '‘'=>'`', '|'=>'|', '〃'=>'"',' '=>' ', '×'=>'*', ' ̄'=>'~', '.'=>'.', '*'=>'*', '&'=>'&','<'=>'<', '>'=>'>', '$'=>'$', '@'=>'@', '^'=>'^', '_'=>'_', '"'=>'"', '¥'=>'$', '='=>'=', '\'=>'\\', '/'=>'/' ); return strtr($str, $arr); } } if (!function_exists('api')) { /** * Url生成 * @param integer $version API版本 * @param string $url 访问网址 * @param integer $appid 当前APPID * @param integer $id 传入参数 * @param array $vars 变量 * @return void */ function api(int $version,$url,int $appid = 0,array $vars = []){ $id = isset($vars['id']) ? '/'.$vars['id'] : ''; if(isset($vars['id'])){ unset($vars['id']); } $vars = empty($vars) ? '' : '?'.http_build_query($vars); $appid = $appid ? '/'.$appid : ''; $url = strtolower($url); $urls = explode('/',$url); if('system' == $urls[0]){ unset($urls[0]); if('miniprogram' == strtolower($urls[1])){ unset($urls[1]); } $urls = implode('/',$urls); return Request::root(true)."/openapi{$appid}/v{$version}/{$urls}"; }else{ return Request::root(true)."/api{$appid}/v{$version}/{$url}{$id}.html".$vars; } } } if (!function_exists('urls')) { /** * Url生成 * @param integer $version API版本 * @param string $url 访问网址 * @param integer $appid 当前APPID * @param integer $id 传入参数 * @param array $vars 变量 * @return void */ function urls($url,int $appid = 0,array $vars = []){ $id = isset($vars['id']) ? '/'.$vars['id'] : ''; if(isset($vars['id'])){ unset($vars['id']); } $vars = empty($vars) ? '' : '?'.http_build_query($vars); $appid = $appid ? '/'.$appid : ''; return Request::root(true).'/app'.$appid.'/'.strtolower($url).$id.$vars; } }