сделать подпись :
The signature message is built by concatenating the following data with a line break "\n"
HTTP Method ("POST")
MD5 hash of payload (the XML itself)
Content-Type header (e.g. "text/xml; charset=utf-8")
Timestamp as sent in Date header
Additional custom headers (usually empty)
Request URI string (usually "/transaction")
Afterwards you build the HMAC digest with SHA512 of this message with the shared secret as key. The digest should be generated in binary (not hexadecimal) and then base64 encoded.
вот как я это делаю:
xml = '<?xml version='1.0' encoding='utf-8'?>...'
now = datetime.utcnow()
form = 'EEE, dd LLL yyyy hh:mm:ss'
date = format_datetime(now, form, locale='en') + ' GMT'
headers = {
'Content-Type': 'text/xml; charset=utf-8',
'Date': date,
'Authorization': ''
}
b64body = base64.b64encode(xml.encode())
signature_string = f"POST\n{b64body}\n{headers['Content-Type']}\n{headers['Date']}\n/transaction\n{shared_key}"
sign = base64.b64encode(hashlib.sha512(signature_string.encode()).hexdigest().encode())
headers['Authorization'] = f'Gateway {api_key}:{sign}'
но оно его не принимает, подскажите пожалуйста правильно ли я заинкодил sign согласно описанию ?
во-первых, не надо так строить хмл
Обсуждают сегодня