def send_requests(**kwargs): url = ConfigManager.get_service(Constants.HOST.TEST) # todo 关于接口签名认证的方法可以做进一步处理如:直接去数据库查询等。 headers = { 'User-Agent': ConfigManager.get_basic(Constants.UserAgent.CHROME) } # 请求头默认带浏览器chrome 可配置 headers = headers if kwargs.get('HEADERS') is None else dict( headers, **kwargs.get('HEADERS')) # 和传入的请求头合并 # method = 'post' if kwargs.get('请求类型') is '' else kwargs.get('METHOD') method = 'post' allow_redirects = True if kwargs.get( 'allow_redirects') is None else kwargs.get( 'allow_redirects') # 是否重定向 timeout = 500 if kwargs.get('time_out') is None else kwargs.get( 'time_out') # 超时时间的设置 data = dict() format_data = kwargs.get('data') if isinstance(format_data, str): format_data = json.loads(format_data) format_data['mch_no'] = ConfigManager.get_service( Constants.Merchant.CS) format_data = json.dumps(format_data) data['data'] = format_data log.info("==============================本次请求data:::%s" % format_data) data['sign'] = RequestManager.get_sign(format_data) # 为请求增加签名认证 if method.upper().__eq__('GET'): res = requests.get( url, params=kwargs.get('params'), headers=headers, allow_redirects=allow_redirects, timeout=timeout, verify=False) # verify 由于该请求走fiddler会报错 所以关闭verify保证能抓到请求 return res, res.json() if method.upper().__eq__('POST'): res = requests.post(url, json=kwargs.get('json'), headers=headers, data=data, params=kwargs.get('params'), allow_redirects=allow_redirects, timeout=timeout, verify=False) return res, json.loads(res.json().get('data'))
class Handle(object): """ 管理所有的数据处理和预期结果 keeping_accounts: 记账handle管理 Handle_Withdrawal: 提现handle管理 """ put = ConfigManager.get_basic(Constants.PutBug.BUTTON) # 是否提交禅道bug @staticmethod def machaccnt_pay_dispatch_handle(exc_data): # 处理记账excle参数 exc_data = HandleKeepingAccounts.machaccnt_pay_dispatch_handle( exc_data) return exc_data @staticmethod def machaccnt_pay_channel_rate_common(exc_data): # 含手续费的记账 excle处理 copy_exc_data = HandleKeepingAccounts.machaccnt_pay_channel_rate_common( exc_data) return copy_exc_data @staticmethod def machaccnt_pay_dispatch_assert(self, html, excepted, mach_pay_up_obj=None, mch_ant_bef=None, mch_ant_after=None, amt_info_after=None, part=Constants.RESULT.FALSE): # 支付记账断言 HandleKeepingAccounts.machaccnt_pay_dispatch_assert( self, html, excepted, mach_pay_up_obj, mch_ant_bef, mch_ant_after, amt_info_after, part, Handle.put) @staticmethod def machaccnt_refund_dispatch_assert(self, html, excepted, mach_pay_up_obj=None, mch_ant_bef=None, mch_ant_after=None, amt_info_after=None, settled_ant_bef=None, settled_ant_aft=None, part=Constants.RESULT.FALSE): # 退款记账断言 HandleKeepingAccounts.machaccnt_refund_dispatch_assert( self, html, excepted, mach_pay_up_obj, mch_ant_bef, mch_ant_after, amt_info_after, settled_ant_bef, settled_ant_aft, part, Handle.put) @staticmethod def machaccnt_promotion_dispatch_assert(self, html, excepted, mach_pay_up_obj=None, mch_ant_bef=None, mch_ant_after=None, amt_info_after=None, settled_ant_bef=None, settled_ant_aft=None, part=Constants.RESULT.FALSE): # 活动记账断言 HandleKeepingAccounts.machaccnt_promotion_dispatch_assert( self, html, excepted, mach_pay_up_obj, mch_ant_bef, mch_ant_after, amt_info_after, settled_ant_bef, settled_ant_aft, part, Handle.put) @staticmethod def machaccnt_promotion_refund_dispatch_assert( self, html, excepted, mach_pay_up_obj=None, mch_ant_bef=None, mch_ant_after=None, amt_info_after=None, settled_ant_bef=None, settled_ant_aft=None, part=Constants.RESULT.FALSE): # 活动退款记账断言 HandleKeepingAccounts.machaccnt_promotion_refund_dispatch_assert( self, html, excepted, mach_pay_up_obj, mch_ant_bef, mch_ant_after, amt_info_after, settled_ant_bef, settled_ant_aft, part, Handle.put) @staticmethod def machaccnt_withdraw_handle(exc_data): # 处理记账excle参数 exc_data = HandleWithdrawal.machaccnt_withdraw_handle(exc_data) return exc_data @staticmethod def machaccnt_withdraw_assert(self, html, excepted, befor_dic=None, after_dic=None, part=Constants.RESULT.FALSE): # 提现断言 HandleWithdrawal.machaccnt_withdraw_assert(self, html, excepted, befor_dic, after_dic, part, Handle.put) @staticmethod def machaccnt_timer_assert(self, html, excepted, befor_tuple=None, after_tuple=None, part=Constants.RESULT.FALSE): # 提现定时器断言 HandleWithdrawal.timer_withdraw_assert(self, html, excepted, befor_tuple, after_tuple, part, Handle.put) @staticmethod def machaccnt_handle_assert(self, expect, actual): # 对账断言 HandleReconciliation.handle_assert(self, expect, actual) @staticmethod def machaccnt_settle_handle_assert(self, channel, is_change): # 结算入账断言 HandleSettle.public_handle(self, channel, is_change) @staticmethod def machaccnt_settle_end_handle_assert(self, amount_befour): # 结算入账断言 HandleSettle.remain_ant_assert(self, amount_befour)