有谁有可以为 Walmart API 生成此标头的 python 代码吗?
WM_SEC.AUTH_SIGNATURE
我试图理解 java 示例,但我没有任何运气,因为我没有 Java 经验。
如果有人知道需要签名的字符串的格式,我可能可以从那里弄清楚。
我该如何解决这个问题?
这是我最终用来获取工作授权(如果有人需要的话)的代码:
import requests, json, pprint, time
from requests.auth import HTTPBasicAuth
import errno
from Crypto.Hash import SHA256
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
import hashlib
import base64
ACCOUNT_SID = 'xxxxxx'
AUTH_TOKEN = 'xxxxxxxx'
BASE_URL = 'https://products.api.impactradius.com/Mediapartners/{}/'.format(ACCOUNT_SID)
API_PATH = 'Catalogs/4277'
consumerId = 'xxxxxxxx'
epoxTime = str(int(time.time()*1000))
keyVersion = '1'
URL = 'https://developer.api.walmart.com/api-proxy/service/affil/product/v2/items'
hashDict = { 'WM_CONSUMER.ID' : consumerId,
'WM_CONSUMER.INTIMESTAMP' : epoxTime,
'WM_SEC.KEY_VERSION' : keyVersion
}
sortedHashString = hashDict['WM_CONSUMER.ID'] +'\n'+ hashDict['WM_CONSUMER.INTIMESTAMP'] +'\n'+ hashDict['WM_SEC.KEY_VERSION']+'\n'
encodedHashString = sortedHashString.encode()
try:
with open('./WM_IO_private_key.pem', 'r') as f:
key = RSA.importKey(f.read())
except IOError as e:
print(e)
hasher = SHA256.new(encodedHashString)
signer = PKCS1_v1_5.new(key)
signature = signer.sign(hasher)
signature_enc = str(base64.b64encode(signature),'utf-8')
headers = { 'WM_CONSUMER.ID' : consumerId,
'WM_CONSUMER.INTIMESTAMP' : epoxTime,
'WM_SEC.AUTH_SIGNATURE' : signature_enc,
'WM_SEC.KEY_VERSION' : keyVersion,
'WM_QOS.CORRELATION_ID' : 'afjksldkfj4r8ojfns',
'WM_IFX.CLIENT_TYPE' : 'INTERNAL',
'WM_PREVIEW' : 'false',
'WM_SHOW_REASON_CODES' : 'ALL',
'Content-Type' : 'application/json',
}
params = {
'category' : '4171_1228385',
'publisherId' : 'xxxxxxxxxxx'
}
response = requests.get(URL, headers=headers, params=params)
jsonData = json.loads(response.text)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)