# python
# python(3.7)
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
# install requirement
pip install requests
pip install pycryptodome
"""
import requests
import json
import hashlib
import base64
from Crypto.Cipher import AES
from Crypto import Random
SRV_URL = "https://api.yazx.com/"
POST_URL = SRV_URL + "phone/check/v3/callback"
SNUSER = "xxxx"
SNKEY = 'xxxx'
def decrypt(encrypt_str: str, cecret: str):
"""
base64解码后,再进行aes解密
:param encrypt_str:
:param cecret:
:return:
"""
data = base64.decodebytes(bytes(encrypt_str, encoding="utf8"))
cihpertxt = data[AES.block_size:]
remainder = len(cihpertxt) % AES.block_size
if remainder:
padded_value = cihpertxt + b'\0' * (AES.block_size - remainder)
else:
padded_value = cihpertxt
cryptor = AES.new(bytes(cecret, encoding="utf-8"), AES.MODE_CFB, data[0:AES.block_size], segment_size=128)
plain_text = cryptor.decrypt(padded_value)
return str(plain_text[0:len(cihpertxt)], encoding="utf8")
def check():
payload = {"snuser": SNUSER}
r = requests.post(POST_URL, data=json.dumps(payload), verify=True)
rjson = r.json()
print("====>response body<====")
print(rjson)
if rjson["status"] == 200:
print("====>response plain<====")
json_data = json.loads(decrypt(rjson["data"], SNKEY))
print(json_data)
if __name__ == "__main__":
check()