0 ? $day.'天' : ''; $hour = floor(($remain_time % (3600*24)) / 3600); $hour = $hour > 0 ? $hour.'小时' : ''; if($is_hour && $is_minutes) { $minutes = floor((($remain_time % (3600*24)) % 3600) / 60); $minutes = $minutes > 0 ? $minutes.'分钟' : ''; return $day.$hour.$minutes; } if($hour) { return $day.$hour; } return $day; } //获取全图片地址 $image_data function image_path($image_data){ if(empty($image_data)){ return $image_data; } if (strpos($image_data,'|')!==false){ $image_res = explode('|',$image_data); }elseif(strpos($image_data,',')!==false){ $image_res = explode(',',$image_data); }else{ $image_res = array($image_data); } return $image_res; } /** * @param $id_card * @return false|string */ function get_age($id_card){ # 1.从身份证中获取出生日期 $birth_Date = strtotime(substr($id_card, 6, 8));//截取日期并转为时间戳 # 2.格式化[出生日期] $Year = date('Y', $birth_Date);//yyyy $Month = date('m', $birth_Date);//mm $Day = date('d', $birth_Date);//dd # 3.格式化[当前日期] $current_Y = date('Y');//yyyy $current_M = date('m');//mm $current_D = date('d');//dd # 4.计算年龄() $age = $current_Y - $Year;//今年减去生日年 if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日) $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁 } # 返回 return $age; } function create_invite_code($user_id){ // 生成12位邀请码 $code_str = ''; $base_code = explode(',',"A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z"); $code_key = array_rand($base_code, 10 - strlen($user_id)); array_map(function ($val)use (&$code_str,$base_code){ $code_str .=$base_code[$val] ; },$code_key); return $code_str.$user_id; } // 获取模板区域 function get_city_area() { $field=['id','pid','name']; $list=Db::name('china_area')->where('pid',0)->field($field)->select(); foreach ($list as $k=>&$v){ $v['children']= Db::name('china_area')->where('pid',$v['id'])->field($field)->select(); } return $list; } function http_curl($url,$type='get',$res='json',$arr=''){ $headers = array(); //根据API的要求,定义相对应的Content-Type array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8;application/json"); $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); $output = curl_exec($curl); curl_close($curl); if($res=='json'){ if($output === false){ //请求失败,返回错误信息 return curl_error($curl); }else{ //请求成功,返回信息 return json_decode($output,true); } } } function curl_get($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); if($output === false){ return curl_error($ch); }else{ return json_decode($output,true); } } // 获取物流信息 function get_delivery($send_no = 'JD0053309649641',$express_code=''){ error_reporting(E_ALL || ~E_NOTICE); $AppKey = 204111217; $AppSecret ='LGUYqAh335HMec0eyJZdiHwMhrapU1fH'; $AppCode ='5f96216347b547579e2417685ee8e647';//开通服务后 买家中心-查看AppCode $host = "https://wuliu.market.alicloudapi.com";//api访问链接 $path = "/kdi";//API访问后缀 $method = "GET"; $body =''; $headers = array(); array_push($headers, "Authorization:APPCODE " . $AppCode); $querys = "no={$send_no}&type={$express_code}"; //参数写在这里 $url = $host . $path . "?" . $querys; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); if (1 == strpos("$" . $host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $out_put = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); list($header, $body) = explode("\r\n\r\n", $out_put, 2); if ($httpCode == 200) { return json_decode($body,true)['result']; } else { return []; } } // 实名认证 function user_certification($id_card,$name){ $host = "http://checkone.market.alicloudapi.com"; $path = "/chinadatapay/1882"; $method = "POST"; $appcode = "30be8bdcc65842919980a8276ffc4995"; $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); //根据API的要求,定义相对应的Content-Type array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8"); $bodys = "idcard=".$id_card."&name=".$name; $url = $host . $path; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$".$host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); $res = curl_exec($curl); if($res){ $res = json_decode($res,true); if($res['data']['result'] == 1){ return 1; }else{ return 0; } }else{ return 0; } } /**  * 把返回的数据集转换成Tree  * @param array $list 要转换的数据集  * @param string $pk 自增字段(栏目id)  * @param string $pid parent标记字段  * @return array  */ function make_tree($list,$pk='id',$pid='pid',$child='children',$root=0){ if(is_object($list)) $list = $list->toArray(); $tree=array(); $packData=array(); foreach ($list as $data) { $packData[$data[$pk]] = $data; } foreach ($packData as $key =>$val){ if($val[$pid]==$root){//代表跟节点 $tree[]=& $packData[$key]; }else{ $packData[$val[$pid]][$child][]=& $packData[$key]; //找到其父类 } } return $tree; } //判断字段存在并不为空 function isset_full($arr, $key) { if (isset($arr[$key]) && !empty($arr[$key])) { return true; } else { return false; } } //判断字段存在并不为空 并且等于验证值 function isset_full_check($arr, $key,$check_val) { if (isset($arr[$key]) && !empty($arr[$key]) && $arr[$key] == $check_val) { return true; } else { return false; } } function all_pay_type() { return [ '--','微信[H5]','支付宝[H5]','微信[APP]','支付宝[APP]','微信[公众号]' ]; } /** * @param $start 验证开始时间 * @param $end 验证结束时间 * @param $check_st 已有活动开始时间 * @param $check_end 已有活动结束时间 * @return bool true 可以创建活动 */ function check_act_time($start,$end,$check_st,$check_end) { $check_val = false; if($start > $check_end || $end < $check_st) $check_val = true; return $check_val; } /** * 生成32位随机数 */ function get32Str($length='32'){ $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $len = strlen($str)-1; $randstr = ''; for ($i=0;$i<$length;$i++) { $num=mt_rand(0,$len); $randstr .= $str[$num]; } return $randstr; }