Last active
February 4, 2017 15:34
-
-
Save simpleapples/065f5a8ede296db350f2bcbffa509650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# device_id, sid, uid 需要自己先抓包获取到 | |
# game_mode 1是无尽模式 2是限时模式 | |
import hashlib | |
import hmac | |
import base64 | |
import requests | |
def data_to_string(data): | |
result_string = '' | |
dict_keys = data.keys() | |
sorted_dict_keys = sorted(dict_keys) | |
for dict_key in sorted_dict_keys: | |
result_string += ('&' + str(dict_key) + '=' + str(data[dict_key])) | |
return result_string[1:] | |
def sign_string(string): | |
with open(const.SINAPAY_SIGN_PRIVATE_KEY_PATH) as file: | |
key_string = file.read() | |
key = RSA.importKey(key_string) | |
hash_object = SHA.new(string.encode('utf-8')) | |
signer = PKCS1_v1_5.new(key) | |
signature = signer.sign(hash_object) | |
return base64.b64encode(signature).decode('utf-8') | |
secret = '/TzSbON46vSq88gJyzosplEIoDyMpssbFDCj&' | |
root_url = 'http://snakeapi.afunapp.com/' | |
path = 'top_list_v2/update_score' | |
url = root_url + path | |
data = {'device_id': 'XXX', | |
'game_mode': '1', | |
'kill': '1', | |
'length': '1', | |
'market': 'apple', | |
'platform': '1', | |
'push_channel': '1', | |
'push_id': '111111111222222223333333344444444', | |
'sid': 'XXX', | |
'uid': 'XXX', | |
'version': '2.1'} | |
params_string = data_to_string(data) | |
params_string = 'POST&' + path + '&' + params_string | |
sign = hmac.new(secret.encode(), params_string.encode(), hashlib.sha1).digest() | |
sign_string = base64.urlsafe_b64encode(sign).decode().replace('_', '/').replace('-', '+') | |
params_dict = data.copy() | |
params_dict['snake_sign'] = sign_string | |
response = requests.post(url, params_dict) | |
print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment