def pay(self, channel, total_fee, bill_no, title, return_url = None, optional = None, show_url = None, qr_pay_mode = None, openid = None): pay_data = {} if not self.bc_app_id or not self.bc_app_secret : return self.param_miss('bc_app_id, bc_app_secret') if not channel: return self.param_miss('channel') if not total_fee: return self.param_miss('total_fee') if not bill_no: return self.param_miss('bill_no') if channel == 'WX_JSAPI' and not openid: return self.param_miss('openid') if not channel in self.pay_channels: return self.param_invalid('channel', '应该在' + str(self.pay_channels) + '中') if not isinstance(total_fee, int) or total_fee < 0: return self.param_invalid('total_fee', 'total_fee以分为单位,为正整数') # if len(title) > 32: # return self.param_invalid('title', '32个字节内') if len(bill_no) > 32: return self.param_invalid('bill_no', '32个字节内') if not re.match('^[0-9a-zA-Z]+$', bill_no): return self.param_invalid('bill_no', '只能字母数字组合') pay_data['channel'] = channel pay_data['app_id'] = self.bc_app_id timestamp = long(time.time()) * 1000 pay_data['timestamp'] = timestamp pay_data['app_sign'] = self.bc_sign(timestamp) pay_data['total_fee'] = total_fee pay_data['title'] = title pay_data['bill_no'] = bill_no if channel == 'WX_JSAPI' and openid: pay_data['openid'] = openid if return_url: pay_data['return_url'] = return_url if optional: pay_data['optional'] = optional if channel == 'ALI_WEB' and show_url: pay_data['show_url'] = show_url if channel == 'ALI_QRCODE' and qr_pay_mode: pay_data['qr_pay_mode'] = qr_pay_mode return httpPost(self.random_server() + '/' + self.api_version + '/' + self.pay_url, pay_data)
def refund(self, refund_fee, refund_no, bill_no, channel=None, optional=None): pay_data = {} if not self.bc_app_id or not self.bc_app_secret: return self.param_miss('bc_app_id, bc_app_secret') if not refund_fee: return self.param_miss('refund_fee') if not refund_no: return self.param_miss('refund_no') if channel and not channel in self.refund_channels: return self.param_invalid('channel', '应该在' + str(self.refund_channels) + '中') if int(refund_fee) < 0: return self.param_invalid('refund_fee', 'refund_fee以分为单位,为正整数') now = datetime.now() date = now.strftime("%Y%m%d") if len(refund_no) > 32 or not refund_no.startswith( str(date)) or not re.match('^[0-9a-zA-Z]+$', refund_no): return self.param_invalid( 'refund_no', '32个字节内, 8位日期开头加24为流水号, 流水号字母数字组合,流水号不能为000') if len(bill_no) > 32: return self.param_invalid('bill_no', '32个字节内') if not re.match('^[0-9a-zA-Z]+$', bill_no): return self.param_invalid('bill_no', '只能字母数字组合') pay_data = {} if channel: pay_data['channel'] = channel pay_data['app_id'] = self.bc_app_id timestamp = long(time.time()) * 1000 pay_data['timestamp'] = timestamp pay_data['app_sign'] = self.bc_sign(timestamp) pay_data['refund_fee'] = int(refund_fee) pay_data['refund_no'] = refund_no pay_data['bill_no'] = bill_no if optional: pay_data['optional'] = optional return httpPost( self.random_server() + '/' + self.api_version + '/' + self.refund_url, pay_data)
def refund(self, refund_fee, refund_no, bill_no, channel = None, optional = None): pay_data = {} if not self.bc_app_id or not self.bc_app_secret : return self.param_miss('bc_app_id, bc_app_secret') if not refund_fee: return self.param_miss('refund_fee') if not refund_no: return self.param_miss('refund_no') if channel and not channel in self.refund_channels: return self.param_invalid('channel', '应该在' + str(self.refund_channels) + '中') if int(refund_fee) < 0: return self.param_invalid('refund_fee', 'refund_fee以分为单位,为正整数') now = datetime.now() date = now.strftime("%Y%m%d") if len(refund_no) > 32 or not refund_no.startswith(str(date)) or not re.match('^[0-9a-zA-Z]+$', refund_no): return self.param_invalid('refund_no', '32个字节内, 8位日期开头加24为流水号, 流水号字母数字组合,流水号不能为000') if len(bill_no) > 32: return self.param_invalid('bill_no', '32个字节内') if not re.match('^[0-9a-zA-Z]+$', bill_no): return self.param_invalid('bill_no', '只能字母数字组合') pay_data = {} if channel: pay_data['channel'] = channel pay_data['app_id'] = self.bc_app_id timestamp = long(time.time()) * 1000 pay_data['timestamp'] = timestamp pay_data['app_sign'] = self.bc_sign(timestamp) pay_data['refund_fee'] = int(refund_fee) pay_data['refund_no'] = refund_no pay_data['bill_no'] = bill_no if optional: pay_data['optional'] = optional return httpPost(self.random_server() + '/' + self.api_version + '/' + self.refund_url, pay_data)
def pay(self, channel, total_fee, bill_no, title, return_url=None, optional=None, show_url=None, qr_pay_mode=None, openid=None, bill_timeout=None): pay_data = {} if not self.bc_app_id or not self.bc_app_secret: return self.param_miss('bc_app_id, bc_app_secret') if not channel: return self.param_miss('channel') if not total_fee: return self.param_miss('total_fee') if not bill_no: return self.param_miss('bill_no') if channel == 'WX_JSAPI' and not openid: return self.param_miss('openid') if not channel in self.pay_channels: return self.param_invalid('channel', '应该在' + str(self.pay_channels) + '中') if not isinstance(total_fee, int) or total_fee < 0: return self.param_invalid('total_fee', 'total_fee以分为单位,为正整数') # if len(title) > 32: # return self.param_invalid('title', '32个字节内') if len(bill_no) > 32: return self.param_invalid('bill_no', '32个字节内') if not re.match('^[0-9a-zA-Z]+$', bill_no): return self.param_invalid('bill_no', '只能字母数字组合') pay_data['channel'] = channel pay_data['app_id'] = self.bc_app_id timestamp = long(time.time()) * 1000 pay_data['timestamp'] = timestamp pay_data['app_sign'] = self.bc_sign(timestamp) pay_data['total_fee'] = total_fee pay_data['title'] = title pay_data['bill_no'] = bill_no if channel == 'WX_JSAPI' and openid: pay_data['openid'] = openid if return_url: pay_data['return_url'] = return_url if optional: pay_data['optional'] = optional if channel == 'ALI_WEB' and show_url: pay_data['show_url'] = show_url if channel == 'ALI_QRCODE' and qr_pay_mode: pay_data['qr_pay_mode'] = qr_pay_mode if bill_timeout: pay_data['bill_timeout'] = bill_timeout return httpPost( self.random_server() + '/' + self.api_version + '/' + self.pay_url, pay_data)