def on_post(self, req, resp): # body = req.stream.read() # pdb.set_trace() # req.context = json.loads(body.decode('utf-8')) doc = req.context['doc'] sigg = doc['sigg'] if sigg != utils.getSignature(req): raise falcon.HTTPError(falcon.HTTP_753, 'BAD SIGNATURE', 'SIG INVALID') try: rawUrl = doc['raw'] last_update = datetime.datetime.now() short = utils.get_hash_key(rawUrl) short_path = 's.edyd.cn/' + short if not dbutils.find_update_short(short=short_path, raw=rawUrl, update_time=last_update): dbutils.save_short(short=short_path, raw=rawUrl, update_time=last_update) except Exception as e: raise falcon.HTTPError(falcon.HTTP_400, repr(e)) returndata = {'raw': rawUrl, 'short': short_path, 'last_update': last_update} resp.body = json.dumps(returndata, cls=utils.DatetimeEncoder)
def login(self, imsi, ua): print "==============user start login==================" input = { "method": "user.login", "userName": "", "userPass": "", } input["sig"] = utils.getSignature(input) params = urllib.urlencode(input) headers = { "user-agent": ua, "Appstore-clientType": "android", "Appstore-IMEI": "123456789000000", "Appstore-IMSI": imsi } try: connection = httplib.HTTPConnection(utils.API_HOST) connection.request("POST", "/api", params, headers) response = connection.getresponse().read() # print "=========" + response connection.close() except Exception(e): print("========" + str(e)) if "errorcode" in response or response is None: return results = json.loads(response) return results["results"].encode("utf-8")
def hitBinanceWebAPI(self, method, url, param='', signed=False): url = "https://api.binance.com" + url headers = {'X-MBX-APIKEY': config.getApiKey()} if (not signed): try: r = requests.request(method=method.upper(), url=url, params=param, headers=headers) data = r.json() return data except requests.exceptions.ConnectionError as e: err = {'e': 100, 'msg': 'Unable to connect to network'} data = json.loads(json.dumps(err)) except e: err = {'e': 100, 'msg': str(e)} data = json.loads(json.dumps(err)) return data else: if (param != ''): msg = utils.getQueryString(param) signature = utils.getSignature(msg) param.update({"signature": signature}) print param try: r = requests.request(method=method.upper(), url=url, headers=headers, params=param) data = r.json() except requests.exceptions.ConnectionError as e: err = {'e': 100, 'msg': 'Unable to connect to network'} data = json.loads(json.dumps(err)) except e: err = {'e': 100, 'msg': str(e)} data = json.loads(json.dumps(err)) return data
rhs_leaf.append(hashPadded(hex(j)[2] * 64, "1" * 64)[2:]) # The old leaf is previous pubkey + previous message old_leaf.append(createLeaf(public_key[j - 1], rhs_leaf[j - 1])) # The new leaf is current pubkey with current message new_leaf.append(createLeaf(public_key[j], rhs_leaf[j])) # The message to sign is the previous leaf with the new leaf message = hashPadded(old_leaf[j - 1], new_leaf[j - 1]) # Remove '0x' from byte message = message[2:] # Obtain Signature r, s = getSignature(message, sk[j - 1], public_key[j - 1]) # check the signature is correct ed.checkvalid(r, s, message, public_key[j - 1]) # Now we reverse the puplic key by bit # we have to reverse the bits so that the # unpacker in libsnark will return us the # correct field element # To put into little-endian pub_key_x = hex( int( ''.join( str(e) for e in hexToBinary(hex(public_key[j - 1][0]))[::-1]), 2)) pub_key_y = hex(