loadXML($xmlStr); $array_e = $xml_tree->getElementsByTagName($field); $info = $array_e->item(0)->nodeValue; return $info; } } if(!function_exists('getDaysByMonth')) { /** * 根据年月获取所属月份的日期 * @param $year int 年份 * @param $month int 月份 * @return array * */ function getDaysByMonth($year, $month) { $days = date('t', strtotime($year. '-' . $month)); $start_time = strtotime(date($year. '-' . $month. '-01')); $array = array(); for($i=0; $i<$days;$i++) { $array[] = date('Y-m-d', $start_time + $i*86400); } return $array; } } /* * 获取时差 * */ if(!function_exists('date_diff_for_hour')) { /** * 获取时差 * @param $dateOne datetime * @param $dateTwo datetime * @return int * */ function date_diff_for_hour($dateOne, $dateTwo=null) { if(is_null($dateTwo)) $dateTwo = date('Y-m-d H:i:s'); return abs(floor((strtotime($dateOne)-strtotime($dateTwo))%86400 / 3600)); } } /* * 获取近七日日期 * */ if(!function_exists('get_recent_day')) { /** * 获取最近日期 * @param $time * @param $format string * @return array * */ function get_recent_day($time = '', $format='Y-m-d'){ $time = empty($time) ? time() : $time; $date = []; for ($i=0; $i<=6; $i++){ $timestamp = strtotime( '+' . ($i-7) .' days', $time); $yearInfo = date('Y', $timestamp); $date[$yearInfo][] = date($format, $timestamp); } return $date; } } /* * 将近N小时和日期转化为*年*月*日 *:*:*格式 * */ if(!function_exists('to_datetime')) { function to_datetime($param) { if(empty($param)) return null; if(strtotime($param) === false) { $result = date('Y-m-d H:i:s', strtotime('-' . (int)$param. ' hour')); } else { $result = date('Y-m-d H:i:s', strtotime($param)); } return $result; } } /* * 获取字符串对应的hash值 * */ if(!function_exists('get_hash_code')) { function get_hash_code($str, $remainder=0) { if(empty($str)) return false; $encrypt = md5($str); $number = base_convert($encrypt, 16, 10); $label = substr($number, -4); return $remainder > 0 ? abs($label % $remainder) : $number; } } /* * 获取日期对应的数字(0:星期日 1:星期一 2:星期二以此类推) * */ if(!function_exists('get_week')) { function get_week($timestamp){ $date_str=date('Y-m-d',$timestamp); $arr=explode("-", $date_str); $year=$arr[0]; //月,输出2位整型,不够2位右对齐 $month=sprintf('%02d',$arr[1]); //日,输出2位整型,不够2位右对齐 $day=sprintf('%02d',$arr[2]); //时分秒默认赋值为0; $hour = $minute = $second = 0; //转换成时间戳 $strap = mktime($hour,$minute,$second,$month,$day,$year); //获取数字型星期几 return date("w",$strap); } } /* * 获取字符串对应的hash值 * */ if(!function_exists('get_token')) { function get_token($corpid, $userId, $timestamps, $extra='') { $str = 'wAAVfvfgR8uMIGIoRJquy66uw'; return md5($corpid . $userId . $str . $timestamps . $extra); } } if(!function_exists('get_random_str')) { function get_random_str($length) { $nonceStr = ""; $codeAlphabet = "ABCDEFGHIJKLMnopQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789"; for ($i = 0; $i < $length; $i++) { $nonceStr .= $codeAlphabet[mt_rand(0, strlen($codeAlphabet) - 1)]; } return $nonceStr; } } function h5_set_sign($params) { if(empty($params)){ return false; } $str = ''; ksort($params); foreach($params as $k=>$v){ if(is_array($v)){ $v = json_encode($v); } $str .= $k.'='.$v; } $solt = 'ur904wtr5pfctaw9'; $sign = md5(md5($str) . $solt); return $sign; } function h5_verify_sign($params) { if( empty($params) || !isset($params['sign']) ){ return false; } $sign = $params['sign']; unset($params['sign']); $_sign = h5_set_sign($params); if($sign == $_sign){ return true; } return false; } /* * 将分钟转换为 x天y小时z分钟 * */ if(!function_exists('turn_minute')) { function turn_minute($minute) { $days = floor($minute/1440); $hours = floor(($minute - $days*1440)/60); $minutes = ($minute - $days*60*24 - $hours*60); $days = $days > 0 ? $days . '天' : ''; $hours = $hours > 0 ? $hours . '小时' : ''; $minutes = $minutes > 0 ? $minutes . '分钟' : ''; return $days . $hours . $minutes; } } /** * 获取url参数 * */ if(!function_exists('getUrlParams')) { function getUrlParams($url, $param) { $pathData = parse_url($url); if(isset($pathData['fragment']) && $pathData['fragment']) { $pathData = parse_url($pathData['fragment']); } $value = ''; if(isset($pathData['query']) && $pathData['query']) { parse_str($pathData['query'], $query); $value = $query[$param] ?? ''; } return $value; } } /** * 获取url参数 * */ if(!function_exists('shouldMiss')) { /** * @param $currentValue integer 当前订单数 * @param $missSetValue integer 间隔的订单数 * @param $missValue integer 需要漏掉的订单数 * @return boolean 应该漏单返回true,否则false **/ function shouldMiss($currentValue, $missSetValue, $missValue) { for($i=0; $i<$missValue; $i++) { $remainder = ($missSetValue + $missValue - $i) % ($missSetValue + $missValue); if( $currentValue >1 && ($currentValue % ($missSetValue + $missValue)) == $remainder) { return true; } } return false; } } /** * 获取毫秒级时间戳 */ if(!function_exists('getMillisecond')) { function getMillisecond() { list($microsecond, $time) = explode(' ', microtime()); //' '中间是一个空格 return (float)sprintf('%.0f', (floatval($microsecond) + floatval($time)) * 1000); } }