Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
    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 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
Ejemplo n.º 11
0
    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(execute_command)  # 获取包含认证参数的字典

        params.append('Destination.DeliveryChannel=' +
                      execute_command['delivery_channel'])
        params.append('Destination.AttributeList.member.1.Key=' +
                      execute_command['member_key'])
        params.append('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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
    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
Ejemplo n.º 14
0
    def ListInventorySupply(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            # result = common_unit.read_xmlfile('test_file/inventory_list.xml')
            result = common_unit.xmltojson(str(inventory))
            result = test_interface.select_inventory_list(result)
        else:
            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)  # 获取包含认证参数的字典

            if 'sku' in execute_command:
                if execute_command['sku'] != '':
                    sku_list = execute_command['sku'].split(',')
                    sku_params_list = []
                    for i in sku_list:
                        sku_params_list.append('SellerSkus.member.' +
                                               str(sku_list.index(i) + 1) +
                                               '=' + i)
                    params += sku_params_list

            if 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    st = execute_command['start_time']
                    s_time = common_unit.conver_time(st)
                    params.append('QueryStartDateTime=' + quote(s_time))

            if 'response_group' in execute_command:
                if execute_command['response_group'] != '':
                    params.append('ResponseGroup=' +
                                  quote(execute_command['response_group']))

            params = params + default_params
            params = sorted(
                params)  # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序
            params = '&'.join(params)  # 对请求身进行分割
            params = params.replace('+', "%2B")
            params = params.replace(' ', "%20")
            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')
            # print(signature)
            # 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
Ejemplo n.º 15
0
    def CancelFeedSubmissions(execute_command):
        params = ['Action=CancelFeedSubmissions'] + 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_list' in execute_command:
            if execute_command['submission_id_list'] != '':
                id_list = execute_command['submission_id_list'].split(',')
                submission_id_list = []
                for i in id_list:
                    submission_id_list.append('FeedSubmissionIdList.Id.' +
                                              str(id_list.index(i) + 1) + '=' +
                                              i)
                params += submission_id_list

        if 'feed_type' in execute_command:
            if execute_command['feed_type'] != '':
                feed_list = execute_command['feed_type'].split(',')
                feed_type_list = []
                for i in feed_list:
                    feed_type_list.append('FeedTypeList.Type.' +
                                          str(feed_list.index(i) + 1) + '=' +
                                          i)
                params += feed_type_list

        if 'start_time' in execute_command:
            if execute_command['start_time'] != '':
                st = common_unit.conver_time(execute_command['start_time'])
                st = quote(st)
                params.append('SubmittedFromDate=' + st)

        if 'end_time' in execute_command:
            if execute_command['end_time'] != '':
                et = common_unit.conver_time(execute_command['end_time'])
                et = quote(et)
                params.append('SubmittedToDate=' + et)

        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
Ejemplo n.º 16
0
    def RequestReport(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            result = common_unit.read_xmlfile('test_file/requestReport.xml')
        else:
            params = ['Action=RequestReport'
                      ] + ['Timestamp=' + common_unit.get_time_stamp()]
            # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
            access_params = common_unit.make_access_param(execute_command)
            market_place_id = access_params[-1].split('=')[1]
            access_params += ['MarketplaceIdList.Id.1=' + market_place_id]
            params = params + access_params  # 获取包含认证参数的字典
            if 'report_type' in execute_command:
                if execute_command['report_type'] != '':
                    params.append('ReportType=' +
                                  quote(execute_command['report_type']))

            if 'start_time' in execute_command:
                s = execute_command['start_time']
                if s != '':
                    st = common_unit.conver_time(s)
                    st = quote(st)
                    params.append('StartDate=' + st)

            if 'end_time' in execute_command:
                e = execute_command['end_time']
                if e != '':
                    et = common_unit.conver_time(e)
                    et = quote(et)
                    params.append('EndDate=' + et)

            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')
            url = connect_url(params, signature)  # 拼接请求字符串
            # print(url)
            r = requests.post(url, headers=headers)  # 发起请求
            result = common_unit.xmltojson(r.text)
            # print(r.text)
            error_result = common_unit.catch_exception(result)  #异常处理
            if error_result != '':
                result = error_result
        return result
Ejemplo n.º 17
0
    def ListFinancialEvents(execute_command):
        params = ['Action=ListFinancialEvents'] + 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 'page' in execute_command:
            if execute_command['page'] != '':
                params.append('MaxResultsPerPage=' +
                              quote(execute_command['page']))  #返回结果页数

        if 'order_id' in execute_command:
            if execute_command['order_id'] != '':
                params.append('AmazonOrderId=' +
                              quote(execute_command['order_id']))  #订单编号

        if 'event_group_id' in execute_command:
            if execute_command['event_group_id'] != '':
                params.append('FinancialEventGroupId=' +
                              quote(execute_command['event_group_id']))  #事件组编号

        if 'start_time' in execute_command:
            if execute_command['start_time'] != '':
                st = common_unit.conver_time(execute_command['start_time'])
                st_timeArray = quote(st)
                params.append('PostedAfter=' + st_timeArray)  #开始时间

        if 'end_time' in execute_command:
            if execute_command['end_time'] != '':
                et = common_unit.conver_time(execute_command['end_time'])
                et_timeArray = quote(et)
                params.append('PostedBefore=' + et_timeArray)  #结束时间

        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
Ejemplo n.º 18
0
 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)
     error_result = common_unit.catch_exception(result)  # 异常处理
     if error_result != '':
         result = error_result
     return result
Ejemplo n.º 19
0
 def ListOrders(execute_command):
     if common_unit.test_access_param(execute_command) != -1:
         result = common_unit.read_xmlfile('test_file/order_list.xml')
         result = eval(result)
         test_common.get_test_order_list(execute_command, result)
     else:
         params = ['Action=ListOrders'] + 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[-1] = 'MarketplaceId.Id.1=' + params[-1].split('=')[1]
         if 'create_time' in execute_command:
             if execute_command['create_time'] != '':
                 ct = common_unit.conver_time(
                     execute_command['create_time'])
                 c_time = quote(ct)
                 params += ['CreatedAfter=' + c_time]
             else:
                 params += ['CreatedAfter=' + quote('1970-01-01T00:00:00')]
         if 'end_time' in execute_command:
             if execute_command['end_time'] != '':
                 # params += ['CreatedBefore=' + quote(execute_command['end_time'] + 'T00:00:00')]
                 et = common_unit.conver_time(execute_command['end_time'])
                 e_time = quote(et)
                 params += ['CreatedBefore=' + e_time]
             else:
                 delay = datetime.datetime.now() - datetime.timedelta(
                     days=1)
                 e_time = delay.strftime('%Y-%m-%dT%H:%M:%S')
                 params += ['CreatedBefore=' + quote(e_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'])))  # 计算字符串的加密签名
         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
Ejemplo n.º 20
0
    def CreateShipment(execute_command):
        params = ['Action=CreateShipment'] + 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 += ['HazmatType=' + execute_command['hazmat_type']]
        params += ['ShipmentId=' + execute_command['shipment_id']]
        params += ['ShippingServiceId=' + execute_command['shipment_id']]
        params += ['ShipmentRequestDetails.AmazonOrderId=' + execute_command['order_id']]
        params += ['ShipmentRequestDetails.LabelCustomization.CustomTextForLabel=' + execute_command['custom_label']]
        params += ['ShipmentRequestDetails.LabelCustomization.StandardIdForLabel=' + execute_command['stand_label']]
        params += ['ShipmentRequestDetails.MustArriveByDate=' + execute_command['must_arrive_date']]
        params += ['ShipmentRequestDetails.PackageDimensions.Length=' + execute_command['length']]
        params += ['ShipmentRequestDetails.PackageDimensions.Width=' + execute_command['width']]
        params += ['ShipmentRequestDetails.PackageDimensions.Height=' + execute_command['height']]
        params += ['ShipmentRequestDetails.PackageDimensions.Unit=' + execute_command['unit']]
        params += ['ShipmentRequestDetails.Weight.Value=' + execute_command['weight_value']]
        params += ['ShipmentRequestDetails.Weight.Unit=' + execute_command['weight_unit']]
        params += ['ShipmentRequestDetails.ShipDate=' + execute_command['ship_date']]
        params += ['ShipmentRequestDetails.ShipFromAddress.Name=' + execute_command['address_name']]
        params += ['ShipmentRequestDetails.ShipFromAddress.AddressLine1=' + execute_command['address_line']]
        params += ['ShipmentRequestDetails.ShipFromAddress.City=' + execute_command['address_city']]
        params += ['ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode=' + execute_command['state_or_province']]
        params += ['ShipmentRequestDetails.ShipFromAddress.PostalCode=' + execute_command['post_code']]
        params += ['ShipmentRequestDetails.ShipFromAddress.CountryCode=' + execute_command['country_code']]
        params += ['ShipmentRequestDetails.ShipFromAddress.Email=' + execute_command['email']]
        params += ['ShipmentRequestDetails.ShipFromAddress.Phone=' + execute_command['phone']]
        params += ['ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience=' + execute_command['experience']]
        params += ['ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp=' + execute_command['pick_up']]
        params += ['ShipmentRequestDetails.ShippingServiceOptions.DeclaredValue.CurrencyCode=' + execute_command['currency_code']]
        params += ['ShipmentRequestDetails.ShippingServiceOptions.DeclaredValue.Amount=' + execute_command['amount']]
        params += ['ShipmentRequestDetails.ShippingServiceOptions.LabelFormat=' + execute_command['label_format']]
        params += ['ShipmentRequestDetails.ItemList.Item.1.OrderItemId=' + execute_command['order_item_id']]
        params += ['ShipmentRequestDetails.ItemList.Item.1.Quantity=' + execute_command['quantity']]

        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)
        error_result = common_unit.catch_exception(result)  # 异常处理
        if error_result != '':
            result = error_result
        return result
Ejemplo n.º 21
0
 def ListAllFulfillmentOrdersByNextToken(execute_command):
     if common_unit.test_access_param(execute_command) == 0:
         result = common_unit.read_xmlfile(
             'test_file/listAllfulfillmentorderbynextToken.xml')
         # result = common_unit.xmljson(listAllfulfillmentOrders)
         # result = test_interface.select_inboundlist_between_time(result)
     else:
         r = ''
         if 'next_token' in execute_command:
             if execute_command['next_token'] != '':
                 ntoken = execute_command['next_token']
                 params = 'Action=ListAllFulfillmentOrdersByNextToken&NextToken=' + ntoken
                 url = 'https://' + host_name + port_point + '?' + params
                 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
Ejemplo n.º 22
0
    def ListAllFulfillmentOrders(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            # result = common_unit.xmltojson(listAllfulfillmentOrder)
            # result = common_unit.read_xmlfile('test_file/listAllfulfillmentorder.xml')

            if 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    start_time = execute_command['start_time']
                    start_date, time_stamp = common_unit.conver_date_time(
                        start_time)
                    # print(start_time,time_stamp)
                    result = common_unit.xmltojson(listAllfulfillmentOrder)
                    result = test_interface.listAllfulfillmentOrders_between_time(
                        start_date, result)

        else:
            params = ['Action=ListAllFulfillmentOrders'] + 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 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    st = execute_command['start_time']
                    st = common_unit.conver_time(st)
                    params.append('QueryStartDateTime=' + quote(st))
            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
Ejemplo n.º 23
0
 def GetOrder(execute_command):
     if common_unit.test_access_param(execute_command) != -1:
         result = common_unit.read_xmlfile('test_file/get_order.xml')
         result = eval(result)
         test_common.get_test_order(execute_command, result)
     else:
         params = ['Action=GetOrder'] + 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 'order_id' in execute_command:
             if execute_command['order_id'] != '':
                 order_id_list = execute_command['order_id'].split(',')
                 order_param_list = []
                 for i in order_id_list:
                     order_param_list.append(
                         'AmazonOrderId.Id.' +
                         str(order_id_list.index(i) + 1) + '=' + i)
                 params += order_param_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
Ejemplo n.º 24
0
    def ListOrderItems(execute_command):
        if common_unit.test_access_param(execute_command) != -1:
            result = common_unit.read_xmlfile('test_file/order_item_list.xml')
            result = eval(result)
            test_common.get_test_orderitem_list(execute_command, result)
        else:
            params = ['Action=ListOrderItems'] + 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 'order_id' in execute_command:
                if execute_command['order_id'] != '':
                    params += [
                        str('AmazonOrderId=' +
                            quote(execute_command['order_id']))
                    ]
            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)
            # print(attribute_content)
            # print(type(attribute_content))
            # result = write_order_item_into_database(execute_command,attribute_content)
            error_result = common_unit.catch_exception(result)  # 异常处理
            if error_result != '':
                result = error_result
        return result
Ejemplo n.º 25
0
 def GetFulfillmentOrder(execute_command):
     if common_unit.test_access_param(execute_command) == 0:
         # result = common_unit.read_xmlfile('test_file/getfulfillmentorder.xml')
         if 'fulfillment_order_id' in execute_command:
             if execute_command['fulfillment_order_id'] != '':
                 fulfillment_order_id = execute_command[
                     'fulfillment_order_id']
                 result = common_unit.xmltojson(getfulfillmentOrder)
                 result = test_interface.getFulfillmentOrder(
                     fulfillment_order_id, result)
     else:
         params = ['Action=GetFulfillmentOrder'] + 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']))
         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
Ejemplo n.º 26
0
    def CreateFulfillmentReturn(execute_command):
        params = ['Action=CreateFulfillmentReturn'] + 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 'return_item_id' in execute_command:
            if execute_command['return_item_id'] != '':
                return_item_list = execute_command['return_item_id'].split(',')
                return_param_list = []
                for i in return_item_list:
                    return_param_list.append(
                        'Items.member.' + str(return_item_list.index(i) + 1) +
                        '.SellerReturnItemId=' + i)
                params += return_param_list

        if 'order_item_id' in execute_command:
            if execute_command['order_item_id'] != '':
                order_item_list = execute_command['order_item_id'].split(',')
                order_param_list = []
                for i in order_item_list:
                    order_param_list.append('Items.member.' +
                                            str(order_item_list.index(i) + 1) +
                                            '.SellerFulfillmentOrderItemId=' +
                                            i)
                params += order_param_list

        if 'shipment_id' in execute_command:
            if execute_command['shipment_id'] != '':
                ship_id_list = execute_command['shipment_id'].split(',')
                ship_param_list = []
                for i in ship_id_list:
                    ship_param_list.append('Items.member.' +
                                           str(ship_id_list.index(i) + 1) +
                                           '.AmazonShipmentId=' + i)
                params += ship_param_list

        if 'reason_code' in execute_command:
            if execute_command['reason_code'] != '':
                reason_code_list = execute_command['reason_code'].split(',')
                reason_code_param_list = []
                for i in reason_code_list:
                    reason_code_param_list.append(
                        'Items.member.' + str(reason_code_list.index(i) + 1) +
                        '.ReturnReasonCode=' + i)
                params += reason_code_param_list

        if 'comment' in execute_command:
            if execute_command['comment'] != '':
                comment_list = execute_command['comment'].split(',')
                comment_param_list = []
                for i in comment_list:
                    comment_param_list.append('Items.member.' +
                                              str(comment_list.index(i) + 1) +
                                              '.ReturnComment=' + i)
                params += comment_param_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
Ejemplo n.º 27
0
    def GetReportRequestList(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            result = common_unit.read_xmlfile(
                'test_file/getReportRequestList.xml')
        else:
            params = ['Action=GetReportRequestList'] + 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_request_id' in execute_command:
                if execute_command['report_request_id'] != '':
                    request_id_list = execute_command[
                        'report_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 += request_list

            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

            if 'process_status' in execute_command:
                if execute_command['process_status'] != '':
                    process_status_list = execute_command[
                        'process_status'].split(',')
                    process_list = []
                    for i in process_status_list:
                        process_list.append(
                            'ReportProcessingStatusList.Status.' +
                            str(process_status_list.index(i) + 1) + '=' + i)
                    params += process_list

            if 'max_count' in execute_command:
                if execute_command['max_count'] != '':
                    params.append('MaxCount=' +
                                  quote(execute_command['max_count']))

            if 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    st = common_unit.conver_time(execute_command['start_time'])
                    st = quote(st)
                    params.append('RequestedFromDate=' + st)  #开始时间

            if 'end_time' in execute_command:
                if execute_command['end_time'] != '':
                    et = common_unit.conver_time(execute_command['end_time'])
                    et = quote(et)
                    params.append('RequestedToDate=' + et)  #结束时间

            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)
            # print(r.text)
            error_result = common_unit.catch_exception(result)  # 异常处理
            if error_result != '':
                result = error_result

        return result
Ejemplo n.º 28
0
    def UpdateFulfillmentOrder(execute_command):
        params = ['Action=UpdateFulfillmentOrder'] + 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 'fulfillment_action' in execute_command:
            if execute_command['fulfillment_action'] != '':
                params.append('FulfillmentAction=' +
                              quote(execute_command['fulfillment_action']))
        if 'display_order_id' in execute_command:
            if execute_command['display_order_id'] != '':
                params.append('DisplayableOrderId=' +
                              quote(execute_command['display_order_id']))
        if 'display_order_datetime' in execute_command:
            if execute_command['display_order_datetime'] != '':
                order_datetime = execute_command['display_order_datetime']
                order_datetime = common_unit.conver_time(order_datetime)
                params.append('DisplayableOrderDateTime=' +
                              quote(order_datetime))
        if 'display_order_comment' in execute_command:
            if execute_command['display_order_comment'] != '':
                params.append('DisplayableOrderComment=' +
                              quote(execute_command['display_order_comment']))
        if 'ship_speed_category' in execute_command:
            if execute_command['ship_speed_category'] != '':
                params.append('ShippingSpeedCategory=' +
                              quote(execute_command['ship_speed_category']))
        if 'address_name' in execute_command:
            if execute_command['address_name'] != '':
                params.append('DestinationAddress.Name=' +
                              quote(execute_command['address_name']))
        if 'address_line1' in execute_command:
            if execute_command['address_line1'] != '':
                params.append('DestinationAddress.Line1=' +
                              quote(execute_command['address_line1']))
        if 'address_line2' in execute_command:
            if execute_command['address_line2'] != '':
                params.append('DestinationAddress.Line2=' +
                              quote(execute_command['address_line2']))
        if 'address_line3' in execute_command:
            if execute_command['address_line3'] != '':
                params.append('DestinationAddress.Line2=' +
                              quote(execute_command['address_line3']))
        if 'district_or_country' in execute_command:
            if execute_command['district_or_country'] != '':
                params.append('DestinationAddress.DistrictOrCounty=' +
                              quote(execute_command['district_or_country']))
        if 'address_city' in execute_command:
            if execute_command['address_city'] != '':
                params.append('DestinationAddress.City=' +
                              execute_command['address_city'])
        if 'country_code' in execute_command:
            if execute_command['country_code'] != '':
                params.append('DestinationAddress.CountryCode=' +
                              quote(execute_command['country_code']))
        if 'state_or_province' in execute_command:
            if execute_command['state_or_province'] != '':
                params.append('DestinationAddress.StateOrProvinceCode=' +
                              quote(execute_command['state_province_code']))
        if 'post_code' in execute_command:
            if execute_command['post_code'] != '':
                params.append('DestinationAddress.PostalCode=' +
                              quote(execute_command['post_code']))
        if 'phone_number' in execute_command:
            if execute_command['phone_number'] != '':
                params.append('DestinationAddress.PhoneNumber=' +
                              quote(execute_command['phone_number']))
        if 'fulfillment_policy' in execute_command:
            if execute_command['fulfillment_policy'] != '':
                params.append('FulfillmentPolicy=' +
                              quote(execute_command['fulfillment_policy']))
        if 'notific_email_list' in execute_command:
            if execute_command['notific_email_list'] != '':
                email_list = execute_command['notific_email_list'].split(',')
                email_param_list = []
                for q in email_list:
                    email_param_list.append('NotificationEmailList.member.' +
                                            str(email_list.index(q) + 1) +
                                            '=' + q)
                params += email_param_list
        if 'sku' in execute_command:
            if execute_command['sku'] != '':
                sku_list = execute_command['sku'].split(',')
                sku_param_list = []
                for i in sku_list:
                    sku_param_list.append('Items.member.' +
                                          str(sku_list.index(i) + 1) + '=' + i)
                params += sku_param_list

        if 'order_item_id' in execute_command:
            if execute_command['order_item_id'] != '':
                sku_list = execute_command['order_item_id'].split(',')
                sku_param_list = []
                for i in sku_list:
                    sku_param_list.append('Items.member.' +
                                          str(sku_list.index(i) + 1) + '=' + i)
                params += sku_param_list

        if 'quantity' in execute_command:
            if execute_command['quantity'] != '':
                quantity_list = execute_command['quantity'].split(',')
                quantity_param_list = []
                for q in quantity_list:
                    quantity_param_list.append('Items.member.' +
                                               str(quantity_list.index(q) +
                                                   1) + '=' + q)
                params += quantity_param_list
        # params.append('Items.member.1.SellerSKU=' + quote(execute_command['sku']))
        # params.append('Items.member.1.SellerFulfillmentOrderItemId=' + quote(execute_command['order_item_id']))
        # params.append('Items.member.1.Quantity=' + quote(execute_command['quantity']))
        # params.append('Items.member.1.GiftMessage=' + quote(execute_command['gift_message']))
        # params.append('Items.member.1.DisplayableComment=' + quote(execute_command['dispaly_comment']))
        # params.append('Items.member.1.FulfillmentNetworkSKU=' + quote(execute_command['network_sku']))
        # params.append('Items.member.1.PerUnitDeclaredValue.CurrencyCode=' + quote(execute_command['puv_currency_code']))
        # params.append('Items.member.1.PerUnitDeclaredValue.Value=' + quote(execute_command['puv_value']))
        # params.append('Items.member.1.PerUnitPrice.CurrencyCode=' + quote(execute_command['pup_currency_code']))
        # params.append('Items.member.1.PerUnitPrice.Value=' + quote(execute_command['pup_value']))
        # params.append('Items.member.1.PerUnitTax.CurrencyCode=' + quote(execute_command['put_currency_code']))
        # params.append('Items.member.1.PerUnitTax.Value=' + quote(execute_command['put_value']))

        params = params + default_params
        params = sorted(params)
        params = '&'.join(params)
        params = params.replace('+', '%2B')
        params = params.replace('/', '%2F')
        print(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('+', '%2B').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
Ejemplo n.º 29
0
    def GetFulfillmentPreview(execute_command):
        params = ['Action=GetFulfillmentPreview'] + 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 'address_name' in execute_command:
            if execute_command['address_name'] != '':
                params.append('Address.Name=' +
                              execute_command['address_name'])
        if 'address_line1' in execute_command:
            if execute_command['address_line1'] != '':
                params.append('Address.Line1=' +
                              execute_command['address_line1'])

        if 'address_line2' in execute_command:
            if execute_command['address_line2'] != '':
                params.append('Address.Line2=' +
                              execute_command['address_line2'])
        if 'address_line3' in execute_command:
            if execute_command['address_line3'] != '':
                params.append('Address.Line3=' +
                              execute_command['address_line3'])
        if 'state_or_province' in execute_command:
            if execute_command['state_or_province'] != '':
                params.append('Address.StateOrProvinceCode=' +
                              execute_command['state_or_province'])
        if 'post_code' in execute_command:
            if execute_command['post_code'] != '':
                params.append('Address.PostalCode=' +
                              execute_command['post_code'])
        if 'country_code' in execute_command:
            if execute_command['country_code'] != '':
                params.append('Address.CountryCode=' +
                              execute_command['country_code'])
        if 'address_city' in execute_command:
            if execute_command['address_city'] != '':
                params.append('Address.City=' +
                              execute_command['address_city'])

        if 'quantity' in execute_command:
            if execute_command['quantity'] != '':
                quantity_list = execute_command['quantity'].split(',')
                quantity_param_list = []
                for q in quantity_list:
                    quantity_param_list.append('Items.member.' +
                                               str(quantity_list.index(q) +
                                                   1) + '.Quantity=' + q)
                params += quantity_param_list

        if 'order_item_id' in execute_command:
            if execute_command['order_item_id'] != '':
                order_item_list = execute_command['order_item_id'].split(',')
                order_param_list = []
                for i in order_item_list:
                    order_param_list.append('Items.member.' +
                                            str(order_item_list.index(i) + 1) +
                                            '.SellerFulfillmentOrderItemId=' +
                                            i)
                params += order_param_list

        if 'sku' in execute_command:
            if execute_command['sku'] != '':
                sku_list = execute_command['sku'].split(',')
                sku_param_list = []
                for i in sku_list:
                    sku_param_list.append('Items.member.' +
                                          str(sku_list.index(i) + 1) +
                                          '.SellerSKU=' + i)
                params += sku_param_list

        if 'ship_speed_category' in execute_command:
            if execute_command['ship_speed_category'] != '':
                categry_list = execute_command['ship_speed_category'].split(
                    ',')
                category_param_list = []
                for i in categry_list:
                    category_param_list.append('ShippingSpeedCategories.' +
                                               str(categry_list.index(i) + 1) +
                                               '=' + i)
                params += category_param_list

        if 'fulfillment_preview' in execute_command:
            if execute_command['fulfillment_preview'] != '':
                params.append('IncludeCODFulfillmentPreview=' +
                              execute_command['fulfillment_preview'])

        if 'delivery_windows' in execute_command:
            if execute_command['delivery_windows'] != '':
                params.append('IncludeDeliveryWindows=' +
                              execute_command['delivery_windows'])

        params = params + default_params
        params = sorted(params)
        params = '&'.join(params)
        params = params.replace('+', '%2B')
        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,
                                          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