解析返回的header头。
@param string $str 头信息。
@return array 返回头信息的数组。
485553
private static function _parseHttpSocketHeader($str) {
    $slice = explode("\r\n", $str);
    $headers = array();

    foreach ($slice as $v) {
      if (false !== strpos($v, "HTTP")) {
        list(, $headers["http_code"]) = explode(" ", $v);
        $headers["status"] = $v;
      } else {
        $item = explode(":", $v);
        $headers[$item[0]] = isset($item[1]) ? $item[1] : '';
      }
    }

    return $headers;
  }
1176530
private function checkSignature($str = '')
    {
        $nonce = $this->input->get('nonce');
        $timestamp = $this->input->get('timestamp');
        $msg_signature = $this->input->get('msg_signature');
        $signature = empty($msg_signature) ? $this->input->get('signature') : $msg_signature;
        $tmpArr = [$this->config->get('token'), $timestamp, $nonce, $str];
        sort($tmpArr, SORT_STRING);
        return sha1(implode($tmpArr)) === $signature;
    }
151332
public function decode($str)
    {
        $fixlen    = strlen($this->fixed_code);
        $user_id   = substr($str, -$this->length);
        $salt_rand = (int)substr($str, $fixlen, 1);
        $rand      = substr($str, $fixlen + 1, 4);

        $len  = strlen($user_id);
        $rlen = strlen($rand);
        $slen = count($this->salt);

        //对随机码解密
        $sr = $salt_rand;
        for ($j = 0; $j < $rlen; $j++) {
            if ($rand[$j] >= $sr) {
                $rand[$j] = $rand[$j] - $sr;
            } else {
                $rand[$j] = 10 - abs($rand[$j] - $sr);
            }

            $sr = ($rand[$j] + $sr) % 10;
        }

        //对用户ID加密
        for ($i = 0; $i < $len; $i++) {
            $k1 = $i % $rlen;
            $k2 = $i % $slen;

            $rval1 = $rand[$k1];

            if ($user_id[$i] >= $this->salt[$k2][$rval1]) {
                $user_id[$i] = $user_id[$i] - $this->salt[$k2][$rval1];
            } else {
                $user_id[$i] = 10 - abs($user_id[$i] - $this->salt[$k2][$rval1]);
            }
        }

        if ($this->validateNumber($user_id . $salt_rand)) {
            return ltrim($user_id, '0');
        } else {
            return 0;
        }
    }
832887
public function toBytes($str)
    {
        $hex = bin2hex($str);

        if (!$hex) {
            return array();
        }

        $b = array();
        for ($i = 0; $i < strlen($hex); $i += 2) {
            $b[] = chr(base_convert(substr($hex, $i, 2), 16, 10));
        }

        return $b;
    }
199318
public static function encode(String $str) : String
    {
        return str_replace(array_keys(self::$phpTagChars), array_values(self::$phpTagChars), $str);
    }
846191
private function extractHeaders($str)
    {
        $this->debug->log(__METHOD__);
        $this->debug->groupUncollapse();
        $headerStart = 0;
        #$this->debug->log(('top', \substr($return, 0, $this->curlInfo['header_size']));
        $headerLenStack = array();
        $i = 0;
        while (true) {
            $headerEnd     = \strpos($str, "\r\n\r\n", $headerStart);
            $headerLength  = $headerEnd - $headerStart;
            $headers       = \substr($str, $headerStart, $headerLength);
            $headerStart   = $headerEnd+4;
            $headerLenStack[] = \strlen($headers)+4;
            #$this->debug->log('headers', \str_replace(array("\r","\n"), array('|','|'), $headers));
            if (\count($headerLenStack) > $this->curlInfo['redirect_count']) {
                #$this->debug->log('header_len_stack','['.\implode(',',$header_len_stack).']');
                $sum = 0;
                for ($j=$i; $j>=0; $j--) {
                    $sum += $headerLenStack[$j];
                    if ($sum == $this->curlInfo['header_size']) {
                        #$this->debug->info('found headers');
                        break 2;
                    }
                }
            }
            if ($headerEnd === false || $i > 20) {
                $this->debug->warn('error parsing headers');
                break;
            }
            $i++;
        }
        // $this->debug->log('headers', $headers);
        return $headers;
    }
625817
public function getHeaderStr()
    {
        $headers = [];
        foreach ($this->getHeaders() as $co => $vo) {
            foreach ($vo as $ko) {
                $headers[] = $co . ': ' . $ko;
            }
        }
        return $headers;
    }
1182710
public static function getLength($str)
    {
        $bytes = 0;
        $chars = 0;
        while ($bytes < strlen($str)) {
            $charBytes = 1;
            if ((ord($str[$bytes]) & 0xC0) == 0xC0) {
                $charBytes++;
                if (ord($str[$bytes]) & 0x20 ) {
                    $charBytes++;
                    if (ord($str[$bytes]) & 0x10 ) {
                        $charBytes++;
                    }
                }
            }

            if ($bytes + $charBytes > strlen($str)) {
                // wrong character
                break;
            }

            $chars++;
            $bytes += $charBytes;
        }

        return $chars;
    }
1083420
private static function dealStr($str){
		$res = explode(self::$separate,$str);//空格分隔
        $str_time = preg_replace(self::$timeRegx,'',$res[self::$timeLine-1]);
        $date_time = \DateTime::createFromFormat(self::$timeFromat,$str_time,(new \DateTimeZone('Asia/Shanghai')));
        if ($date_time){
            $timestamp  = $date_time->getTimestamp();
        }else{
            throw new Exception("时间格式化有问题");
        }
        $t = $timestamp;
		$flow = $res[self::$flowLine-1]??0;//流量
		self::compareTime($t,$flow);
	}
428562
public function getErrors ($str = FALSE)
	{
		
		// Copy the errors array
		
		$errors	= $this->errors;
		
		// Reset errors
		
		$this->resetErrors ();
		
		// If return as string
		
		if ($str)
		{
			
			// Convert to string and return
			
			return implode ('<br />', $errors);
			
		}
		
		// Else
		
		else
		{
			
			// Return the errors array
			
			return $errors;
			
		}
		
	}
1024539
public static function encode(String $str) : String
    {
        return preg_replace
        (
            array_keys(self::$scriptTagChars), 
            array_values(self::$scriptTagChars), 
            $str
        );
    }
72984
public static function toString($str){
		$str = strtoupper($str);

		// csSave actually has to be able to consider extra characters
		if(self::$charset === Base32Characters::CROCKFORD){
			$str = str_replace('O', '0', $str);
			$str = str_replace(['I', 'L'], '1', $str);
		}

		return self::bin2str(self::toBin($str));
	}
865107
protected function checkSignature($str = '') {
        $signature = app('request')->get('signature');
        $signature = app('request')->get('msg_signature', $signature); //如果存在加密验证则用加密验证段
        $timestamp = app('request')->get('timestamp');
        $nonce = app('request')->get('nonce');

        $token = $this->configs['token'];
        $tmpArr = array($token, $timestamp, $nonce, $str);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        return $tmpStr == $signature;
    }
1182403
public static function strrev($str)
    {
        $result = '';
        $strLen = static::length($str);

        if (!$strLen) {
            return $result;
        }

        for ($i = $strLen - 1; $i >= 0; $i--) {
            $result .= static::substr($str, $i, 1);
        }

        return $result;
    }
241735
protected function getHexSequence($str)
	{
		$seq = [];
		$i   = 0;
		do
		{
			$cp = ord($str[$i]);
			if ($cp >= 0xF0)
			{
				$cp = ($cp << 18) + (ord($str[++$i]) << 12) + (ord($str[++$i]) << 6) + ord($str[++$i]) - 0x3C82080;
			}
			elseif ($cp >= 0xE0)
			{
				$cp = ($cp << 12) + (ord($str[++$i]) << 6) + ord($str[++$i]) - 0xE2080;
			}
			elseif ($cp >= 0xC0)
			{
				$cp = ($cp << 6) + ord($str[++$i]) - 0x3080;
			}
			$seq[] = sprintf('%04x', $cp);
		}
		while (++$i < strlen($str));

		return implode('-', $seq);
	}
828492
public static function getString(&$str)
    {
        $p = mb_orig_strpos($str, "\x00");
        if ($p === false) {
            return '';
        }
        $r = mb_orig_substr($str, 0, $p);
        $str = mb_orig_substr($str, $p + 1);
        return $r;
    }
197571
function unpack($str)
    {
        $data = array();
        foreach ($this->fileds as $k => $field)
        {
            /**
             * @var $field Field
             */
            switch ($field->type)
            {
                case Field::INT:
                    switch ($field->size)
                    {
                        case 1:
                            list(, $data[$k]) = unpack($field->signed ? 'c' : 'C', $str);
                            break;
                        case 2:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('n', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 's' : 'S', $str);
                            }
                            break;
                        case 4:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('N', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 'l' : 'L', $str);
                            }
                            break;
                        case 8:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('J', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 'q' : 'Q', $str);
                            }
                            break;
                        default:
                            break;
                    }
                    break;
                case Field::FLOAT:
                    list(, $data[$k]) = unpack($field->size == 4 ? 'f' : 'd', $str);
                    break;
                case Field::CHAR:
                    $data[$k] = substr($str, 0, strpos($str, "\0"));
                    break;
                case Field::STRUCT:
                    $data[$k] = $field->struct->unpack($str);
                    break;
                default:
                    break;
            }
            $str = substr($str, $field->size);
        }
        return $data;
    }