getAccessToken($appid, $secret); return $token; } /* * 手机验证码发送(装企端接收) */ function sendSms($mobile, $content) { if (!preg_match("/^1\d{10}$/", $mobile) && empty($content)) { return false; } $smsObj = new ChuanglanSmsApi(); $result = $smsObj->sendSMS($mobile, '【志远装饰】' . $content); $output = json_decode($result, true); if (is_null($output)) return false; if ($output['code'] != 0) { trace($output, 'error'); return false; } return true; } /* * 手机验证码发送(用户端接收) */ function sendSmsUser($mobile, $content) { if (!preg_match("/^1\d{10}$/", $mobile) && empty($content)) { return false; } $smsObj = new ChuanglanSmsApi(); $result = $smsObj->sendSMS($mobile, '【志远装饰】' . $content); $output = json_decode($result, true); if (is_null($output)) return false; if ($output['code'] != 0) { trace($output, 'error'); return false; } return true; } /** * 微信公众号二维码生成 */ function officialQrcode($token, $data) { $qr = new Qrcode(); $rs = $qr->create($token, json_encode($data)); $qrArr = json_decode($rs, true); if (isset($qrArr['errcode'])) { return ['code' => 1, 'msg' => $qrArr['errmsg']]; } $url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $qrArr['ticket']; return ['code' => 0, 'data' => $url]; } /** * 普通网址二维码生成 */ function qrcode($url, $path = false) { $qr = QrCodeGen::generateQr($url, $path); return $qr; } /* * 通信外部接口 */ function curlparam($url, $cmunioncode) { $headerArray = array("Content-type:application/json;", "Accept:application/json", 'Cmuc:' . $cmunioncode); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); $output = curl_exec($ch); curl_close($ch); return $output; } /* * 通信外部接口 */ function curl($url) { $headerArray = array("Content-type:application/json;", "Accept:application/json"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); $output = curl_exec($ch); curl_close($ch); return $output; } function curlpost($url = '', $params = '') { if (empty($url) || empty($param)) { return false; } $curlPost = $params; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //抓取指定网页 curl_setopt($ch, CURLOPT_HEADER, 0); //设置header curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_POST, 1); //post提交方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $output = curl_exec($ch); curl_close($ch); return $output; } /** * @name: get_encoding * @description: 自动检测内容编码进行转换 * @param: string data * @param: string to 目标编码 * @return: string **/ function get_encoding($data, $to) { $encode_arr = array('UTF-8', 'ASCII', 'GBK', 'GB2312', 'BIG5', 'JIS', 'eucjp-win', 'sjis-win', 'EUC-JP'); $encoded = mb_detect_encoding($data, $encode_arr); $data = mb_convert_encoding($data, $to, $encoded); return $data; } /** * 获取汉字拼音首字母 * @param $s0 * @return null|string */ function getfirstchar($s0) { $fchar = ord($s0[0]); if ($fchar >= ord("A") and $fchar <= ord("z")) return strtoupper($s0[0]); $s1 = get_encoding($s0, 'GB2312'); $s2 = get_encoding($s1, 'UTF-8'); if ($s2 == $s0) { $s = $s1; } else { $s = $s0; } $asc = ord($s[0]) * 256 + ord($s[1]) - 65536; if ($asc >= -20319 and $asc <= -20284) return "A"; if ($asc >= -20283 and $asc <= -19776) return "B"; if ($asc >= -19775 and $asc <= -19219) return "C"; if ($asc >= -19218 and $asc <= -18711) return "D"; if ($asc >= -18710 and $asc <= -18527) return "E"; if ($asc >= -18526 and $asc <= -18240) return "F"; if ($asc >= -18239 and $asc <= -17923) return "G"; if ($asc >= -17922 and $asc <= -17418) return "H"; if ($asc >= -17922 and $asc <= -17418) return "I"; if ($asc >= -17417 and $asc <= -16475) return "J"; if ($asc >= -16474 and $asc <= -16213) return "K"; if ($asc >= -16212 and $asc <= -15641) return "L"; if ($asc >= -15640 and $asc <= -15166) return "M"; if ($asc >= -15165 and $asc <= -14923) return "N"; if ($asc >= -14922 and $asc <= -14915) return "O"; if ($asc >= -14914 and $asc <= -14631) return "P"; if ($asc >= -14630 and $asc <= -14150) return "Q"; if ($asc >= -14149 and $asc <= -14091) return "R"; if ($asc >= -14090 and $asc <= -13319) return "S"; if ($asc >= -13318 and $asc <= -12839) return "T"; if ($asc >= -12838 and $asc <= -12557) return "W"; if ($asc >= -12556 and $asc <= -11848) return "X"; if ($asc >= -11847 and $asc <= -11056) return "Y"; if ($asc >= -11055 and $asc <= -10247) return "Z"; return ''; } /** * 微信native支付 * @param type string 企业类型 hdyj/xjs * @param data array 订单信息orderNo,money,body,attach,price * @param money float 金额 * @param attach 标识,回调判断使用 * @param price float 产品价格 */ function wxNativePay($type, $data) { $config = [ 'app_id' => config("app.$type.mini_appid"), 'mch_id' => config("app.$type.mch_id"), 'key' => config("app.$type.mch_key"), ]; $wxConfig = new WxPayConfig($config); $input = new WxPayUnifiedOrder(); $input->SetBody($data['body']); $input->SetAttach($data['attach']); $input->SetOut_trade_no($data['orderNo']); $input->SetTotal_fee($data['money'] * 100); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetNotify_url(""); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($data['price']); $response = \WxPayApi::unifiedOrder($wxConfig, $input); $payUrl = isset($response['code_url']) ? $response['code_url'] : ''; return $payUrl; } /** * 微信jsapi支付 */ function wxJsapiPay($config, $order, $openid) { // 微信支付请求接口配置生成 $wxConfig = new WxPayConfig($config); $input = new WxPayUnifiedOrder(); $input->SetBody($order['body']); $input->SetAttach($order['attach']); $input->SetOut_trade_no($order['orderNo']); $input->SetTotal_fee($order['money'] * 100); $input->SetOpenid($openid); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetNotify_url($order['notifyUrl']); $input->SetTrade_type("JSAPI"); $response = \WxPayApi::unifiedOrder($wxConfig, $input, 12); if ($response['return_code'] != 'SUCCESS') { trace($response, 'error'); trace($config, 'error'); } $wxPayResult = new \WxPayResults(); $timeStamp = time(); $wxPayResult->SetData('appId', $response["appid"]); $wxPayResult->SetData('timeStamp', "$timeStamp"); $wxPayResult->SetData('nonceStr', WxPayApi::getNonceStr()); $wxPayResult->SetData('package', 'prepay_id=' . $response["prepay_id"]); $wxPayResult->SetData('signType', 'HMAC-SHA256'); $sign = $wxPayResult->MakeSign($wxConfig, false); $wxPayResult->SetData('paySign', $sign); $parameters = $wxPayResult->GetValues(); return $parameters; } /* * oss文件上传 */ function ossUpload($path, $file) { $accessKeyId = config('app.ali_oss_access_key_id'); $accessKeySecret = config('app.ali_oss_access_key_secret'); $endpoint = config('app.ali_oss_end_point'); $bucket = config('app.ali_oss_bucket'); $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint); try { $oss->uploadFile($bucket, $path, $file); } catch (OssException $e) { return false; } return true; } /* * 检测文件是否存在于oss */ function ossFileExist($object) { $accessKeyId = config('app.ali_oss_access_key_id'); $accessKeySecret = config('app.ali_oss_access_key_secret'); $endpoint = config('app.ali_oss_end_point'); $bucket = config('app.ali_oss_bucket'); $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint); // 检测文件是否存在 return $oss->doesObjectExist($bucket, $object); } /** * oss文件删除 */ function fileDelete($path) { if (file_exists($path)) { // 删除本地文件 return unlink($path); } // 删除阿里云oss文件 $accessKeyId = config('app.ali_oss_access_key_id'); $accessKeySecret = config('app.ali_oss_access_key_secret'); $endpoint = config('app.ali_oss_end_point'); $bucket = config('app.ali_oss_bucket'); try { $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint); if (is_array($path)) { return $oss->deleteObjects($bucket, $path); } else { return $oss->deleteObject($bucket, $path); } } catch (OssException $e) { return false; } } /** * 手机类型获取 */ function mobileType() { $agent = $_SERVER['HTTP_USER_AGENT']; $type = [ 'Macintosh' => 'MAC', 'Android' => '安卓', 'iPhone' => 'Iphone', 'Windows' => 'PC', ]; foreach ($type as $en => $ch) { if (stripos($agent, $en) !== false) return $ch; } return '其他'; } /** * 数组转url * @param $data Array */ function toUrlParams($data) { $buff = ""; foreach ($data as $k => $v) { if ($k != "sign" && $v != "" && !is_array($v)) { $buff .= $k . "=" . $v . "&"; } } $buff = trim($buff, "&"); return $buff; } /** * 查询条件生成 */ function setCondition($param, $item, $condition, &$set) { if (!is_array($param)) { $value = $param; } else { if (is_array($item)) { $value = isset($param[$item[0]]) ? $param[$item[0]] : ''; $item = $item[1]; } else { $value = isset($param[$item]) ? $param[$item] : ''; } } if ($value === '' || $value === null) return; if (is_array($condition)) { if (is_string($condition[1]) && preg_match('/VALUE/', $condition[1])) $condition[1] = str_replace('VALUE', $value, $condition[1]); else $condition[1] = $value; } else { $condition = [$condition, $value]; } array_unshift($condition, $item); $set[] = $condition; } /** * 获取汉子拼音 */ function hanzi2pinyin($hanzi) { if (empty($hanzi)) return ''; $pinyin = new Pinyin(); $quanpin = $pinyin->permalink($hanzi, ''); return $quanpin; } /** * 获取汉子首字母 */ function hanziInitials($hanzi) { if (empty($hanzi)) return ''; $pinyin = new Pinyin(); $quanpin = $pinyin->permalink($hanzi, ''); return $quanpin[0] ?? ''; } /** * 对数组按首字母进行排序 */ function hanziInitsort($arr, $ks) { $sort = null; foreach ($arr as $key => $val) { $s = hanziInitials($val[$ks]); $arr[$key]['s'] = $s; $sort[] = strtoupper($s); } array_multisort($sort, SORT_ASC, $arr); $sort = array_unique($sort); //asort($sort); /*foreach($sort as $key=>$val){ $xin[]=strtoupper($val); }*/ $data = ['sort' => $sort, 'arr' => $arr]; return $data; } /** * 对已排序的数组取第一个 */ function hanziheadstr($arr) { $sort = []; foreach ($arr as $key => $val) { $arr[$key]['s'] = substr($val['pinyin'], 0, 1); $sort[] = strtoupper(substr($val['pinyin'], 0, 1)); } $sort = array_unique($sort); $data = ['sort' => $sort, 'arr' => $arr]; return $data; } /** * 获取org ids array * @param integer $orgid 目标节点id * @return array $orgids 子节点ids数组 */ function orgSubIds($orgid) { $theorg = Org::find($orgid); if ($theorg) { $orgids = Org::where([['path', 'like', $theorg->path . '%']])->column('id'); return $orgids; } else { return []; } } function ossContentUpload($path, $content) { $accessKeyId = config('app.ali_oss_access_key_id'); $accessKeySecret = config('app.ali_oss_access_key_secret'); $endpoint = config('app.ali_oss_end_point'); $bucket = config('app.ali_oss_bucket'); $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint); try { $oss->putObject($bucket, $path, $content); } catch (OssException $e) { trace('文件内容上传失败,PATH:' . $path . ';error:' . $e->getErrorMessage(), 'error'); return false; } return true; } /** * 十进制转64进制 */ function dec52($num) { $out = ""; $codes = "zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM"; do { $i = 1; $y = $num % 52; $out = $codes[$y] . $out; $num = $num / 52 >= 1 ? $num / 52 : 0; $i++; } while ($num > 0); for ($i = 1; $i < 3; $i++) { $r = rand(0, 51); $out = $codes[$r] . $out; } return $out; } /** * 获取公海保护数据 */ function pubpoolSetting($type) { $existed_obj = Setting::where('name', 'pubpool')->find(); if ($existed_obj) { $contentarr = json_decode($existed_obj->content, true); return $contentarr[$type]; } else { return null; } } /** * 获取直属公海ID */ function knnPubPool($org_id) { $ownnodepool = Pool::where('org_id', $org_id)->find(); if (!$ownnodepool) { if ($org_id == 0) { return $org_id; } $current_org_node = Org::find($org_id); $parentnodepool = Pool::where('org_id', $current_org_node->pid)->find(); if (!$parentnodepool) { $grand_parent_org_node = Org::find($current_org_node->pid); $grandnodepool = Pool::where('org_id', $grand_parent_org_node->pid)->find(); if (!$grandnodepool) { $far_grand_parent_org_node = Org::find($grand_parent_org_node->pid); $fargrandnodepool = Pool::where('org_id', $far_grand_parent_org_node->pid)->find(); if (!$fargrandnodepool) { } return $grandnodepool->pid; } return $parentnodepool->pid; } return $current_org_node->pid; } return $org_id; } /** * 随机字符串生成 * @param length integer */ function str_rand(int $length) { $range = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM'; $str = ''; while ($length > 0) { $rand = mt_rand(0, 61); $str .= $range[$rand]; $length--; } return $str; } /* * 手机加密结构 */ function cypherphone($value) { $aec = new Aec(config('app.aec_key'), config('app.aec_iv')); $value = $aec->encrypt($value); return $value; } /* * 积分表数据增加 */ function credits($root_id, $val, $code, $org_id = 0) { $where[] = ['code', '=', $code]; $where[] = ['root_id', '=', $root_id]; if ($org_id > 0) { $where[] = ['org_id', '=', $org_id]; } $info = CreditsSetting::where($where)->find(); if ($info) { CreditsSetting::where($where)->update(['value' => $val]); } else { $save['code'] = $code; $save['root_id'] = $root_id; $save['value'] = $val; if ($org_id > 0) { $save['org_id'] = $org_id; } CreditsSetting::insert($save); } } /* * 公司unionid本系统自生成函数 */ // function unionidgen($username, $length = 16) // { // $key = ''; // $str = md5($username.config('app.salt')); // for ($i = 0; $i < $length; $i++) { // $key .= $str{mt_rand(0, 31)}; //生成php随机数 // } // return $key; // } /** * 断点调试方法 */ if (!function_exists('p')) { function p($data, $die = true, $show_type = false) { $trace = (new \Exception())->getTrace()[0]; echo "{$trace['file']}:{$trace['line']}行"; echo '
';
        if ($show_type) {
            var_dump($data);
        } else {
            print_r($data);
        }
        echo '
'; if ($die) die; } } /** * 创建文件夹 * @param $dir * @param int $mode * @return bool */ if (!function_exists('mkdirs')) { function mkdirs($dir, $mode = 0777) { if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE; if (!mkdirs(dirname($dir), $mode)) return FALSE; return @mkdir($dir, $mode); } } /** * 毫秒时间戳格式化 * @param $time * @return string|string[] */ if (!function_exists('get_microtime_format')) { function get_microtime_format($time) { $time = $time * 0.001; if (strstr($time, '.')) { sprintf("%01.3f", $time); //小数点。不足三位补0 list($usec, $sec) = explode(".", $time); $sec = str_pad($sec, 3, "0", STR_PAD_RIGHT); //不足3位。右边补0 } else { $usec = $time; $sec = "000"; } $date = date("Y-m-d H:i:s.x", $usec); return str_replace('x', $sec, $date); } } /** * 生成一个32位随机字符串 */ if (!function_exists('make_string')) { function make_string() { $time = time(); $random = random_int(1000, 9999); $str = md5($time . $random); return $str; } } /** * 生成一个不重复随机文件名 */ if (!function_exists('make_file_name')) { function make_file_name($path, $ext) { $file_name = make_string() . '.' . $ext; if (file_exists($path . $file_name)) { make_file_name($path, $ext); } return $file_name; } } /** * 获取当前部门上级部门 */ if (!function_exists('orgParentIds')) { function orgParentIds($orgid, $pid = []) { $pid[] = $orgid; $theorg = Org::find($orgid); if (!empty($theorg) && $theorg['pid'] != 0) { $pid = orgParentIds($theorg['pid'], $pid); } return $pid; } } /** * 获取根部门 */ if (!function_exists('orgRootId')) { function orgRootId($orgid) { $theorg = Org::find($orgid); $root_id = $theorg['id']; if (!empty($theorg) && $theorg['pid'] != 0) { $root_id = orgRootId($theorg['pid']); } return $root_id; } } /** * 数字转汉字 */ function numToWord($num) { $chiNum = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九'); $chiUni = array('', '十', '百', '千', '万', '亿', '十', '百', '千'); $chiStr = ''; $num_str = (string)$num; $count = strlen($num_str); $last_flag = true; //上一个 是否为0 $zero_flag = true; //是否第一个 $temp_num = null; //临时数字 $chiStr = ''; //拼接结果 if ($count == 2) { //两位数 $temp_num = $num_str[0]; $chiStr = $temp_num == 1 ? $chiUni[1] : $chiNum[$temp_num] . $chiUni[1]; $temp_num = $num_str[1]; $chiStr .= $temp_num == 0 ? '' : $chiNum[$temp_num]; } else if ($count > 2) { $index = 0; for ($i = $count - 1; $i >= 0; $i--) { $temp_num = $num_str[$i]; if ($temp_num == 0) { if (!$zero_flag && !$last_flag) { $chiStr = $chiNum[$temp_num] . $chiStr; $last_flag = true; } } else { $chiStr = $chiNum[$temp_num] . $chiUni[$index % 9] . $chiStr; $zero_flag = false; $last_flag = false; } $index++; } } else { $chiStr = $chiNum[$num_str[0]]; } return $chiStr; } /** * 数组转树形 */ function tree($data,$pid = 0, $persons) { $new_arr = []; foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $persions = isset($persons[$v['id']]) ? $persons[$v['id']] : []; $children = tree($data, $v['id'], $persons); $v['children'] = array_merge_recursive($children, $persions); if (empty($v['children'])) $v['disabled']=true; $new_arr[] = $v; } } return $new_arr; } /** * 小程序主体 更换 配置信息 * user表和employee表 字段需一致 * 根据域名判断使用的小程序 */ function appletConfiguration() { $domain = request()->domain(); $data['url'] = $domain; //原有小程序 $data['unionid'] = 'unionid'; //主体unionid $data['mini_openid'] = 'mini_openid'; //小程序openid $data['appid'] = config('app.kfweb_appid'); $data['secret'] = config('app.kfweb_secret'); $data['name'] = '装修宝pro'; return $data; } /** * 数据统计 */ function dataStatistics($root_id, $field, $count, $type = 'inc') { DataStatistics::where('root_id', $root_id)->$type($field, $count)->update(); } /** * 查询指定时间范围内的所有日期,月份,季度,年份 * * @param $startDate 指定开始时间,Y-m-d格式 * @param $endDate 指定结束时间,Y-m-d格式 * @param $type 类型,day 天,month 月份,quarter 季度,year 年份 * @return array */ function getDateByInterval($startDate, $endDate, $type) { $tempDate = $startDate; $returnData = []; $i = 0; if ($type == 'year') { while (strtotime($tempDate) < strtotime($endDate)) { $temp = []; $year = strtotime('+' . $i . ' year', strtotime($startDate)); $temp['name'] = date('Y', $year) . '年'; $temp['startDate'] = date('Y-01-01', $year); $temp['endDate'] = date('Y-12-31', $year); $tempDate = $temp['endDate']; $returnData[] = $temp; $i++; } } elseif ($type == 'month') { while (strtotime($tempDate) < strtotime($endDate)) { $temp = []; $month = strtotime('first day of +' . $i . ' month', strtotime($startDate)); $temp['name'] = date('Y-m', $month); $temp['startDate'] = date('Y-m-01', $month); $temp['endDate'] = date('Y-m-t', $month); $tempDate = $temp['endDate']; $returnData[] = $temp; $i++; } } else { if(strtotime($tempDate) == strtotime($endDate)){ $returnData[] = $tempDate; }else{ while (strtotime($tempDate) < strtotime($endDate)) { $tempDate = date('Y-m-d', strtotime('+' . $i . ' day', strtotime($startDate))); $returnData[] = $tempDate; $i++; } } } return $returnData; } /** * 计算两个时间的时间差 */ function get_date_diff($start, $end) { if (is_numeric($start)) $start = date('Y-m-d H:i:s'); if (is_numeric($end)) $end = date('Y-m-d H:i:s'); $startDate = date_create($start); $endDate = date_create($end); $d_time = date_diff($startDate, $endDate); $start_date = date('Y-m-d', strtotime($start)); $end_date = date('Y-m-d', strtotime($end)); $startDateD = date_create($start_date); $endDateD = date_create($end_date); $d_date = date_diff($startDateD, $endDateD); $d = [ 'y' => $d_time->y, 'm' => $d_time->m, 'd' => $d_time->d, 'h' => $d_time->h, 'i' => $d_time->i, 's' => $d_time->s, 'f' => $d_time->f, 'invert' => $d_time->invert, 'days' => $d_date->days ]; return (object)$d; } //vr第一帧 function getFirstImg($vr) { if (strpos($vr, '/vr/#')) { $ali_oss_bindurl = config('app.vr_ali_oss_bindurl'); $show_url = config('app.vr_show_domain'); $sid = substr(str_replace($show_url,'',$vr),0,32); $pic_path = VrGroup::where('sid',$sid)->value('pic_path'); $res = 'https://' . $ali_oss_bindurl . '/' . $pic_path; }else{ $vrObj = new Vr(); $res = $vrObj->getFirstImg($vr); } return $res; } //vr链接设置修改 function vrlinkSet($vr_link) { //2023-05-04 装企销冠app创建的vr作品 if (strpos($vr_link, '/vr/#')) return $vr_link; // 旧域名 替换成 新域名 $links = [ 'xiaohongwu' => 'hnweizhihui.xiaohongwu.nczyzs.com', 'kujiale' => 'pano337.p.kujiale.com', 'justeasy' => 'vr-17.justeasy.nczyzs.com', '3d66' => 'vr.3d66.nczyzs.com', ]; $url = parse_url($vr_link); if ($url === false || !isset($url['host'])) { echo json_encode(['code' => 1, 'msg' => '链接格式错误']); exit; } if (strpos($url['host'], 'xiaohongwu') !== false) { return str_replace($url['host'], $links['xiaohongwu'], $vr_link); } if (strpos($url['host'], 'kujiale') !== false) { return str_replace($url['host'], $links['kujiale'], $vr_link); } if (strpos($url['host'], 'justeasy') !== false) { return str_replace($url['host'], $links['justeasy'], $vr_link); } if (strpos($url['host'], '3d66') !== false) { return str_replace($url['host'], $links['3d66'], $vr_link); } echo json_encode(['code' => 1, 'msg' => '无效的VR链接']); exit; } /** * 下载文件并上传oss后删除本地文件 */ function downClueRecordUrl($url, $name) { $res = down_file($url, 'upload/fishcall/', 'upload/fishcall/' . $name); if ($res) { $url = app()->getRootPath() . 'public/upload/fishcall/' . $name; if(ossUpload('fishcall/' . $name, $url)){ unlink('upload/fishcall/' . $name); return true; } } return false; } /** * @param $url 文件下载地址 * @param string $folder 文件存储地址 * @param string $down_name 文件另存名称 * @return bool */ function down_file($url, $folder = "./", $down_name = '') { set_time_limit(0); // 设置超时时间 $destination_folder = $folder . '/'; // 文件下载保存目录,默认为当前文件目录 if (!is_dir($destination_folder)) { // 判断目录是否存在 mkdirs($destination_folder); // 如果没有就建立目录 } $file = fopen($url, "rb"); // 远程下载文件,二进制模式 if ($file) { // 如果下载成功 $newf = fopen($down_name, "wb"); // 远在文件文件 if ($newf) // 如果文件保存成功 while (!feof($file)) { // 判断附件写入是否完整 fwrite($newf, fread($file, 1024 * 8), 1024 * 8); // 没有写完就继续 } fclose($file); // 关闭远程文件 fclose($newf); } return true; }