将参数转为hash形式
@param $params
@param $urlencode

@return string
168867
public static function buildQueryStr($params) {
        $arrTmp = array();
        foreach ($params as $k => $v){
            //参数为空不参与签名
            if(isset($v) && $v != ''){
                array_push($arrTmp, "$k=$v");
            }
        }
        return implode('&', $arrTmp);
    }
922090
public function hashCode()
    {
        $h = crc32(serialize($this->value)) ^ crc32($this->comparison);

        if ($this->table !== null) {
            $h ^= crc32($this->table);
        }

        if ($this->column !== null) {
            $h ^= crc32($this->column);
        }

        foreach ($this->clauses as $clause) {
            // TODO: I KNOW there is a php incompatibility with the following line
            // but I don't remember what it is, someone care to look it up and
            // replace it if it doesn't bother us?
            // $clause->appendPsTo($sb='',$params=array());
            $sb = '';
            $params = array();
            $clause->appendPsTo($sb, $params);
            $h ^= crc32(serialize(array($sb, $params)));
            unset ($sb, $params);
        }

        return $h;
    }
83496
function formatBizQueryParaMap($paraMap, $urlencode)
  {
    $buff = "";
    ksort($paraMap);
    foreach ($paraMap as $k => $v)
    {
      if($urlencode)
      {
        $v = urlencode($v);
      }
      //$buff .= strtolower($k) . "=" . $v . "&";
      $buff .= $k . "=" . $v . "&";
    }
    $reqPar = "";
    if (strlen($buff) > 0)
    {
      $reqPar = substr($buff, 0, strlen($buff)-1);
    }
    return $reqPar;
  }
1277362
private function privateRequest($url, $params = [], $method = 'GET')
    {
        // build the POST data string
        $params['timestamp']  = number_format((microtime(true) * 1000), 0, '.', '');
        $params['recvWindow'] = $this->recvWindow;

        $query   = http_build_query($params, '', '&');

        // set API key and sign the message
        $sign    = hash_hmac('sha256', $query, $this->secret);

        $headers = array(
            'X-MBX-APIKEY: ' . $this->key
        );

        // make request
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
   
         // build the POST data string
        $postdata = $params;

        // Set URL & Header
        curl_setopt($this->curl, CURLOPT_URL, $this->url . $url."?{$query}&signature={$sign}");

        //Add post vars
        if($method == "POST") {
            curl_setopt($this->curl,CURLOPT_POST, 1);
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, array());
        }

        //Get result
        $result = curl_exec($this->curl);
        if($result === false)
            throw new \Exception('CURL error: ' . curl_error($this->curl));

         // decode results
        $result = json_decode($result, true);
        if(!is_array($result) || json_last_error())
            throw new \Exception('JSON decode error');

        return $result;

    }
975432
static private function encodeMatched(string $pattern, array $params): string
    {
        // 参数替换进去
        $others = [];
        foreach ($params as $k => $v) {
            if (strstr($pattern, '{' . $k . '}') !== false) {
                $pattern = str_replace('{' . $k . '}', $v, $pattern);
            } else {
                $others[$k] = $v;
            }
        }

        //剩下的参数附加上去
        $pattern = self::urlAppend($pattern, $others);

        return trim($pattern, '?');
    }
78569
public String urlEncode(String s) {
        if (s == null || s.isEmpty()) {
            return s;
        }

        return URL.encodeQueryString(s);
    }
992272
public function buildRequestMysign($para_sort) {
        //把数组所有元素，按照“参数=参数值”的模式用“&”字符拼接成字符串
        $prestr = HelperFunction::createLinkstring($para_sort);

        $mysign = "";
        switch (strtoupper(trim($this->sign_type))) {
            case "MD5" :
                $mysign = HelperFunction::md5Sign($prestr, $this->key);
                break;
            default :
                $mysign = "";
        }

        return $mysign;
    }
406670
public static function urlEncode($key)
    {
        $s = urlencode($key);

        // Don't use strict form encoding by changing the square bracket control
        // characters back to their literals. This is fine by the server, and
        // makes these parameter strings easier to read.
        $s = str_replace('%5B', '[', $s);
        $s = str_replace('%5D', ']', $s);

        return $s;
    }
26078
public static function sign(array $params, string $secretKey, array $ignoreParamKeys = [], bool $doNotHash = false): string
    {
        $paramsPrepared = self::getParamsToSign($params, $ignoreParamKeys, 1);
        $stringToSign = implode(self::ITEMS_DELIMITER, $paramsPrepared);
        return $doNotHash
            ? $stringToSign
            : base64_encode(hash_hmac('sha512', $stringToSign, $secretKey, true))
            ;
    }
1352618
public function composeUri($params)
    {
        $ret   = '';
        $first = true;

        foreach ($params as $param => $values) {
            if (!$first) {
                $ret .= $this->seperators['param'];
            }
            $first    = false;
            $internal = $param;
            if ($external = $this->translateKeyOutput($param)) {
                $param = $external;
            }
            $ret .= $param . $this->seperators['key_value'];
            $firstValue = true;
            foreach ($values as $value) {
                if ($external = $this->translateValueOutput($internal, $value)) {
                    $value = $external;
                }
                if (!$firstValue) {
                    $ret .= $this->seperators['value'];
                } else {
                    $firstValue = false;
                }
                $ret .= urlencode($value);
            }
        }

        return $ret;
    }
83473
private function prepareQuery($params = []) {
		if(!is_array($params)) {
			return $params;
		}

		$query = [];

		foreach($params as $key => $value) {
			if(is_array($value)) {
				foreach($value as $element) {
					$query[] = sprintf(
						'%s[]=%s',
						$key,
						urlencode($element)
					);
				}
			} else {
				$query[] = sprintf(
					'%s=%s',
					$key,
					urlencode($value)
				);
			}
		}

		return implode("&",$query);
	}
980711
function getSignature(array $params, $method = null)
    {
        ksort($params);
        unset($params['sign']);
        unset($params['signature']);
        array_push($params, $this->secretKey);

        if ($method) {
            array_unshift($params, $method);
        }

        return hash('sha256', join('{up}', $params));
    }
1136078
private function privateRequest($url, $params = [], $method = "GET") {

        $url = $this->url . $url;

        //Doesnt work with an empty params array...
        if(sizeof($params)==0) $params['a'] = 'b';

        //Authorisation & request code taken from PHP example on cryptopia API guide
        $nonce = explode(' ', microtime())[1];
        $post_data                  = json_encode( $params );
        $m                          = md5( $post_data, true );
        $requestContentBase64String = base64_encode( $m );
        $signature                  = $this->key . "POST" . strtolower( urlencode( $url ) ) . $nonce . $requestContentBase64String;
        $hmacsignature              = base64_encode( hash_hmac("sha256", $signature, base64_decode( $this->secret ), true ) );
        $header_value               = "amx " . $this->key . ":" . $hmacsignature . ":" . $nonce;
        $headers                    = array("Content-Type: application/json; charset=utf-8", "Authorization: $header_value");

        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode( $params ) );
        curl_setopt($this->curl, CURLOPT_URL, $url );
        $result = curl_exec($this->curl);


        if($result===false)
            throw new \Exception('CURL error: ' . curl_error($this->curl));

         // decode results
        $result = json_decode($result, true);
        if(!is_array($result))
            throw new \Exception('JSON decode error');

        return $result;

    }
1209618
public function postUrlEncoded($url, array $params)
    {
        $request = new Request(
            $url,
            'POST',
            'php://temp',
            ['content-type' => 'application/x-www-form-urlencoded']
        );

        $request->getBody()->write(http_build_query($params));
        return $this->send($request);
    }
1160907
static public function secureUrlCached($url, $params = []) {
        if (is_array($url)) {
            $url = implode("/", $url);
        }
        $cacheKey = Cached::keymaker(__METHOD__, $url, $params);
        $cached = new Cached($cacheKey);
        if (!$cached->exists()) {
            $result = self::secureUrl($url, $params);
            syslog(LOG_INFO, "Returned " . count($result) . " rows.");
            $cached->set($result);
        }
        return $cached->get();
    }
920755
protected static function sns_token_uri($code)
    {
        $param = [
            'appid' => static::$appid,
            'secret' => static::$secret,
            'code' => $code,
            'grant_type' => 'authorization_code',
        ];

        return self::SNS_TOKEN_URI . http_build_query($param);
    }
750262
private function _get_id_string(string $request, string $params = null): string
  {
    return md5($request.($params ?: ''));
  }