您好,登錄后才能下訂單哦!
一、簡單說明
1、源代碼文件見附件 Credit.zip
2、關于轉賬功能,因時間問題,轉賬功能待續
4、邏輯圖
二、代碼
1、包encryption中的(password.py文件)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Created on Thu Nov 10 14:47:29 2016 密碼相關功能 @author: toby """ import hashlib, re #密碼進行MD5加密 def md5(passwd): hashs = hashlib.md5() #創建MD5對象 hashs.update(passwd) #生成加密串 return hashs.hexdigest() #獲取加密串 #密碼位數檢測,只能是6位數字 def check_digit(passwd): com = re.compile('^\d{6,6}$') temps = com.findall(passwd) if len(temps) == 0: return False else: return True #檢測銀行卡號位數 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 卡號申請程序 @author: toby """ from encryption import password import shelve, random, getpass, time #申請資格評估 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] = val if __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 password import getpass from 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 數據操作相關功能 #我的卡號:1098521606032848 @author: toby """ from encryption import password import shelve, getpass, time #數據庫讀取操作,這是一個全局動作 f = shelve.open('data.db') #檢測卡號是否存在 def check_card_active(card_number): if f.get(card_number,None) != None: #判斷對應卡號是否存在 return True else: return False #檢測對應卡號中對應的關鍵字數據,例如檢測對應卡號密碼 def get_data(card,keys): data = f[card] return data[keys] #查詢對應卡號的所有數據 def get_all_data(card): data = f[card] print ''' 卡號: %s 戶名: %s 固定額度: %s (人民幣) 可用余額: %s (人民幣) 需還款: %s (人民幣) 還款日: %s '''% (card,data['name'],data['fixed_amount'],data['temp_money'],data['repayment_amount'],data['repayment_time']) #扣款通用接口,正常POS機消費或者網銀支付 ,無需手續費 def pos_smart_pay(card_number,card_password,price): if check_card_active(card_number) == False: print '對不起,卡號有誤!' return False passwd_md5 = password.md5(card_password) #將輸入的密碼進行加密,用于和數據庫中的md5密碼匹配 db_passwd = get_data(card_number,'passwd') #從數據庫讀取對應卡號的密碼 if passwd_md5 != db_passwd: print '支付密碼錯誤' return False else: data = f[card_number] #讀取對應卡號信息 existing = data['temp_money'] #讀取現有金額 if price > existing: print '對不起,余額不足' else: result = existing - price #現有金額減去正常消費價格 data['temp_money'] = int(result) #臨時存儲計算結果 f[card_number] = data #計算結果數據入庫 current_repayment_amoount = data['repayment_amount'] #讀取現有還款金額 res = current_repayment_amoount + price #現有還款金額 + 當前消費金額 = 需還款的金額 data['repayment_amount'] = int(res) f[card_number] = data #需還款金額數據入庫 action = "POS消費" record_water(card_number,action,price) f.close() return True #取款機取款功能 需5%手續費 def cash_debit(card_number,money): data = f[card_number] #讀取對應卡號信息 existing = data['temp_money'] #讀取現有可用金額 if money > existing: print ''' 對不起,余額不足,無法套現 您當前可用金額: %s ''' % existing else: repayment = money * 0.05 #套現時計算手續費 print ''' 取款金額: %s 手續費: %s ''' % (money, repayment) result = existing - money - repayment #現有金額-套現金額(再減去手續費) data['temp_money'] = int(result) #臨時存儲計算結果 f[card_number] = data #計算結果數據入庫 current_repayment_amoount = data['repayment_amount'] #讀取現有還款金額 temporary = current_repayment_amoount + money + (money * 0.05) #現有還款金額 + 當前套現金額+手續費 data['repayment_amount'] = int(temporary) f[card_number] = data #需還款金額數據入庫 #調用記錄流水的函數進行記錄流水 action = "取款機套現" 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 #需還款金額 - 傳入進來的還款額 = 剩余還款額(全部還清后這里為0元,還多少減多少) f[card_number] = data #剩余還款額數據入庫 existing = data['temp_money'] #讀取現有可用金額 data['temp_money'] = existing + money #現有可用金額 + 已傳入進來的需還金額 (累加到可用金額,還多少就會累加多少) f[card_number] = data #還款后累加可用后的金額數據入庫 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('支付卡號:') payment_price = input('價格:') payment_password = getpass.getpass('支付密碼:') if pos_smart_pay(payment_card,payment_password,int(payment_price)) == True: print '支付完成' break else: print '支付失敗' continue
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。