$row) { foreach ($row as $key => $value) { $arrSort[$key][$uniqid] = $value; } } array_multisort($arrSort[$field], constant($sort), $array); return $array; } } //post请求 if(!function_exists('httpPostForm')){ /** * 表单提交数据 * @param $url * @param $data * @return array */ function httpPostForm($url, $data){ $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0);//设置header curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //https if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($error = curl_error($ch)) { die($error); } curl_close($ch); return array($httpCode, $response); } } if (!function_exists('httpPostJson')) { /** * @param string $url * @param string $jsonStr * @return array */ function httpPostJson($url, $jsonStr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //https if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($jsonStr) ) ); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($error = curl_error($ch)) { die($error); } curl_close($ch); return array($httpCode, $response); } } //request 请求 if (!function_exists('httpRequest')) { function httpRequest($sUrl, $data = array()) { $header = array('X-AUTH-APP-ID:a2nkCKjTJJNSVaeQITwmV/1zw9Dpn56Acr2Z81MOkkJ/8VapjA6oPA==', 'X-AUTH-KEY:89c9c457-7fff-41f8-9ba5-1e9154a7b972', 'companyUuid:haixifangchan_company8fee8cd09'); if ($data) { $sUrl = $sUrl . '?' . http_build_query($data); } $ch = curl_init(); if (substr($sUrl, 0, 5) == 'https') { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 } curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $sUrl); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, false); $response = curl_exec($ch); $request_header = curl_getinfo($ch, CURLINFO_HEADER_OUT); //print_r($request_header);exit(); if ($error = curl_error($ch)) { die($error); } curl_close($ch); return json_decode($response, 1); } } // if (!function_exists('uploadImg')) { //上传图片 function uploadImg($url, $path = 'wx/fn/') { //$path = 'img/wechatapp/fn/'; 路径 if (!is_dir($path)){ $oldumask = umask(0); mkdir($path, 0777,true); umask($oldumask); } //对照片处理 $url = mb_substr($url, 0, -4); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); $file = curl_exec($ch); curl_close($ch); $filename = pathinfo($url, PATHINFO_BASENAME); $filename = strtolower($filename); $resource = fopen($path . $filename, 'a'); fwrite($resource, $file); fclose($resource); $name = $path . $filename; return $name; } } /** * 图片压缩处理 * @param string $sFile 源图片路径 * @param int $iWidth 自定义图片宽度 * @param int $iHeight 自定义图片高度 * @return string 压缩后的图片路径 */ if (!function_exists('getThumb')) { function getThumb($sFile, $iWidth, $iHeight) { //图片公共路径 //判断该图片是否存在 if (!file_exists($sFile)) return $sFile; //判断图片格式(图片文件后缀) $extend = explode(".", $sFile); $attach_fileext = strtolower($extend[count($extend) - 1]); if (!in_array($attach_fileext, array('jpg', 'png', 'jpeg'))) { return ''; } //压缩图片文件名称 $sFileNameS = str_replace("." . $attach_fileext, "_" . $iWidth . '_' . $iHeight . '.' . $attach_fileext, $sFile); //判断是否已压缩图片,若是则返回压缩图片路径 if (file_exists($sFileNameS)) { return $sFileNameS; } //生成压缩图片,并存储到原图同路径下 resizeImage($sFile, $sFileNameS, $iWidth, $iHeight); if (!file_exists($sFileNameS)) { return $sFile; } return $sFileNameS; } } /** * 生成图片 * @param string $im 源图片路径 * @param string $dest 目标图片路径 * @param int $maxwidth 生成图片宽 * @param int $maxheight 生成图片高 */ if (!function_exists('resizeImage')) { function resizeImage($im, $dest, $maxwidth, $maxheight) { $img = getimagesize($im); switch ($img[2]) { case 1: $im = @imagecreatefromgif($im); break; case 2: $im = @imagecreatefromjpeg($im); break; case 3: $im = @imagecreatefrompng($im); break; } $pic_width = imagesx($im); $pic_height = imagesy($im); $resizewidth_tag = false; $resizeheight_tag = false; if (($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight)) { if ($maxwidth && $pic_width > $maxwidth) { $widthratio = $maxwidth / $pic_width; $resizewidth_tag = true; } if ($maxheight && $pic_height > $maxheight) { $heightratio = $maxheight / $pic_height; $resizeheight_tag = true; } if ($resizewidth_tag && $resizeheight_tag) { if ($widthratio < $heightratio) $ratio = $widthratio; else $ratio = $heightratio; } if ($resizewidth_tag && !$resizeheight_tag) $ratio = $widthratio; if ($resizeheight_tag && !$resizewidth_tag) $ratio = $heightratio; $newwidth = $pic_width * $ratio; $newheight = $pic_height * $ratio; if (function_exists("imagecopyresampled")) { $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $pic_width, $pic_height); } else { $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $pic_width, $pic_height); } imagejpeg($newim, $dest); imagedestroy($newim); } else { imagejpeg($im, $dest); } } } //巧房房源图片处理 if (!function_exists('editPhoto')) { //图片处理 function editPhoto($community_list) { foreach ($community_list as $key => $value) { foreach ($value as $k => $item) { if (empty($item) || is_null($item)) { $community_list[$key][$k] = ''; } //图片处理,取室内图,取不到再用户型图 if ($value['photoList']) { foreach ($value['photoList'] as $v) { if ($v['categoryName'] == 'shinei' || $v['categoryName'] == '室内图' || $v['categoryCnName'] == '室内图') { $community_list[$key]['photoList'] = 'http://uyu.xmfish.com/thumb2/byurl/?url=' . str_replace('https://', '', $v['photoUrl']) . '|300'; break; } else { $community_list[$key]['photoList'] = 'http://uyu.xmfish.com/thumb2/byurl/?url=' . str_replace('https://', '', $v['photoUrl']) . '|300'; } } } } //photoList原先就是数组,清空获取不到值,只能进行转换 $community_list[$key]['photo_list'][0] = $community_list[$key]['photoList']; $community_list[$key]['photoList'] = $community_list[$key]['photo_list']; unset($community_list[$key]['photo_list']); //计算单价 $community_list[$key]['unitPrice'] = str_replace(',', '', number_format($value['sellPrice'] / $value['square'], 2)); } return $community_list; } } //二维数组去重 if (!function_exists('moreArrayUnique')) { function moreArrayUnique($arr = array()) { foreach ($arr[0] as $k => $v) { $arr_inner_key[] = $k; } foreach ($arr as $k => $v) { $v = join(",", $v); $temp[$k] = $v; } $temp = array_unique($temp); foreach ($temp as $k => $v) { $a = explode(",", $v); $arr_after[$k] = array_combine($arr_inner_key, $a); } $arr_after = array_values($arr_after); return $arr_after; } } if (!function_exists('msectime')) { //时间转换成毫秒 function msectime() { list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectime; } } if ( ! function_exists('friendly_time') ) { /** * @param $time * @return false|string */ function friendly_time($time) { $surplus = time() - $time; switch (true) { case $surplus < 60: return $surplus . '秒前'; case $surplus < 3600: return ceil($surplus / 60) . '分钟前'; case $surplus < 3600 * 24: return ceil($surplus / 3600) . '小时前'; case $surplus < 3600 * 24 * 7: return ceil($surplus / (3600 * 24)) . '天前'; default: return date('m月d日', $time); } } }