Skip to content

Instantly share code, notes, and snippets.

@seandong
Created December 11, 2018 11:20
Show Gist options
  • Save seandong/427524818bc5ffbaafc61e57a9278d7d to your computer and use it in GitHub Desktop.
Save seandong/427524818bc5ffbaafc61e57a9278d7d to your computer and use it in GitHub Desktop.
zhiren API demo
#!/usr/bin/env python
# -*- coding: utf8 -*-
import hmac
import hashlib
import json
import time
import urllib
import requests
access_key = 'xxx'
secret_key = 'xxx'
#payload = ''
tonce = time.time()
string_to_sign = 'GET' + '/api/v2/sub_companies' + access_key + str(tonce)# + json.dumps(payload)
signature = hmac.new(secret_key, string_to_sign, hashlib.sha256).hexdigest()
params = {'access_key': access_key, 'tonce': tonce, 'payload': ''}
headers = {'x-zhiren-signature': signature}
r = requests.get('https://zhiren.com/api/v2/sub_companies', params=urllib.urlencode(params), headers=headers)
print r.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment