// +---------------------------------------------------------------------- // 应用公共文件 // use think\Db; function get_array_url($k = '', $value = '', $emp = '') { $url = \think\Request::instance()->get(); unset($url['s']); if ($k) { if (isset($url[$k])) { if ($value) { $url[$k] = $value; } else { unset($url[$k]); } } else { if ($value) { $url[$k] = $value; } } } if ($emp) { $array = explode(',', $emp); if (is_array($array)) { foreach ($array as $key => $value) { if (isset($url[$value])) { unset($url[$value]); } } } } return http_build_query($url); } /** * curl操作函数 * @param string $url 请求地址 * @param string $method 提交方式 * @param array $postFields 提交内容 * @param array $header 请求头 * @return mixed 返回数据 */ function http($url, $method = "GET", $postFields = null, $headers = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); if (!is_null($postFields)) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); } //https request if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } if (is_array($headers) && 0 < count($headers)) { $httpHeaders = []; foreach ($headers as $key => $value) { array_push($httpHeaders, $key . ":" . $value); } curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); } $data = curl_exec($ch); $err = curl_errno($ch); curl_close($ch); if ($err > 0) { return curl_error($ch); } else { return $data; } } function get_income($uid, $touid) { $map = [ 'uid' => $touid, 'fromuser' => $uid, ]; $all = Db::name('AccountLogs')->where($map)->sum('increase') ?? '0.00'; return $all; } // 过滤掉特殊字符保留 中文 英文 数字 ,。【】 function check_text($str) { preg_match_all('/[\x{4e00}-\x{9fa5}\。\.a-zA-Z0-9【】,,-]/u', $str, $jg); return join('', $jg[0]); }