您好,登錄后才能下訂單哦!
一、簡(jiǎn)單說(shuō)明
1、源代碼文件見附件 Credit.zip
2、關(guān)于轉(zhuǎn)賬功能,因時(shí)間問題,轉(zhuǎn)賬功能待續(xù)
4、邏輯圖
二、代碼
1、包encryption中的(password.py文件)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Created on Thu Nov 10 14:47:29 2016 密碼相關(guān)功能 @author: toby """ import hashlib, re #密碼進(jìn)行MD5加密 def md5(passwd): hashs = hashlib.md5() #創(chuàng)建MD5對(duì)象 hashs.update(passwd) #生成加密串 return hashs.hexdigest() #獲取加密串 #密碼位數(shù)檢測(cè),只能是6位數(shù)字 def check_digit(passwd): com = re.compile('^\d{6,6}$') temps = com.findall(passwd) if len(temps) == 0: return False else: return True #檢測(cè)銀行卡號(hào)位數(shù) def check_card(card): com = re.compile('^\d{16,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 卡號(hào)申請(qǐng)程序 @author: toby """ from encryption import password import shelve, random, getpass, time #申請(qǐng)資格評(píng)估 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 #生成卡號(hào) def carid(): carid = "" for i in range(16): temp = random.randint(0,9) carid += str(temp) return carid #新申請(qǐng)的用戶數(shù)據(jù)入庫(kù) def examine(key,val): data = shelve.open('data.db') data[key] = val if __name__ == "__main__": print ''' 信用卡申請(qǐng)資格評(píng)估 ''' income = input('月收入:') age = input('年齡:') #評(píng)估申請(qǐng)資格 if ssessment(income,age) == False: print '評(píng)估結(jié)果:無(wú)申請(qǐng)資格' else: print ''' 評(píng)估結(jié)果:可申請(qǐng) 請(qǐng)?zhí)顚懺敿?xì)資料 ''' name = raw_input('姓名:') card = raw_input('×××:') phone = raw_input('手機(jī):') address = raw_input('地址:') #根據(jù)條件自動(dòng)生成固定額度 fixed_amount = quota(income) #調(diào)用自動(dòng)生成額度函數(shù) #初次申請(qǐng)卡號(hào),初始記錄還款的key為0 repayment_amount = 0 #初始化還款金額,首次為0元 #自動(dòng)生成卡號(hào) kaid = carid() #調(diào)用自動(dòng)生成16位卡號(hào)函數(shù) while True: passwd1 = getpass.getpass('設(shè)置密碼:') passwd2 = getpass.getpass('確認(rèn)密碼:') if passwd1 != passwd2: print '密碼不一致' continue if password.check_digit(passwd1) == False: #檢測(cè)密碼合法性 print '只能輸入6位數(shù)字密碼' continue else: print '------卡號(hào)申請(qǐng)成功!------' print '卡號(hào)為: %s' % kaid print '可用額度: %s' % fixed_amount date = time.strftime('%Y-%m-%d %H:%M:%S') #記錄申請(qǐng)時(shí)間 repayment_time = time.strftime('%Y-%m-%d') #申請(qǐng)通過(guò)當(dāng)天日期為還款日 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) #調(diào)用數(shù)據(jù)入庫(kù)函數(shù)進(jìn)行將新申請(qǐng)的數(shù)據(jù)存入模擬數(shù)據(jù)庫(kù) break
3、login.py
# -*- coding: utf-8 -*- """ Created on Fri Nov 11 21:35:04 2016 模擬取款機(jī)登錄入口程序 @author: toby """ from encryption import password import getpass from data_function import * if __name__ == "__main__": try: while True: print ''' ------銀行系統(tǒng)登錄入口------ ''' card_number = raw_input('卡號(hào):') card_password = getpass.getpass('口令:') if password.check_card(card_number) == False: print '卡號(hào)位數(shù)不正確,請(qǐng)仔細(xì)輸入' continue if check_card_active(card_number) == False: print '對(duì)不起,該卡號(hào)不存在' continue if password.check_digit(card_password) == False: print '密碼無(wú)效' continue passwd_md5 = password.md5(card_password) #將輸入的密碼進(jìn)行加密,用于和數(shù)據(jù)庫(kù)中的md5密碼匹配 db_passwd = get_data(card_number,'passwd') #從數(shù)據(jù)庫(kù)讀取對(duì)應(yīng)卡號(hào)的密碼 if passwd_md5 != db_passwd: #輸入的密碼進(jìn)行加密后和從數(shù)據(jù)庫(kù)中讀取的MD5密碼串進(jìn)行配對(duì) print '密碼錯(cuò)誤' continue else: while True: print ''' XX銀行歡迎您 1 ----------------- 取現(xiàn) 2 ----------------- 查詢 3 ----------------- 還款 4 ----------------- 轉(zhuǎn)賬 5 ----------------- 退出 ''' main_menu = input('選擇您需要的操作(1-5):') if main_menu == 1: cash_amount = input('取款金額:') print ''' 溫馨提示:信用卡取現(xiàn)需收取5%手續(xù)費(fèi) ''' action = raw_input('是否繼續(xù)套現(xiàn)(y/n):') if action == 'y': if cash_debit(card_number,int(cash_amount)): #調(diào)用套現(xiàn)接口 print '請(qǐng)?zhí)崛‖F(xiàn)金' continue else: print '機(jī)器故障,無(wú)法提取' break if action == 'no': continue if main_menu == 2: print ''' 1 ----------------- 查詢余額 2 ----------------- 查詢明細(xì) ''' 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) #調(diào)用查詢流水函數(shù) 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 '轉(zhuǎn)賬功能正在開發(fā)' action = raw_input('是否返回主菜單(y):') if action == 'y': continue if main_menu == 5: print '柜員機(jī)系統(tǒng)已退出' break continue except Exception,e: print Exception,":::-->",e
4、data_function.py
# -*- coding: utf-8 -*- """ Created on Fri Nov 11 16:10:05 2016 數(shù)據(jù)操作相關(guān)功能 #我的卡號(hào):1098521606032848 @author: toby """ from encryption import password import shelve, getpass, time #數(shù)據(jù)庫(kù)讀取操作,這是一個(gè)全局動(dòng)作 f = shelve.open('data.db') #檢測(cè)卡號(hào)是否存在 def check_card_active(card_number): if f.get(card_number,None) != None: #判斷對(duì)應(yīng)卡號(hào)是否存在 return True else: return False #檢測(cè)對(duì)應(yīng)卡號(hào)中對(duì)應(yīng)的關(guān)鍵字?jǐn)?shù)據(jù),例如檢測(cè)對(duì)應(yīng)卡號(hào)密碼 def get_data(card,keys): data = f[card] return data[keys] #查詢對(duì)應(yīng)卡號(hào)的所有數(shù)據(jù) def get_all_data(card): data = f[card] print ''' 卡號(hào): %s 戶名: %s 固定額度: %s (人民幣) 可用余額: %s (人民幣) 需還款: %s (人民幣) 還款日: %s '''% (card,data['name'],data['fixed_amount'],data['temp_money'],data['repayment_amount'],data['repayment_time']) #扣款通用接口,正常POS機(jī)消費(fèi)或者網(wǎng)銀支付 ,無(wú)需手續(xù)費(fèi) def pos_smart_pay(card_number,card_password,price): if check_card_active(card_number) == False: print '對(duì)不起,卡號(hào)有誤!' return False passwd_md5 = password.md5(card_password) #將輸入的密碼進(jìn)行加密,用于和數(shù)據(jù)庫(kù)中的md5密碼匹配 db_passwd = get_data(card_number,'passwd') #從數(shù)據(jù)庫(kù)讀取對(duì)應(yīng)卡號(hào)的密碼 if passwd_md5 != db_passwd: print '支付密碼錯(cuò)誤' return False else: data = f[card_number] #讀取對(duì)應(yīng)卡號(hào)信息 existing = data['temp_money'] #讀取現(xiàn)有金額 if price > existing: print '對(duì)不起,余額不足' else: result = existing - price #現(xiàn)有金額減去正常消費(fèi)價(jià)格 data['temp_money'] = int(result) #臨時(shí)存儲(chǔ)計(jì)算結(jié)果 f[card_number] = data #計(jì)算結(jié)果數(shù)據(jù)入庫(kù) current_repayment_amoount = data['repayment_amount'] #讀取現(xiàn)有還款金額 res = current_repayment_amoount + price #現(xiàn)有還款金額 + 當(dāng)前消費(fèi)金額 = 需還款的金額 data['repayment_amount'] = int(res) f[card_number] = data #需還款金額數(shù)據(jù)入庫(kù) action = "POS消費(fèi)" record_water(card_number,action,price) f.close() return True #取款機(jī)取款功能 需5%手續(xù)費(fèi) def cash_debit(card_number,money): data = f[card_number] #讀取對(duì)應(yīng)卡號(hào)信息 existing = data['temp_money'] #讀取現(xiàn)有可用金額 if money > existing: print ''' 對(duì)不起,余額不足,無(wú)法套現(xiàn) 您當(dāng)前可用金額: %s ''' % existing else: repayment = money * 0.05 #套現(xiàn)時(shí)計(jì)算手續(xù)費(fèi) print ''' 取款金額: %s 手續(xù)費(fèi): %s ''' % (money, repayment) result = existing - money - repayment #現(xiàn)有金額-套現(xiàn)金額(再減去手續(xù)費(fèi)) data['temp_money'] = int(result) #臨時(shí)存儲(chǔ)計(jì)算結(jié)果 f[card_number] = data #計(jì)算結(jié)果數(shù)據(jù)入庫(kù) current_repayment_amoount = data['repayment_amount'] #讀取現(xiàn)有還款金額 temporary = current_repayment_amoount + money + (money * 0.05) #現(xiàn)有還款金額 + 當(dāng)前套現(xiàn)金額+手續(xù)費(fèi) data['repayment_amount'] = int(temporary) f[card_number] = data #需還款金額數(shù)據(jù)入庫(kù) #調(diào)用記錄流水的函數(shù)進(jìn)行記錄流水 action = "取款機(jī)套現(xiàn)" record_water(card_number,action,money) f.close() return True #通用還款接口 def repayment_interface(card_number,money): try: data = f[card_number] current_repayment_amoount = data['repayment_amount'] #讀取需還款金額 data['repayment_amount'] = current_repayment_amoount - money #需還款金額 - 傳入進(jìn)來(lái)的還款額 = 剩余還款額(全部還清后這里為0元,還多少減多少) f[card_number] = data #剩余還款額數(shù)據(jù)入庫(kù) existing = data['temp_money'] #讀取現(xiàn)有可用金額 data['temp_money'] = existing + money #現(xiàn)有可用金額 + 已傳入進(jìn)來(lái)的需還金額 (累加到可用金額,還多少就會(huì)累加多少) f[card_number] = data #還款后累加可用后的金額數(shù)據(jù)入庫(kù) action = "還款" record_water(card_number,action,money) f.close() return True except Exception,e: print Exception,":::-->",e #通用記錄流水接口 def record_water(card_number,action,money): water = shelve.open('water_data/%s.list' % card_number) date = time.strftime('%Y-%m-%d %H:%M:%S') water[date] = "行為:%s, 金額:%s" % (action,money) water.close() #通用查詢流水接口 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 模擬第三方支付 @author: toby """ import getpass from data_function import * #第三方支付接口 while True: payment_card = raw_input('支付卡號(hào):') payment_price = input('價(jià)格:') payment_password = getpass.getpass('支付密碼:') if pos_smart_pay(payment_card,payment_password,int(payment_price)) == True: print '支付完成' break else: print '支付失敗' continue
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。