第一中大小寫加數字的字符串
import random
import string
def ra():
ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 4))
return ('gpw10280508019_' + ran_str)
print ('gpw10280508019_'+ ran_str) #定義全局驗證碼變量
代碼詳解:
ran_str 生成字符串變量和訂單號進行拼接
第二中純數字字符串
def ra():
auth = ""
for i in range(0,15): #定義循環4次,形成4個驗證碼
current_code = random.randint(0,9) #定義隨機數字的范圍
auth += str(current_code) #將隨機數字賦值給 全局變量auth
return auth
代碼詳解:
auth將隨機數字賦值給 全局變量auth