Mini Shell

Direktori : /www/wwwroot/itapgo.com/wp-includes/Requests/
Upload File :
Current File : /www/wwwroot/itapgo.com/wp-includes/Requests/IDNAEncoder.php

<?php

/**
 * IDNA URL encoder
 *
 * Note: Not fully compliant, as nameprep does nothing yet.
 *
 * @package Requests
 * @subpackage Utilities
 * @see https://tools.ietf.org/html/rfc3490 IDNA specification
 * @see https://tools.ietf.org/html/rfc3492 Punycode/Bootstrap specification
 */
class Requests_IDNAEncoder {
	/**
	 * ACE prefix used for IDNA
	 *
	 * @see https://tools.ietf.org/html/rfc3490#section-5
	 * @var string
	 */
	const ACE_PREFIX = 'xn--';

	/**#@+
	 * Bootstrap constant for Punycode
	 *
	 * @see https://tools.ietf.org/html/rfc3492#section-5
	 * @var int
	 */
	const BOOTSTRAP_BASE         = 36;
	const BOOTSTRAP_TMIN         = 1;
	const BOOTSTRAP_TMAX         = 26;
	const BOOTSTRAP_SKEW         = 38;
	const BOOTSTRAP_DAMP         = 700;
	const BOOTSTRAP_INITIAL_BIAS = 72;
	const BOOTSTRAP_INITIAL_N    = 128;
	/**#@-*/

	/**
	 * Encode a hostname using Punycode
	 *
	 * @param string $string Hostname
	 * @return string Punycode-encoded hostname
	 */
	public static function encode($string) {
		$parts = explode('.', $string);
		foreach ($parts as &$part) {
			$part = self::to_ascii($part);
		}
		return implode('.', $parts);
	}

	/**
	 * Convert a UTF-8 string to an ASCII string using Punycode
	 *
	 * @throws Requests_Exception Provided string longer than 64 ASCII characters (`idna.provided_too_long`)
	 * @throws Requests_Exception Prepared string longer than 64 ASCII characters (`idna.prepared_too_long`)
	 * @throws Requests_Exception Provided string already begins with xn-- (`idna.provided_is_prefixed`)
	 * @throws Requests_Exception Encoded string longer than 64 ASCII characters (`idna.encoded_too_long`)
	 *
	 * @param string $string ASCII or UTF-8 string (max length 64 characters)
	 * @return string ASCII string
	 */
	public static function to_ascii($string) {
		// Step 1: Check if the string is already ASCII
		if (self::is_ascii($string)) {
			// Skip to step 7
			if (strlen($string) < 64) {
				return $string;
			}

			throw new Requests_Exception('Provided string is too long', 'idna.provided_too_long', $string);
		}

		// Step 2: nameprep
		$string = self::nameprep($string);

		// Step 3: UseSTD3ASCIIRules is false, continue
		// Step 4: Check if it's ASCII now
		if (self::is_ascii($string)) {
			// Skip to step 7
			if (strlen($string) < 64) {
				return $string;
			}

			throw new Requests_Exception('Prepared string is too long', 'idna.prepared_too_long', $string);
		}

		// Step 5: Check ACE prefix
		if (strpos($string, self::ACE_PREFIX) === 0) {
			throw new Requests_Exception('Provided string begins with ACE prefix', 'idna.provided_is_prefixed', $string);
		}

		// Step 6: Encode with Punycode
		$string = self::punycode_encode($string);

		// Step 7: Prepend ACE prefix
		$string = self::ACE_PREFIX . $string;

		// Step 8: Check size
		if (strlen($string) < 64) {
			return $string;
		}

		throw new Requests_Exception('Encoded string is too long', 'idna.encoded_too_long', $string);
	}

	/**
	 * Check whether a given string contains only ASCII characters
	 *
	 * @internal (Testing found regex was the fastest implementation)
	 *
	 * @param string $string
	 * @return bool Is the string ASCII-only?
	 */
	protected static function is_ascii($string) {
		return (preg_match('/(?:[^\x00-\x7F])/', $string) !== 1);
	}

	/**
	 * Prepare a string for use as an IDNA name
	 *
	 * @todo Implement this based on RFC 3491 and the newer 5891
	 * @param string $string
	 * @return string Prepared string
	 */
	protected static function nameprep($string) {
		return $string;
	}

	/**
	 * Convert a UTF-8 string to a UCS-4 codepoint array
	 *
	 * Based on Requests_IRI::replace_invalid_with_pct_encoding()
	 *
	 * @throws Requests_Exception Invalid UTF-8 codepoint (`idna.invalidcodepoint`)
	 * @param string $input
	 * @return array Unicode code points
	 */
	protected static function utf8_to_codepoints($input) {
		$codepoints = array();

		// Get number of bytes
		$strlen = strlen($input);

		// phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer -- This is a deliberate choice.
		for ($position = 0; $position < $strlen; $position++) {
			$value = ord($input[$position]);

			// One byte sequence:
			if ((~$value & 0x80) === 0x80) {
				$character = $value;
				$length    = 1;
				$remaining = 0;
			}
			// Two byte sequence:
			elseif (($value & 0xE0) === 0xC0) {
				$character = ($value & 0x1F) << 6;
				$length    = 2;
				$remaining = 1;
			}
			// Three byte sequence:
			elseif (($value & 0xF0) === 0xE0) {
				$character = ($value & 0x0F) << 12;
				$length    = 3;
				$remaining = 2;
			}
			// Four byte sequence:
			elseif (($value & 0xF8) === 0xF0) {
				$character = ($value & 0x07) << 18;
				$length    = 4;
				$remaining = 3;
			}
			// Invalid byte:
			else {
				throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $value);
			}

			if ($remaining > 0) {
				if ($position + $length > $strlen) {
					throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
				}
				for ($position++; $remaining > 0; $position++) {
					$value = ord($input[$position]);

					// If it is invalid, count the sequence as invalid and reprocess the current byte:
					if (($value & 0xC0) !== 0x80) {
						throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
					}

					--$remaining;
					$character |= ($value & 0x3F) << ($remaining * 6);
				}
				$position--;
			}

			if (// Non-shortest form sequences are invalid
				$length > 1 && $character <= 0x7F
				|| $length > 2 && $character <= 0x7FF
				|| $length > 3 && $character <= 0xFFFF
				// Outside of range of ucschar codepoints
				// Noncharacters
				|| ($character & 0xFFFE) === 0xFFFE
				|| $character >= 0xFDD0 && $character <= 0xFDEF
				|| (
					// Everything else not in ucschar
					$character > 0xD7FF && $character < 0xF900
					|| $character < 0x20
					|| $character > 0x7E && $character < 0xA0
					|| $character > 0xEFFFD
				)
			) {
				throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
			}

			$codepoints[] = $character;
		}

		return $codepoints;
	}

	/**
	 * RFC3492-compliant encoder
	 *
	 * @internal Pseudo-code from Section 6.3 is commented with "#" next to relevant code
	 * @throws Requests_Exception On character outside of the domain (never happens with Punycode) (`idna.character_outside_domain`)
	 *
	 * @param string $input UTF-8 encoded string to encode
	 * @return string Punycode-encoded string
	 */
	public static function punycode_encode($input) {
		$output = '';
		// let n = initial_n
		$n = self::BOOTSTRAP_INITIAL_N;
		// let delta = 0
		$delta = 0;
		// let bias = initial_bias
		$bias = self::BOOTSTRAP_INITIAL_BIAS;
		// let h = b = the number of basic code points in the input
		$h = 0;
		$b = 0; // see loop
		// copy them to the output in order
		$codepoints = self::utf8_to_codepoints($input);
		$extended   = array();

		foreach ($codepoints as $char) {
			if ($char < 128) {
				// Character is valid ASCII
				// TODO: this should also check if it's valid for a URL
				$output .= chr($char);
				$h++;
			}
			// Check if the character is non-ASCII, but below initial n
			// This never occurs for Punycode, so ignore in coverage
			// @codeCoverageIgnoreStart
			elseif ($char < $n) {
				throw new Requests_Exception('Invalid character', 'idna.character_outside_domain', $char);
			}
			// @codeCoverageIgnoreEnd
			else {
				$extended[$char] = true;
			}
		}
		$extended = array_keys($extended);
		sort($extended);
		$b = $h;
		// [copy them] followed by a delimiter if b > 0
		if (strlen($output) > 0) {
			$output .= '-';
		}
		// {if the input contains a non-basic code point < n then fail}
		// while h < length(input) do begin
		$codepointcount = count($codepoints);
		while ($h < $codepointcount) {
			// let m = the minimum code point >= n in the input
			$m = array_shift($extended);
			//printf('next code point to insert is %s' . PHP_EOL, dechex($m));
			// let delta = delta + (m - n) * (h + 1), fail on overflow
			$delta += ($m - $n) * ($h + 1);
			// let n = m
			$n = $m;
			// for each code point c in the input (in order) do begin
			for ($num = 0; $num < $codepointcount; $num++) {
				$c = $codepoints[$num];
				// if c < n then increment delta, fail on overflow
				if ($c < $n) {
					$delta++;
				}
				// if c == n then begin
				elseif ($c === $n) {
					// let q = delta
					$q = $delta;
					// for k = base to infinity in steps of base do begin
					for ($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE) {
						// let t = tmin if k <= bias {+ tmin}, or
						//     tmax if k >= bias + tmax, or k - bias otherwise
						if ($k <= ($bias + self::BOOTSTRAP_TMIN)) {
							$t = self::BOOTSTRAP_TMIN;
						}
						elseif ($k >= ($bias + self::BOOTSTRAP_TMAX)) {
							$t = self::BOOTSTRAP_TMAX;
						}
						else {
							$t = $k - $bias;
						}
						// if q < t then break
						if ($q < $t) {
							break;
						}
						// output the code point for digit t + ((q - t) mod (base - t))
						$digit   = $t + (($q - $t) % (self::BOOTSTRAP_BASE - $t));
						$output .= self::digit_to_char($digit);
						// let q = (q - t) div (base - t)
						$q = floor(($q - $t) / (self::BOOTSTRAP_BASE - $t));
					} // end
					// output the code point for digit q
					$output .= self::digit_to_char($q);
					// let bias = adapt(delta, h + 1, test h equals b?)
					$bias = self::adapt($delta, $h + 1, $h === $b);
					// let delta = 0
					$delta = 0;
					// increment h
					$h++;
				} // end
			} // end
			// increment delta and n
			$delta++;
			$n++;
		} // end

		return $output;
	}

	/**
	 * Convert a digit to its respective character
	 *
	 * @see https://tools.ietf.org/html/rfc3492#section-5
	 * @throws Requests_Exception On invalid digit (`idna.invalid_digit`)
	 *
	 * @param int $digit Digit in the range 0-35
	 * @return string Single character corresponding to digit
	 */
	protected static function digit_to_char($digit) {
		// @codeCoverageIgnoreStart
		// As far as I know, this never happens, but still good to be sure.
		if ($digit < 0 || $digit > 35) {
			throw new Requests_Exception(sprintf('Invalid digit %d', $digit), 'idna.invalid_digit', $digit);
		}
		// @codeCoverageIgnoreEnd
		$digits = 'abcdefghijklmnopqrstuvwxyz0123456789';
		return substr($digits, $digit, 1);
	}

	/**
	 * Adapt the bias
	 *
	 * @see https://tools.ietf.org/html/rfc3492#section-6.1
	 * @param int $delta
	 * @param int $numpoints
	 * @param bool $firsttime
	 * @return int New bias
	 *
	 * function adapt(delta,numpoints,firsttime):
	 */
	protected static function adapt($delta, $numpoints, $firsttime) {
		// if firsttime then let delta = delta div damp
		if ($firsttime) {
			$delta = floor($delta / self::BOOTSTRAP_DAMP);
		}
		// else let delta = delta div 2
		else {
			$delta = floor($delta / 2);
		}
		// let delta = delta + (delta div numpoints)
		$delta += floor($delta / $numpoints);
		// let k = 0
		$k = 0;
		// while delta > ((base - tmin) * tmax) div 2 do begin
		$max = floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN) * self::BOOTSTRAP_TMAX) / 2);
		while ($delta > $max) {
			// let delta = delta div (base - tmin)
			$delta = floor($delta / (self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN));
			// let k = k + base
			$k += self::BOOTSTRAP_BASE;
		} // end
		// return k + (((base - tmin + 1) * delta) div (delta + skew))
		return $k + floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN + 1) * $delta) / ($delta + self::BOOTSTRAP_SKEW));
	}
}
福建点点够企业管理有限公司 | 中国银联条码前置平台全国拓展商

打造支付生态系统

打造由机构、商家、供应链、消费者多重角色的支付生态系统,支持机构实现管道财富自由!

专业的国际化内训扁平化的奖金制度

系统化、国际化的内训

专业的导师团、教练团为团队赋能,支持团队每个人拿到自己的家庭、事业、健康三大目标,同时有内训系统的晋升机制,全面实现每个合伙人“生命丰盛,生活富足”的人生愿景。

平台化支付管道收益

响应国家平台化经济体建设政策号召,深入运营中国银联条码支付综合前置平台的全国拓展,以及国有企业-现代金控的创鑫钱包业务全国合伙人招募,令每个参与者都能建立稳定、可持续的管道式收益事业。

未来前瞻

居于庞大的合伙人群体建设成熟,形成了海量的商户和交易数据,为点点够系统沉淀巨量大数据,数据资产运营以及以人为本的自主研发产品将逐步上线,旨在让每个点点够的数据节点都能发挥出应有的价值。

以人为本的培训生态

点点够引入了国际先进的企业管理课程,并对课程内容进行了行业订制化和国学本土化的转换,每个加入点点够的内勤或合伙人都将经历“体验式”全程培训,历经4个月。全面将每一个人打造成为在生活和工作方方面面都有影响力的人物。

为什么选择点点够?

在点点够,除了让你建立以国有企业为背景的产品平台管道式收益,还让你在不断学习和教练托起团队成员的同时,也不断让你越来越“值钱”。一群人,一起做一件有意义有价值的事情。建立正向的人生观、价值观、世界观。

2019年初,中国银联上线“条码前置平台-up.95516.com”,福建点点够企业管理有限公司与中国银联厦门分公司、新生支付有限公司签署三方协议,成为中国银联全国拓展机构。并开始向全国拓展子机构。

2022年4月点点够又与国通星驿签署全国拓展协议,补充了新生支付只能在福建、浙江、江苏、四川、海南五省拓展的不足。真正为全国全量拓展提供了更多可能性。

点点够团队志在2023年12月1日达到月交易过百亿!

值得投资的大数据价值

点点够将不断沉淀合伙人、商户、消费者交易数据,海量的数据将转化为更具时代意义的价值,我们将数据从现实交易数据转化为“实体+虚拟化”二维世界的数据,为用户提供现实和元宇宙双重服务。点点够通用积分机制和元宇宙创意平台计划于2025年上线。

合伙人社群

点点够服务的第一阵营是银联机构和创鑫伙伴,这些都是具有创业激情和梦想的人,基础业务数据都是靠这些人沉淀的,他们对点点够的企业文化及内训具有强烈的信任感,同时对这个国家和社会也具有时代的使命感。

/

商户社群

从刷卡机用户,到收款码商家,再到B2B企业级大型商户,都是机构服务的对象,也是点点够事业奠基的根本,持续为他们提供更具服务价值的支持,将不断拉升对点点够平台的信赖。

持卡人社群

信用卡持卡人的增长是有目共睹的,他们成为了我们重要的创业过滤群体,他们更有理财、管理能力,同时也是渴望财富自由、生活幸福的核心群体。点点够为他们提供专业的用卡服务指导。

扫码消费社群

巨量的扫码消费群体,几乎涵盖所有人。点点够透过积分机制,将线下实际交易数据转化为点点够应用端(微信小程序、云闪付小程序)的多元化服务,为他们提供包括但不限于:线上购物通兑,元宇宙平台充值通兑。

行业资讯

数字经济催生新兴业态,聚合码付打造便捷的支付方式

数字经济催生新兴业态,聚合码付打造便捷的支付方式

随着数字经济的快速发展,新兴业态如雨后春笋般涌现。数字经济以互联网、物联网、人工智能等技术为基础,改变了传统经济的生产、流通和消费方式,带动了新的商业模式和产业形态的诞生。同时,数字经济也创造了一种全新的支付方式,让人们享受到了更加便捷的消费体验。 数字经济催生新兴业态...

央行发布:2023年支付结算工作重点

央行发布:2023年支付结算工作重点

据人民银行官网消息,日前,人民银行召开2023年支付结算工作电视会议。会议全面总结2022年支付结算工作,深入分析当前面临的形势,就2023年重点工作任务作出部署。人民银行党委委员、副行长张青松出席会议并讲话。 会议认为,2022年人民银行支付结算条线认真贯彻落实党中央决策部署,按照行党委工作要求,始终坚持“支付为民”,支付市场治理扎实有效,支付清算基础设施稳健运行,支付普惠进程不断深化,有效服务实体经济和民生发展。...

周小川最新重磅发言!谈及支付业务

中国金融学会第七届理事会会长、中国央行原行长周小川近日在“2023中国金融学会学术年会暨中国金融论坛年会”时发表演讲,谈及支付系统的演进和商业银行个贷模式的选择,认为这与现代化有一定的关系,起因是这些年其一直在观察支付系统和数字货币的进展,而它们正是服务于实体经济。 这些年支付系统的演进变化很快,有很多新技术和新进展,特别是从互联网支付到数字货币,到数字驱动的个人零售业务,下一步可能大家还要研究人工智能会有什么样的影响和作用。...

联系我们

点点够总部在美丽的海滨城市厦门,欢迎随时前来考察指导!网站底部有我们的客服电话,请于上班时间来电!上班时间:周一至周五,上午9:00-晚上9:00.