123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- use Hashids\Hashids;
- use support\facade\Logger;
-
- function quickSort($array)
- {
- if(!isset($array[1]))
- return $array;
- $mid = $array[0];
- $leftArray = array();
- $rightArray = array();
- foreach($array as $v)
- {
- if($v > $mid)
- $rightArray[] = $v;
- if($v < $mid)
- $leftArray[] = $v;
- }
- $leftArray = quickSort($leftArray);
- $leftArray[] = $mid;
- $rightArray = quickSort($rightArray);
- return array_merge($leftArray,$rightArray);
- }
- function getHashids(){
- global $hashids;
- if($hashids instanceof Hashids ){
- return $hashids;
- }
- $hashids = new Hashids('D6M97LIvpp4qWuz3nKzqi6yYN4GAA61b',32);
- return $hashids;
-
- }
- function getProp($param, $key, $default = '')
- {
- $result = $default;
- if (is_object($param) && isset($param->$key)) {
- $result = $param->$key;
- }
- if (is_array($param) && isset($param[$key])) {
- $result = $param[$key];
- }
- return $result;
- }
- function get_client_ip()
- {
- $ip = '0.0.0.0';
- if ($request = request()) {
- $header = $request->header();
- if(isset($header['remoteip'])){
- $ip = $header['remoteip'];
- }else{
- $rip = $request->getRealIp();
- $riparr = explode(',',$rip);
- $ip = $riparr['0'];
- }
- }
- return $ip;
- }
- function get_client_ua()
- {
- $request = request();
- $header = $request->header();
- if(isset($header['user-agent'])){
- return $header['user-agent'];
- }
- Logger::app('noagent:'.json_encode($header));
- return '';
- }
|