Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python's simple simulation banking system function (card number application, repayment, payment, cash withdrawal)

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

First, a brief explanation

1. For source code files, please see attachment Credit.zip.

2. With regard to the transfer function, due to the time problem, the transfer function will be continued.

4. Logical diagram

II. Code

1. (password.py file) in the package encryption

#! / usr/bin/env python#-*-coding: utf-8-*-"Created on Thu Nov 10 14:47:29 2016 password related functions @ author: toby"import hashlib, re# password MD5 encryption def md5 (passwd): hashs = hashlib.md5 () # create MD5 object hashs.update (passwd) # generate encryption string return hashs.hexdigest () # get encryption string # password digit detection Can only be 6 digits def check_digit (passwd): com = re.compile ('^\ d {6 passwd 6} $') temps = com.findall (passwd) if len (temps) = 0: return False else: return True# check bank card number def check_card (card): com = re.compile ('^\ d {16cr 16} $') temps = com.findall (card) if len (temps) = 0: return False else: return True

2 、 applys.py

#! / usr/bin/env python#-*-coding: utf-8-*-"" Created on Thu Nov 10 14:42:29 2016 Card number Application procedure @ author: toby "" from encryption import passwordimport shelve, random, getpass, time# eligibility Assessment def ssessment (income,age): if income > = 3000 and age > = 22 and age

< 60: return True else: return False #确定额度def quota(money): if money >

3000 and money

< 6000: return 5000 if money >

6000 and money

< 10000: return 10000 if money >

10000 and money

< 20000: return 15000#生成卡号def carid(): carid = "" for i in range(16): temp = random.randint(0,9) carid += str(temp) return carid#新申请的用户数据入库def examine(key,val): data = shelve.open('data.db') data[key] = valif __name__ == "__main__": print ''' 信用卡申请资格评估 ''' income = input('月收入:') age = input('年龄:') #评估申请资格 if ssessment(income,age) == False: print '评估结果:无申请资格' else: print ''' 评估结果:可申请 请填写详细资料 ''' name = raw_input('姓名:') card = raw_input('×××:') phone = raw_input('手机:') address = raw_input('地址:') #根据条件自动生成固定额度 fixed_amount = quota(income) #调用自动生成额度函数 #初次申请卡号,初始记录还款的key为0 repayment_amount = 0 #初始化还款金额,首次为0元 #自动生成卡号 kaid = carid() #调用自动生成16位卡号函数 while True: passwd1 = getpass.getpass('设置密码:') passwd2 = getpass.getpass('确认密码:') if passwd1 != passwd2: print '密码不一致' continue if password.check_digit(passwd1) == False: #检测密码合法性 print '只能输入6位数字密码' continue else: print '------卡号申请成功!------' print '卡号为: %s' % kaid print '可用额度: %s' % fixed_amount date = time.strftime('%Y-%m-%d %H:%M:%S') #记录申请时间 repayment_time = time.strftime('%Y-%m-%d') #申请通过当天日期为还款日 passwd_data = password.md5(passwd1) #密码使用MD5加密 temp = {'date':date,'name':name,'age':age,'income':income,'card':card,'phone':phone,'address':address,'passwd':passwd_data,'fixed_amount':fixed_amount,'temp_money':int(fixed_amount),'repayment_amount':repayment_amount,'repayment_time':repayment_time} examine(kaid,temp) #调用数据入库函数进行将新申请的数据存入模拟数据库 break 3、login.py # -*- coding: utf-8 -*-"""Created on Fri Nov 11 21:35:04 2016模拟取款机登录入口程序@author: toby"""from encryption import passwordimport getpassfrom data_function import *if __name__ == "__main__": try: while True: print ''' ------银行系统登录入口------ ''' card_number = raw_input('卡号:') card_password = getpass.getpass('口令:') if password.check_card(card_number) == False: print '卡号位数不正确,请仔细输入' continue if check_card_active(card_number) == False: print '对不起,该卡号不存在' continue if password.check_digit(card_password) == False: print '密码无效' continue passwd_md5 = password.md5(card_password) #将输入的密码进行加密,用于和数据库中的md5密码匹配 db_passwd = get_data(card_number,'passwd') #从数据库读取对应卡号的密码 if passwd_md5 != db_passwd: #输入的密码进行加密后和从数据库中读取的MD5密码串进行配对 print '密码错误' continue else: while True: print ''' XX银行欢迎您 1 ----------------- 取现 2 ----------------- 查询 3 ----------------- 还款 4 ----------------- 转账 5 ----------------- 退出 ''' main_menu = input('选择您需要的操作(1-5):') if main_menu == 1: cash_amount = input('取款金额:') print ''' 温馨提示:信用卡取现需收取5%手续费 ''' action = raw_input('是否继续套现(y/n):') if action == 'y': if cash_debit(card_number,int(cash_amount)): #调用套现接口 print '请提取现金' continue else: print '机器故障,无法提取' break if action == 'no': continue if main_menu == 2: print ''' 1 ----------------- 查询余额 2 ----------------- 查询明细 ''' sub_menu = input('选择您需要的操作(1-2):') if sub_menu == 1: get_all_data(card_number) action = raw_input('是否返回主菜单(y):') if action == 'y': continue if sub_menu == 2: get_water(card_number) #调用查询流水函数 action = raw_input('是否返回主菜单(y):') if action == 'y': continue if main_menu == 3: temp_money = get_data(card_number,'temp_money') #读取可用金额 repayment_amount = get_data(card_number,'repayment_amount') #读取需还款金额 print ''' 可用余额: %s (人民币) 您需还款: %s (人民币) ''' % (temp_money,repayment_amount) money = input('还款金额:') if repayment_interface(card_number,int(money)) == True: print '还款成功' else: print '还款失败' action = raw_input('是否返回主菜单(y):') if action == 'y': continue if main_menu == 4: print '转账功能正在开发' action = raw_input('是否返回主菜单(y):') if action == 'y': continue if main_menu == 5: print '柜员机系统已退出' break continue except Exception,e: print Exception,":::-->

", e

4 、 data_function.py

#-*-coding: utf-8-*-"" Created on Fri Nov 11 16:10:05 2016 data operation related functions # my card number: 1098521606032848@author: toby "" from encryption import passwordimport shelve, getpass, time# database read operation This is a global action f = shelve.open ('data.db') # detect whether the card number exists def check_card_active (card_number): if f.get (card_number,None)! = None: # determine whether the corresponding card number exists return True else: return False# detect the corresponding keyword data in the corresponding card number For example, check the corresponding card number password def get_data (card) Keys): data = f [card] return data [keys] # query all data of the corresponding card number def get_all_data (card): data = f [card] print''Card number:% s account name:% s fixed amount:% s (RMB) available balance:% s (RMB) repayment:% s (RMB) repayment date: % s''% (card Data ['name'], data [' fixed_amount'], data ['temp_money'], data [' repayment_amount'], data ['repayment_time']) # Universal API for debit For normal POS consumption or online bank payment, there is no handling fee def pos_smart_pay (card_number,card_password,price): if check_card_active (card_number) = = False: print 'Sorry, the card number is wrong!' Return False passwd_md5 = password.md5 (card_password) # encrypts the password entered Used to match the md5 password in the database db_passwd = get_data (card_number 'passwd') # read the password of the corresponding card number from the database if passwd_md5! = db_passwd: print' payment password error 'return False else: data = f [card _ number] # read the corresponding card number information existing = data [' temp_money'] # read the existing amount if price > existing: print 'sorry Insufficient balance 'else: result = existing-price # existing amount minus normal consumer price data [' temp_money'] = int (result) # temporary storage calculation result f [card _ number] = data # calculation result current_repayment_amoount = data ['repayment_amount'] # read the existing repayment amount Res = current_repayment_amoount + price # existing repayment amount + current consumption amount = amount to be repaid data ['repayment_amount'] = int (res) f [card _ number] = data # data to be repaid action = "POS consumption" record_water (card_number Action,price) f.close () return True# cash machine def cash_debit (card_number,money): data = f [card _ number] # read the corresponding card number information existing = data ['temp_money'] # read the available amount if money > existing: print' 'Sorry Sorry, your credit is running low, Unable to cash out your current available amount:% s''% existing else: repayment = money * 0.05# currently calculated handling fee print''withdrawal amount:% s handling fee:% s''% (money Repayment) result = existing-money-repayment # existing amount-cash amount (minus handling fee) data ['temp_money'] = int (result) # temporary storage calculation result f [card _ number] = data # calculation result data into the database current_repayment_amoount = data [' repayment_amount'] # read the existing repayment amount temporary = current_repayment_amoount + money + (money * 0.05) # existing repayment amount + current cash amount + handling fee data ['repayment_amount'] = int (temporary) f [card _ number] = data # data on the amount to be repaid into the database # call the function to record the flow action = "cash machine cash" record_water (card_number Action,money) f.close () return True# Universal repayment Interface def repayment_interface (card_number Money): try: data = f [card _ number] current_repayment_amoount = data ['repayment_amount'] # read the amount to be repaid data [' repayment_amount'] = current_repayment_amoount-money # amount to be repaid-incoming repayment amount = remaining repayment amount (0 yuan here after full repayment How much less) f [card _ number] = data # remaining repayment data existing = data ['temp_money'] # read the existing available amount data [' temp_money'] = existing + money # existing available amount + incoming repayment amount (accumulated to available amount F [card _ number] = data # accumulated amount data after repayment action = "repayment" record_water (card_number,action,money) f.close () return True except Exception,e: print Exception, "::-- >", e# general recording pipeline interface def record_water (card_number,action Money): water = shelve.open ('water_data/%s.list'% card_number) date = time.strftime ('% Y-%m-%d% H15% MRV% S') water [date] = "behavior:% s, amount:% s"% (action) Money) water.close () # General query pipeline API def get_water (card_number): water = shelve.open ('water_data/%s.list'% card_number) for val in water: print val, water [val]

5 、 payment_interface.py

#-*-coding: utf-8-*-"Created on Sat Nov 12 13:47:03 2016 simulates third party payment @ author: toby" import getpassfrom data_function import * # third party payment interface while True: payment_card = raw_input ('payment card number:') payment_price = input ('price:') payment_password = getpass.getpass ('payment password:') if pos_smart_pay (payment_card,payment_password Int (payment_price)) = = True: print 'payment completed' break else: print 'payment failed' continue

Attachment: http://down.51cto.com/data/2368377

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report