生成JS API的签名
@param string $nonceStr
@param int $time
@param string $url
@return string
557563
public function createSignature($nonceStr, $time, $url) {
        $str = "jsapi_ticket=%s&noncestr=%s&timestamp=%d&url=%s";
        $result = sprintf($str, $this->getJsApiTicket()->getTicket(), $nonceStr, $time, $url);
        return sha1($result);
    }
776873
public function redirect($url, $time = 0) {
        if (app('request')->wantsJson()) {
            return $this->json([
                'code' => 302,
                'status' => __('failure'),
                'errors' => '重定向',
                'url' => url()->to($url)
            ]);
        }
        return Factory::response()
            ->redirect(url()->to($url), $time);
    }
701062
private function createHTTPData($url , $payload = array() )
    {
        $nonce = round(microtime(true) * 1000);
        if(!empty($payload)){
            $body        = json_encode($payload);
            $message     = $nonce . $url . $body;
            $append_body = true;
        }else{
            $message     = $nonce . $url;
            $append_body = false;
        }
        $signature = $this->signMessage($message);
        $data = [
            'headers'          => [
                'API-Key'      => $this->api_key,
                'API-Nonce'    => $nonce,
                'API-Sign'     => $signature,
                'API-Platform' => $this->getOSVersion(),
                'API-Plugin'   => self::VERSION,
                'content-type' => 'application/json'
            ],
            'allow_redirects'  => false,
            'timeout'          => 300
        ];
        if($append_body){
            $data["body"] = $body;
        }
        return $data;
    }
457675
function Time(name, ...rest) {
    let h = (methodDescriptor)=>{
        let {key, descriptor} = methodDescriptor;

        let fn = descriptor.value;
        let timer;

        let timeStart;
        let timeEnd;
        if (console != null && typeof console.time === 'function') {
            timeStart = console.time;
            timeEnd = console.timeEnd;
        } else {
            timeStart = ()=>{
                timer = Date.now();
            };

            timeEnd = (name)=>{
                let abstime = Date.now() - timer;

                console.log(name, '：', abstime);
            };
        }

        descriptor.value = function(...args) {
            timeStart(name || key);
            let r = fn.apply(this, args);

            if (r && typeof r.then === 'function') {
                return r.then((succ)=>{
                    timeEnd(name || key);
                    return Promise.resolve(succ);
                }, (fail)=>{
                    timeEnd(name || key);
                    return Promise.reject(fail);
                });
            } else {
                timeEnd(name || key);
                return r;
            }
        };

        return {
            ...methodDescriptor,
            descriptor,
        };
    };

    if (typeof name === 'string') {
        return h;
    } else {
        let args = [name, ...rest];
        name = void(0);
        h(...args);
    }
}
778874
public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
	{
		//排序
		try {
			$array = array($encrypt_msg, $token, $timestamp, $nonce);
			sort($array, SORT_STRING);
			$str = implode($array);
			return array(ErrorCode::$OK, sha1($str));
		} catch (Exception $e) {
			//print $e . "\n";
			return array(ErrorCode::$ComputeSignatureError, null);
		}
	}
410211
public function getSignaturePackage($url = null, $nonce = null, $timestamp = null, $isAdminGroup = false)
    {
        $url = $url ? $url : $this->getUrl();
        $nonce = $nonce ? $nonce : $this->getNonce();
        $timestamp = $timestamp ? $timestamp : time();
        $ticket = $isAdminGroup ? $this->getGroupTicket() : $this->getTicket();

        $sign = $isAdminGroup ? array(
            'groupId' => $ticket['group_id'],
            'timestamp' => $timestamp,
            'nonceStr' => $nonce,
            'signature' => $this->getSignature($ticket['ticket'], $nonce, $timestamp, $url, true),
        ) : array(
            'appId' => $this->appId,
            'nonceStr' => $nonce,
            'timestamp' => $timestamp,
            'url' => $url,
            'signature' => $this->getSignature($ticket, $nonce, $timestamp, $url),
        );

        return $sign;
    }
821696
public function encrypt($xml, $nonce = null, $timestamp = null): string
    {
        try {
            $xml = $this->pkcs7Pad(str_random(16).pack('N', strlen($xml)).$xml.$this->appId, $this->blockSize);

            $encrypted = base64_encode(AES::encrypt(
                $xml,
                $this->aesKey,
                substr($this->aesKey, 0, 16),
                OPENSSL_NO_PADDING
            ));
            // @codeCoverageIgnoreStart
        } catch (Throwable $e) {
            throw new RuntimeException($e->getMessage(), self::ERROR_ENCRYPT_AES);
        }
        // @codeCoverageIgnoreEnd

        !is_null($nonce) || $nonce = substr($this->appId, 0, 10);
        !is_null($timestamp) || $timestamp = time();

        $response = [
            'Encrypt' => $encrypted,
            'MsgSignature' => $this->signature($this->token, $timestamp, $nonce, $encrypted),
            'TimeStamp' => $timestamp,
            'Nonce' => $nonce,
        ];

        //生成响应xml
        return XML::build($response);
    }
527795
function wrapTimerHandler(vHandler) {
				var fnWrappedHandler = function() {
					var aArgs, fnHandler;
					if (bPromisesQueued) {
						aArgs = [fnWrappedHandler, 0].concat(arguments);
						_timeout.apply(window, aArgs);
					} else {
						fnHandler = typeof vHandler !== "function" ? new Function(vHandler) : vHandler; // eslint-disable-line no-new-func
						fnHandler.apply(window, arguments);
					}
				};
				return fnWrappedHandler;
			}
520531
private String generateXml(String encrypt, String signature, String timestamp, String nonce) {
    String format =
        "<xml>\n"
            + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n"
            + "<MsgSignature><![CDATA[%2$s]]></MsgSignature>\n"
            + "<TimeStamp>%3$s</TimeStamp>\n"
            + "<Nonce><![CDATA[%4$s]]></Nonce>\n"
            + "</xml>";
    return String.format(format, encrypt, signature, timestamp, nonce);
  }
274187
public static function redirect($url, $time = 0)
    {
        strpos($url, 'http') === false && $url = self::url($url, 0);
        if (!headers_sent()) {
            ($time === 0) && header("Location: {$url}");
            header("refresh:{$time};url={$url}");
            exit();
        } else {
            exit("<meta http-equiv='Refresh' content='{$time};URL={$url}'>");
        }
    }
1301660
function getJSONP(url, options) {
  return new Promise(function (resolve, reject) {
    if (!url) {
      reject(new Error('No request url'));
    }

    var _ref = options || {};

    var _ref$params = _ref.params;
    var params = _ref$params === undefined ? {} : _ref$params;
    var _ref$timeout = _ref.timeout;
    var timeout = _ref$timeout === undefined ? 15000 : _ref$timeout;
    // the funtion name of callback function

    var name = void 0;
    var timer = void 0;
    var requestUrl = parseUrl(url, params);
    // check whether the callbacl name has been defined
    var match = /callback=(\w+)/.exec(requestUrl);

    if (match && match[1]) {
      name = match[1];
    } else {
      // generate a random function name if no callback name was defined
      // return a function name generated by timestamp and random number
      // eg: jsonp_1355750852040_8260732076596469
      name = 'jsonp_' + getNow() + '_' + getRandomNumber();
      requestUrl += '&callback=' + name;
    }

    // create a script element
    var script = document.createElement('script');
    script.type = 'text/javascript';
    // set the request url
    script.src = requestUrl;
    // set the id of dom node which can be used to find this node
    script.id = 'id_' + name;

    var cleanUp = function cleanUp() {
      // exec callback and remove the callback
      window[name] = undefined;
      // get the script node
      var elem = document.getElementById('id_' + name);
      // remove added script node
      removeElement(elem);

      if (timer) {
        clearTimeout(timer);
      }
    };

    if (timeout) {
      timer = setTimeout(function () {
        cleanUp();
        reject(new Error('Timeout'));
      }, timeout);
    }

    // the callback when request finish
    window[name] = function (json) {
      cleanUp();
      // exec callback
      resolve(json);
    };

    // add script node in head
    var head = document.getElementsByTagName('head');

    if (head && head[0]) {
      head[0].appendChild(script);
    }
  });
}
1300814
public function signature($url = null, $nonce = null, $timestamp = null)
    {
        $url = $url ? $url : $this->getUrl();
        $nonce = $nonce ? $nonce : Str::quickRandom(10);
        $timestamp = $timestamp ? $timestamp : time();
        $ticket = $this->ticket();

        $sign = [
            'appId'     => $this->getAccessToken()->getCorpId(),
            'nonceStr'  => $nonce,
            'timestamp' => $timestamp,
            'url'       => $url,
            'signature' => $this->getSignature($ticket, $nonce, $timestamp, $url),
        ];

        return $sign;
    }
147736
static function relative($time, $alwaysTime = false) {
		$time=self::convert($time, self::PHP);
		$today=date("Ymd");
		if ($time->format("Ymd")==$today) {
			return "dnes v ".$time->format("H.i");
		}
		$time2=clone $time;
		if ($time2->add(new DateInterval("P1D"))->format("Ymd")==$today) {
			return "včera v ".$time->format("H.i");
		}
		$time2=clone $time;
		if ($time2->add(new DateInterval("P2D"))->format("Ymd")==$today) {
			return "předevčírem v ".$time->format("H.i");
		}
		if ($time->format("Y")==date("Y")) {
			return $time->format("j. n.").($alwaysTime?(" v ".$time->format("H.i")):"");
		}
		return $time->format("j. n. Y").($alwaysTime?(" v ".$time->format("H.i")):"");
	}
835301
public static function create($handle, $name = '', $url = '')
    {
        $result = new static();
        $result->handle = (string) $handle;
        $result->name = (string) $name;
        $result->url = (string) $url;
        $result->latestVersion = null;
        $result->createdOn = new DateTime();

        return $result;
    }
44498
protected function timestamped_endpoint( $url ) {
		// Make string for cache with GMT.
		// This is for caching thus you get
		// unique request only for 1 time in 10 minutes.
		$time = substr( date_i18n( 'YmdHi', false, true ), 0, -1 ) . '0';
		return add_query_arg( [
			'timestamp' => $time,
		], $url );
	}
671678
private function getSign($nonce,$timestamp,$token)
	{
		$array = array($nonce,$timestamp,$token);
		sort($array);
		$sign = sha1(implode($array));
		return $sign;
	}
820434
public static function phpGet($url, $timeout = 5, $header = "")
    {
        $header = empty($header) ? self::defaultHeader() : $header;
        $opts = [
            'http' => [
                'protocol_version' => '1.0', //http协议版本(若不指定php5.2系默认为http1.0)
                'method' => "GET", //获取方式
                'timeout' => $timeout, //超时时间
                'header' => $header
            ]
        ];
        $context = stream_context_create($opts);
        return @file_get_contents($url, false, $context);
    }