def balanceOf( self, address ): nonce = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8)) timestamp = int(round(time.time() * 1000)) path = '/v1/wallets/' + address + '/service-tokens/' + self.contractId query_params = { 'limit': 10, 'orderBy': 'desc', 'page': 1 } headers = { 'service-api-key': self.service_api_key, 'nonce': nonce, 'timestamp': str(timestamp) } signature = get_signature('GET', path, nonce, timestamp, self.service_api_secret, query_params) headers['signature'] = signature res = requests.get(self.server_url + path, params=query_params, headers=headers) return res.json()
def mint( self, toAddress: str, amount: str ): nonce = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8)) timestamp = int(round(time.time() * 1000)) path = '/v1/service-tokens/' + self.contractId + '/mint' request_body = { 'ownerAddress': self.ownerAddress, 'ownerSecret': self.ownerSecret, 'toAddress': toAddress, 'amount': amount } headers = { 'service-api-key': self.service_api_key, 'nonce': nonce, 'timestamp': str(timestamp), 'Content-Type': 'application/json' } signature = get_signature('POST', path, nonce, timestamp, self.service_api_secret, body=request_body) headers['signature'] = signature res = requests.post(self.server_url + path, headers=headers, json=request_body) return res.json()
def req_black_list_api(accessKey, secretKey, formdata, url): # 10位秒级时间戳 timestamp = str(int(time.time())) method = 'POST' sig = get_signature(accessKey, secretKey, timestamp,formdata, url, method) headers = { 'signature': sig, 'content-type': 'application/json;charset=UTF-8', 'eventTime': timestamp, # 10位时间戳 'accessKey': accessKey, } resp = requests.post(url=url, headers=headers, data=json.dumps(formdata)) print(resp.text)
def get_info( self ): nonce = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8)) timestamp = int(round(time.time() * 1000)) path = '/v1/service-tokens' headers = { 'service-api-key': self.service_api_key, 'nonce': nonce, 'timestamp': str(timestamp) } signature = get_signature('GET', path, nonce, timestamp, self.service_api_secret) headers['signature'] = signature res = requests.get(self.server_url + path, headers=headers) return res.json()
"time_stamp": "2013-08-27T14:30:10Z", "version": 1, "vxnets.1": "vxnet-0", "zone": "pek1" } secret_access_key = 'SECRETACCESSKEY' body = utils.dict_to_sorted_tuple(body) encoded_body = utils.get_encoded_url(body) string_to_sign = utils.get_string_to_sign(encoded_body) signature = utils.get_signature(string_to_sign, secret_access_key, method='HmacSHA256') print signature import time import datetime print time.time() print datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") string = 'abc_def' print string.replace('_', '-') print str('access_key_id'.split('_'))
def SetSignature(self, request, context): s = get_signature(request) return items_pb2.ItemGRPC(Signature=s)
"version": 1, "vxnets.1": "vxnet-0", "zone": "pek1" } secret_access_key = 'SECRETACCESSKEY' body = utils.dict_to_sorted_tuple(body) encoded_body = utils.get_encoded_url(body) string_to_sign = utils.get_string_to_sign(encoded_body) signature = utils.get_signature( string_to_sign, secret_access_key, method='HmacSHA256' ) print signature import time import datetime print time.time() print datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") string = 'abc_def' print string.replace('_', '-') print str('access_key_id'.split('_'))