def ListRecommendations(execute_command): params = ['Action=ListRecommendations'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) if 'recommend_category' in execute_command: if execute_command['recommend_category'] != '': params += [ 'RecommendationCategory=' + quote(execute_command['recommend_category']) ] params = params + default_params params = sorted(params) params = '&'.join(params) sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) url = connect_url(params, signature) r = requests.post(url, headers=headers) result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def ListReturnReasonCodes(execute_command): params = ['Action=ListReturnReasonCodes'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) if 'fulfillment_order_id' in execute_command: if execute_command['fulfillment_order_id'] != '': params.append('SellerFulfillmentOrderId=' + quote(execute_command['fulfillment_order_id'])) if 'sku' in execute_command: if execute_command['sku'] != '': params.append('SellerSKU=' + quote(execute_command['sku'])) if 'language' in execute_command: if execute_command['language'] != '': params.append('Language=' + quote(execute_command['language'])) params = params + default_params params = sorted(params) params = '&'.join(params) sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) url = connect_url(params, signature) r = requests.post(url, headers=headers) result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def CancelShipment(execute_command): params = ['Action=CancelShipment'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += default_params # 获取认证参数 # 把认证参数添加进请求头 params += common_unit.make_access_param(user_access_dict, execute_command) params = params + default_params params += ['ShipmentId=' + execute_command['shipment_id']] params = sorted(params) params = '&'.join(params) # print(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 # print(common_unit.xmltojson(r.text)) return common_unit.xmltojson(r.text)
def GetFeedSubmissionListByNextToken(execute_command): params = ['Action=GetFeedSubmissionListByNextToken'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) if 'next_token' in execute_command: if execute_command['next_token'] != '': params.append('NextToken=' + execute_command['next_token']) params = params + default_params params = sorted(params) params = '&'.join(params) params = params.replace('+', '%2B') params = params.replace('/', '%2F') params = params + default_params params = sorted(params) params = '&'.join(params) sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) url = connect_url(params, signature) r = requests.post(url, headers=headers) result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def GetFeedSubmissionResult(execute_command): params = ['Action=GetFeedSubmissionResult'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) if 'submission_id' in execute_command: if execute_command['submission_id'] != '': params += [ 'FeedSubmissionId=' + execute_command['submission_id'] ] params = params + default_params params = sorted(params) params = '&'.join(params) sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) url = connect_url(params, signature) r = requests.post(url, headers=headers) # print(r.text) result = r.text # result = common_unit.xmltojson(r.text) # error_result = common_unit.catch_exception(result) # 异常处理 # if error_result != '': # result = error_result return result
def test_access_code(execute_command): params = ['Action=ListMarketplaceParticipations'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序 # 拼接请求身,需要按首字母排序 # 关于api的分类和版本 params = '&'.join(params) # print(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 # print(common_unit.xmltojson(r.text)) result = common_unit.xmltojson(r.text) result = json.loads(result) if "ErrorResponse" not in result: result = {'status_code': '0', 'message': '你真厉害,好哥哥!验证成功啦!'} else: result = {'status_code': '-1', 'message': '你眼瞎啊?抄access都抄错'} return json.dumps(result)
def ListOrdersByNextToken(execute_command): if common_unit.test_access_param(execute_command) != -1: result = common_unit.read_xmlfile('test_file/order_list_next.xml') else: params = ['Action=ListOrdersByNextToken'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) if 'next_token' in execute_command: if execute_command['next_token'] != '': next_token = execute_command['next_token'] params += ['NextToken=' + quote(next_token)] params += default_params params = sorted(params) params = '&'.join(params) params = params.replace('+', '%2B') params = params.replace('/', '%2F') sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) signature = signature.replace('=', '%3D') signature = signature.replace('/', '%2F') url = connect_url(params, signature) r = requests.post(url, headers=headers) result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def GetReportScheduleCount(execute_command): params = ['Action=GetReportScheduleCount'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) # 获取包含认证参数的字典 if 'report_type' in execute_command: if execute_command['report_type'] != '': report_list = execute_command['report_type'].split(',') report_type_list = [] for i in report_list: report_type_list.append('ReportTypeList.Type.' + str(report_list.index(i) + 1) + '=' + i) params += report_type_list params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, execute_command['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def ListMarketplaceParticipations(execute_command): params = ['Action=ListMarketplaceParticipations'] + api_version user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序 # 拼接请求身,需要按首字母排序 # 关于api的分类和版本 params = '&'.join(params) # print(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 # print(common_unit.xmltojson(r.text)) return common_unit.xmltojson(r.text)
def UpdateReportAcknowledgements(execute_command): params = ['Action=UpdateReportAcknowledgements'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) # 获取包含认证参数的字典 params.append('Acknowledged=' + quote(execute_command['acknowledged'])) # true or false if 'request_id' in execute_command: request_id_list = execute_command['request_id'].split(',') request_list = [] for i in request_id_list: request_list.append('ReportRequestIdList.Id.' + str(request_id_list.index(i) + 1) + '=' + i) params = params + default_params + request_list params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) return result
def GetReport(execute_command): if common_unit.test_access_param(execute_command) == 0: result = common_unit.report_content else: params = ['Action=GetReport'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param( execute_command) # 获取包含认证参数的字典 if 'report_id' in execute_command: if execute_command['report_id'] != '': params.append('ReportId=' + quote(execute_command['report_id'])) params = params + default_params params = sorted( params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, execute_command['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 # print(r) # print(r.text) # print(r.content) result = common_unit.read_file(r.text) # result = common_unit.xmltojson(r.content) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def upload_product(execute_command): params = ['Action=SubmitFeed' ] + api_version + ['Timestamp=' + common_unit.get_time_stamp()] user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) # 获取包含认证参数的字典 # if execute_command['feed_method'] == params += ['FeedType=_POST_PRODUCT_DATA_'] # request_content = make_feed.feed_string request_content = make_submit_feed.make_feed_string(execute_command) request_content = bytes(request_content, 'utf-8') # print(request_content) # print(type(request_content)) # print(common_unit.get_md5(request_content)) params += [ 'ContentMD5Value=' + quote(common_unit.get_md5(request_content)).replace('/', '%2F') ] params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, request_content, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) return result
def GetFeedSubmissionResult(execute_command): params = ['Action=GetFeedSubmissionResult'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) # 获取包含认证参数的字典 # params += ['FeedTypeList.Type.1=_POST_PRODUCT_DATA_'] # params += ['FeedTypeList.Type.2=_POST_PRODUCT_PRICING_DATA_'] feed_submission_id = execute_command['submission_id'] params += ['FeedSubmissionId=' + feed_submission_id] params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) return result
def ListInventorySupply(execute_command): params = ['Action=ListInventorySupply'] + api_version + ['Timestamp=' + common_unit.get_time_stamp()] user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) # 获取包含认证参数的字典 # skuList = [] # sku_list = common_unit.get_skuList(execute_command['store_id']) # for i in sku_list: # skuList.append('SellerSkus.member.' + str(sku_list.index(i) + 1) + '=' + i) # 计算skuList列表 params.append('SellerSkus.member.1=' + quote(execute_command['sku'])) params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 params = params.replace('+',"%2B") # print(params) params = params.replace(' ',"%20") # print(params) #把你拉到和我同一水平,再用丰富的经验击败你 #空格不能自动quote,需要手动转换 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote(str(common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) signature = signature.replace('/', '%2F') # print(signature) # signature = signature.replace('=','%3D') # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) return result
def ListInventorySupplyByNextToken(execute_command): if common_unit.test_access_param(execute_command) == 0: result = common_unit.read_xmlfile( 'test_file/inventory_list_next.xml') else: params = [ 'Action=ListInventorySupplyByNextToken' ] + api_version + ['Timestamp=' + common_unit.get_time_stamp()] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param( execute_command) # 获取包含认证参数的字典 if 'next_token' in execute_command: if execute_command['next_token'] != '': params += ['NextToken=' + execute_command['next_token']] params = params + default_params params = sorted(params) params = '&'.join(params) params = params.replace('+', '%2B') params = params.replace('/', '%2F') sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, execute_command['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def CreateInboundShipmentPlan(execute_command): params = ['Action=CreateInboundShipmentPlan'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += default_params # 获取认证参数 # 把认证参数添加进请求头 params += common_unit.make_access_param(user_access_dict, execute_command) #params += ['ShipFromAddress='+execute_command['from_address']] params += ['ShipFromAddress.Name=' + execute_command['address_name']] params += [ 'ShipFromAddress.AddressLine1=' + execute_command['address_line'] ] params += ['ShipFromAddress.City=' + execute_command['address_city']] params += [ 'ShipFromAddress.CountryCode=' + execute_command['address_country'] ] #添加寄出地址 params += [ 'ShipToCountryCode=' + common_unit.country_code[execute_command['to_address_country']] ] #此处应传入一个用逗号分隔的地区代码 # CA – Canada # MX – Mexico # US – United States params += ['LabelPrepPreference=SELLER_LABEL'] params += [ 'InboundShipmentPlanRequestItems.member.1.SellerSKU=' + execute_command['seller_sku'] ] params += [ 'InboundShipmentPlanRequestItems.member.1.Quantity=' + execute_command['quantity'] ] params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序 # 拼接请求身,需要按首字母排序 # 关于api的分类和版本 params = '&'.join(params) # print(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 # print(common_unit.xmltojson(r.text)) return common_unit.xmltojson(r.text)
def ListMarketplaceParticipations(execute_command): if common_unit.test_access_param(execute_command) == 0: # result = common_unit.read_xmlfile('test_file/listmarketplace.xml') seller_id = execute_command['seller_id'] result = common_unit.xmltojson(listMarketplace) result = test_interface.test_ListMarketplaceParticipations( seller_id, result) else: params = ['Action=ListMarketplaceParticipations'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) params = params + default_params params = sorted(params) params = '&'.join(params) sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) url = connect_url(params, signature) r = requests.post(url, headers=headers) print(r.text) result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def GetMyPriceForASIN(execute_command): params = ['Action=GetMyPriceForASIN'] + api_version + ['Timestamp='+common_unit.get_time_stamp()] user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) # 获取包含认证参数的字典 # if 'asin' in execute_command: # asin_list = execute_command['asin'].split(',') # asin_param_list = [] # try: # for i in asin_list: # asin_param_list.append('ASINList.ASIN.' + str(asin_list.index(i) + 1) + '=' + i) # 计算asin列表 # except: # asin_param_list = ['ASINList.ASIN.1='] # 如果不存在asin列表,则直接返回一个空列表扔掉 # if 'asin' in execute_command: params.append('ASINList.ASIN.1=' + quote(execute_command['asin'])) else: params.append('ASINList.ASIN.1=') params = params + default_params # 上面计算的asin列表是该接口的特征参数 添加请求中包含的asin params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序 ,拼接请求身,需要按首字母排序,关于api的分类和版本 params = '&'.join(params) # 对请求身进行分割 params = params.replace('%2B', "%20") params = params.replace(' ', "%20") sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote(str(common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 signature = signature.replace('/', '%2F') url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 return common_unit.xmltojson(r.text)
def DeregisterDestination(execute_command): params = ['Action=DeregisterDestination'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) # 获取包含认证参数的字典 if 'destination' in execute_command: destination_list = execute_command['destination'].split(',') params.append('Destination.DeliveryChannel=' + str(destination_list[0])) params.append('Destination.AttributeList.member.1.Key=' + str(destination_list[1])) params.append('Destination.AttributeList.member.1.Value=' + str(destination_list[2])) params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) return result
def GetCompetitivePricingForSKU(execute_command): params = ['Action=GetCompetitivePricingForSKU']+api_version+['Timestamp='+common_unit.get_time_stamp()] user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(user_access_dict,execute_command) # 获取包含认证参数的字典 if 'sku' in execute_command: sku_list = execute_command['sku'].split(',') sku_param_list = [] #计算asin列表 try: for i in sku_list: sku_param_list.append('SellerSKUList.SellerSKU.'+str(sku_list.index(i)+1)+'='+i) except: sku_param_list = ['SellerSKUList.SellerSKU.1='] # 如果不存在asin列表,则直接返回一个空列表扔掉 # 上面计算的asin列表是该接口的特征参数 # 添加请求中包含的asin params = params + default_params + sku_param_list params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序 # 拼接请求身,需要按首字母排序 # 关于api的分类和版本 params = '&'.join(params) # 对请求身进行分割 params = params.replace('%2B', "%20") # print(params) sig_string = 'POST\n'+host_name+'\n'+port_point+'\n'+params # 连接签名字符串 signature = quote(str(common_unit.cal_signature(sig_string,user_access_dict['secret_key']))) # 计算字符串的加密签名 signature = signature.replace('/', '%2F') url = connect_url(params,signature) r = requests.post(url,headers=headers) # print(common_unit.xmltojson(r.text)) return common_unit.xmltojson(r.text)
def ListFinancialEventGroupsByNextToken(execute_command): params = [ 'Action=ListFinancialEventGroupsByNextToken' ] + api_version + ['Timestamp=' + common_unit.get_time_stamp()] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) # 获取包含认证参数的字典 if 'next_token' in execute_command: if execute_command['next_token'] != '': params += ['NextToken=' + quote(execute_command['next_token'])] params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 params = params.replace('+', '%2B') params = params.replace('/', '%2F') sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, execute_command['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def GetCompetitivePricingForASIN(execute_command): params = ['Action=GetMatchingProduct']+api_version+['Timestamp='+common_unit.get_time_stamp()] user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(user_access_dict,execute_command) # 获取包含认证参数的字典 if 'asin' in execute_command: asin_list = execute_command['asin'].split(',') asin_param_list = [] #计算asin列表 try: for i in asin_list: asin_param_list.append('ASINList.ASIN.'+str(asin_list.index(i)+1)+'='+i) except: asin_param_list = ['ASINList.ASIN.1='] # 如果不存在asin列表,则直接返回一个空列表扔掉 # 上面计算的asin列表是该接口的特征参数 # 添加请求中包含的asin params = params + default_params + asin_param_list params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序 # 拼接请求身,需要按首字母排序 # 关于api的分类和版本 params = '&'.join(params) # print(params) # 对请求身进行分割 sig_string = 'POST\n'+host_name+'\n'+port_point+'\n'+params # 连接签名字符串 signature = quote(str(common_unit.cal_signature(sig_string,user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params,signature) # 拼接请求字符串 r = requests.post(url,headers=headers) # 发起请求 # print(common_unit.xmltojson(r.text)) return common_unit.xmltojson(r.text)
def SubmitFeed(execute_command): params = ['Action=SubmitFeed'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) params += ['FeedType=_POST_PRODUCT_DATA_'] request_content = open('./amazon/submit_xml_string.txt', 'r').read() request_content = bytes(request_content, 'utf-8') # print(type(request_content)) # print(common_unit.get_md5(request_content)) params += [ 'ContentMD5Value=' + quote(common_unit.get_md5(request_content)).replace('/', '%2F') ] params = params + default_params params = sorted(params) params = '&'.join(params) sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) url = connect_url(params, signature) r = requests.post(url, request_content, headers=headers) result = common_unit.xmltojson(r.text) # print(result) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def ListOrders(execute_command): params = ['Action=ListOrders'] + api_version user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += default_params # 获取认证参数 # 把认证参数添加进请求头 params += common_unit.make_access_param(user_access_dict, execute_command) if 'fulfill' in execute_command: fulfill_list = execute_command['fulfill'].split(',') fulfill_param_list = [] try: for i in asin_list: fulfill_param_list.append('FulfillmentChannel.Channel.' + str(fulfill_list.index(i) + 1) + '=' + i) except: fulfill_param_list = [ 'FulfillmentChannel.Channel.1=AFN', 'FulfillmentChannel.Channel.2=MFN' ] params += fulfill_param_list # 添加邮寄方式 if 'last_time' in execute_command: params += ['CreatedBefore']
def GetPackageTrackingDetails(execute_command): params = ['Action=GetPackageTrackingDetails'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) if 'package_number' in execute_command: if execute_command['package_number'] != '': params.append('PackageNumber=' + quote(execute_command['package_number'])) params = params + default_params params = sorted(params) params = '&'.join(params) sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) url = connect_url(params, signature) r = requests.post(url, headers=headers) result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) if error_result != '': result = error_result return result
def ListOrderItems(execute_command): params = ['Action=ListOrderItems']+api_version+['Timestamp='+common_unit.get_time_stamp()] user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += default_params # 获取认证参数 # 把认证参数添加进请求头 params += common_unit.make_access_param(user_access_dict,execute_command) params += [str('AmazonOrderId='+execute_command['order_id'])] # 添加订单编号 # params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote(str(common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 attribute_content = common_unit.xmltojson(r.text) print(attribute_content) result = write_order_item_into_database(execute_command,attribute_content) return result
def ListMatchingProducts(execute_command): params = ['Action=ListMatchingProducts'] + api_version user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) if 'keyword' in execute_command: params.append('Query=' + quote(execute_command['keyword'])) else: params.append('Query=') # 如果不存在搜索关键词,则直接返回一个空的query # 获取特征参数query即搜索关键词 params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序 # 拼接请求身,需要按首字母排序 params = '&'.join(params) # print(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 # print(common_unit.xmltojson(r.text)) return common_unit.xmltojson(r.text)
def syn_inventory(execute_command): params = ['Action=ListInventorySupply'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) # 获取包含认证参数的字典 start_time = '1970-12-31T16:00:00' # 设置一个久远的时间开始同步库存(第一次同步店铺商品列表的库存) start_time = start_time.replace(':', '%3A') params.append('QueryStartDateTime=' + start_time) params = params + default_params # params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature(sig_string, execute_command['secret_key']))) signature = signature.replace('/', '%2F') # signature = signature.replace('=','%3D') # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result
def GetServiceStatus(execute_command): params = ['Action=GetServiceStatus'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] user_access_dict = common_unit.get_amazon_keys( execute_command['store_id']) params += common_unit.make_access_param(user_access_dict, execute_command) # 获取包含认证参数的字典 params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature(sig_string, user_access_dict['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) return result
def UpdateSubscription(execute_command): params = ['Action=UpdateSubscription'] + api_version + [ 'Timestamp=' + common_unit.get_time_stamp() ] # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id']) params += common_unit.make_access_param(execute_command) # 获取包含认证参数的字典 params.append('Subscription.NotificationType=' + execute_command['notify_type']) params.append('Subscription.IsEnabled=' + execute_command['is_enable']) params.append('Subscription.Destination.DeliveryChannel=' + execute_command['delivery_channel']) params.append('Subscription.Destination.AttributeList.member.1.Key=' + execute_command['member_key']) params.append( 'Subscription.Destination.AttributeList.member.1.Value=' + execute_command['member_value']) params = params + default_params params = sorted(params) # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序 params = '&'.join(params) # 对请求身进行分割 sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params # 连接签名字符串 signature = quote( str( common_unit.cal_signature( sig_string, execute_command['secret_key']))) # 计算字符串的加密签名 url = connect_url(params, signature) # 拼接请求字符串 r = requests.post(url, headers=headers) # 发起请求 result = common_unit.xmltojson(r.text) error_result = common_unit.catch_exception(result) # 异常处理 if error_result != '': result = error_result return result