Client Examples

Example

It’s very hard to help debug code remotely. Please don’t expect our support team to help troubleshoot your code. We will do our best to put more code examples here.

The most common issues are:

  • Client computer time is not in sync
  • The parameters are not sorted

Here is the PHP function for constructing a signature.

    private function createAuth($path, $apiParams, $verb)
    {
        if (empty($this->key) || empty($this->secret)) {
            throw new CCXAPIException("API key and secrect can't be empty");
        }
        static $i=0;
        $mt = explode(' ', microtime());
        $apiParams['tonce'] = $mt[1] . substr($mt[0], 2, 3);
        $apiParams['tonce'] += $i++%900;
        $apiParams['access_key'] = $this->key;
        ksort($apiParams);
        $query = http_build_query($apiParams, '', '&');
        // Server received decoded value
        $query = preg_replace('/%5B[0-9]*([a-z]+)?%5D/simU', '[\1]', $query);
        $signature = hash_hmac('sha256', "{$verb}|{$path}|{$query}", $this->secret);
        return $query .'&signature=' . $signature;
    }