| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- //生成随机码
- function create_invite_code() {
- $code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $rand = $code[rand(0,25)]
- .strtoupper(dechex(date('m')))
- .date('d')
- .substr(time(),-5)
- .substr(microtime(),2,5)
- .sprintf('%02d',rand(0,99));
- for(
- $a = md5( $rand, true ),
- $s = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
- $d = '',
- $f = 0;
- $f < 6;
- $g = ord( $a[ $f ] ),
- $d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],
- $f++
- );
- return $d;
- }
- function create_order_number()
- {
- return date('Ymd') . str_pad(mt_rand(1, 999999), 6, '0', STR_PAD_LEFT);
- }
- /**
- * curl 请求
- * @param $url
- * @param null $header
- * @param null $data
- * @return mixed
- */
- function curlRequest($url, $header = null, $data = null)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- if ($data) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- if ($header) {
- curl_setopt($ch, CURLOPT_HEADER, $header);
- }
- $ret = curl_exec($ch);
- curl_close($ch);
- return $ret;
- }
- /**
- * 时间格式化(时间戳)
- * @param $ptime
- * @return false|string
- */
- function uc_time_ago($ptime)
- {
- date_default_timezone_set('PRC');
- $etime = time() - $ptime;
- switch ($etime) {
- case $etime <= 60:
- $msg = '刚刚';
- break;
- case $etime > 60 && $etime <= 60 * 60:
- $msg = floor($etime / 60) . ' 分钟前';
- break;
- case $etime > 60 * 60 && $etime <= 24 * 60 * 60:
- $msg = date('Ymd', $ptime) == date('Ymd', time()) ? '今天 ' . date('H:i', $ptime) : '昨天 ' . date('H:i', $ptime);
- break;
- case $etime > 24 * 60 * 60 && $etime <= 2 * 24 * 60 * 60:
- $msg = date('Ymd', $ptime) + 1 == date('Ymd', time()) ? '昨天 ' . date('H:i', $ptime) : '前天 ' . date('H:i', $ptime);
- break;
- case $etime > 2 * 24 * 60 * 60 && $etime <= 12 * 30 * 24 * 60 * 60:
- $msg = date('Y', $ptime) == date('Y', time()) ? date('m-d H:i', $ptime) : date('Y-m-d H:i', $ptime);
- break;
- default:
- $msg = date('Y-m-d H:i', $ptime);
- }
- return $msg;
- }
- /**
- * 根据生日计算年龄
- * @param $birthday 1999-02-01
- * @return int|string 21
- */
- function birthday($birthday){
- list($year,$month,$day) = explode("-",$birthday);
- $year_diff = date("Y") - $year;
- $month_diff = date("m") - $month;
- $day_diff = date("d") - $day;
- if ($day_diff < 0 || $month_diff < 0)
- $year_diff--;
- return $year_diff;
- }
|