最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python制作短信發(fā)送程序

 更新時間:2023年01月29日 09:24:15   作者:虛壞叔叔  
這篇文章主要為大家詳細介紹了如何利用Python制作短信發(fā)送程序,文中的示例代碼講解詳細,具有一定的借鑒價值,需要的可以參考一下

一、Python短信發(fā)送界面最后的效果

二、準備:注冊騰訊云賬號并配置短信功能

(1)注冊騰訊云賬號

登錄騰訊云網(wǎng)址

(2)獲取AppID、AppKey

在短信功能頁面下,從應用管理>應用列表,獲取ID、Key。

(3)創(chuàng)建簽名

在短信功能頁面下,進入國內(nèi)短信>簽名管理,創(chuàng)建簽名。

(4)創(chuàng)建正文模板

在短信功能頁面下,進入國內(nèi)短信>正文模板管理,創(chuàng)建模版。并獲取模板ID備用。

三.初始化短信發(fā)送程序窗口

3.1初始化窗口菜單

菜單具備打開手機號碼文件、保存記錄、查看版本等功能。

    menu=tkinter.Menu(root)
    submenu1 = tkinter.Menu(menu, tearoff=0)
    submenu1.add_command(label='打開', command=open_file)
    submenu1.add_command(label='保存', command=save_file)
    menu.add_cascade(label='文件',menu=submenu1)
    submenu3 = tkinter.Menu(menu, tearoff=0)    
    submenu3.add_command(label='版本信息', command=Introduction)
    menu.add_cascade(label='幫助',menu=submenu3)
    root.config(menu=menu)

3.2初始化窗口控件

控件包括號碼輸入框、發(fā)送信息按鈕,記錄顯示框。

    global text1,text2
    label1 = tkinter.Label(root, text="手機號碼:", font=("微軟雅黑", 18))
    label1.place(x=30,y=32)
    text1 = tkinter.Text(root, wrap = 'none', font=("微軟雅黑", 18))
    text1.place(x=30+120,y=30, width=520-120-100, height=40)
    button=tkinter.Button(root, text='發(fā)送信息',width=10, height=20, bg='gray', fg='white', font=("微軟雅黑", 12),command=send_Button)
    button.place(x=480,y=30,width=70, height=40)
    sx = tkinter.Scrollbar(root,orient = tkinter.HORIZONTAL)
    sx.pack(side = tkinter.BOTTOM,fill = tkinter.X)
    sy = tkinter.Scrollbar(root)
    sy.pack(side = tkinter.RIGHT,fill = tkinter.Y)     
    text2 = tkinter.Text(root, yscrollcommand = sy.set, xscrollcommand = sx.set, wrap = 'none', font=("微軟雅黑", 10))
    text2.place(x=30,y=100, width=520, height=400)
    text2.config(wrap=tkinter.WORD)
    text2.see(tkinter.END);
    sx.config(command = text2.xview) 
    sy.config(command = text2.yview)

3.3編寫事件觸發(fā)程序

3.3.1文件打開

def open_file():
    global file_path,phone_numbers,flag
    file_path = filedialog.askopenfilename()
    if file_path is not "":
        data=pandas.read_excel(file_path)
        phone = data['號碼'].tolist()
        for i in range(len(phone)):
            phone_numbers.append(str(phone[i]))
        text2.insert(tkinter.END,"*********************************"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"打開文件成功!"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"文件路徑為:"+file_path+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"文件內(nèi)容如下:"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,data, '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"\n", '\n')
        text2.see(tkinter.END);
        flag = 1
    else:
        text2.insert(tkinter.END,"*********************************"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"您未打開文件!"+"\n", '\n')
        text2.see(tkinter.END);
        flag = 0

3.3.2文件保存

def save_file():
    file=open("recorde.txt","a+")
    content=str(text2.get("0.0", "end"))
    file.write(content)
    file.close()
    text2.insert(tkinter.END,"*********************************"+"\n", '\n')
    text2.see(tkinter.END);
    text2.insert(tkinter.END,"保存記錄到recorde.txt成功!"+"\n", '\n')
    text2.see(tkinter.END);
    tkinter.messagebox.showinfo('提示','保存記錄到recorde.txt成功!')
    text2.see(tkinter.END);

3.3.3幫助菜單

def Introduction():
    text2.insert(tkinter.END,"*********************************"+"\n", '\n')
    text2.see(tkinter.END);
    text2.insert(tkinter.END,"版本信息:短信息通知程序 V1.0"+"\n", '\n')
    text2.see(tkinter.END);
    tkinter.messagebox.showinfo('版本信息' ,'短信息通知程序 V1.0')
    text2.see(tkinter.END);

3.3.4發(fā)送按鈕

def send_Button():
    global flag,phone_numbers
    appid = "你的appid"
    appkey = "你的appkey"
    template_id = "你的模板ID"
    sms_sign = "你的公眾號名稱"
    params = []
    ssl._create_default_https_context = ssl._create_unverified_context  
    ssender = SmsSingleSender(appid, appkey)    
    txt1 = str(text1.get("0.0", "end")).replace('\n', '')
    if flag==0:
        if ',' in txt1:
            phone_numbers=str(text1.get("0.0", "end")).replace('\n', '').split(',')
        elif ',' in txt1:
            phone_numbers=str(text1.get("0.0", "end")).replace('\n', '').split(',')
        else:
            phone_numbers=[]
            phone_numbers.append(txt1)
    else:
        flag = 0
    count=0
    for l in phone_numbers:
        count=count+len(str(l))
    if count%11==0:
        result = ""
        for i in range(len(phone_numbers)):
            try:
                result = ssender.send_with_param(86, phone_numbers[i],template_id, params, sign=sms_sign, extend="", ext="") 
            except HTTPError as e:  
                result=e
            except Exception as e:  
                result=e
            text2.insert(tkinter.END,"*********************************"+"\n", '\n')
            text2.see(tkinter.END);
            text2.insert(tkinter.END,"信息發(fā)送至手機號:"+"\n"+str(phone_numbers[i])+"\n")
            text2.see(tkinter.END);
            text2.insert(tkinter.END,"信息發(fā)送返回結(jié)果:"+"\n")
            text2.see(tkinter.END);
            text2.insert(tkinter.END,str(result)+"\n", '\n')
            text2.see(tkinter.END);
            if result['errmsg']=='OK':
                text2.insert(tkinter.END,"信息發(fā)送至【"+str(phone_numbers[i])+"】成功!"+"\n")
                text2.see(tkinter.END);
            else:
                text2.insert(tkinter.END,"信息發(fā)送至【"+str(phone_numbers[i])+"】失??!"+"\n")
                text2.see(tkinter.END);
    else:
        text2.insert(tkinter.END,"*********************************"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"手機號碼格式不正確"+"\n", '\n')
        text2.see(tkinter.END);

四、完整源代碼

import tkinter
import tkinter.messagebox
from tkinter import filedialog
import pandas
import ssl
from qcloudsms_py import SmsSingleSender  
from qcloudsms_py.httpclient import HTTPError 

def open_file():
    global file_path,phone_numbers,flag
    file_path = filedialog.askopenfilename()
    if file_path is not "":
        data=pandas.read_excel(file_path)
        phone = data['號碼'].tolist()
        for i in range(len(phone)):
            phone_numbers.append(str(phone[i]))
        text2.insert(tkinter.END,"*********************************"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"打開文件成功!"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"文件路徑為:"+file_path+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"文件內(nèi)容如下:"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,data, '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"\n", '\n')
        text2.see(tkinter.END);
        flag = 1
    else:
        text2.insert(tkinter.END,"*********************************"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"您未打開文件!"+"\n", '\n')
        text2.see(tkinter.END);
        flag = 0
    
def save_file():
    file=open("recorde.txt","a+")
    content=str(text2.get("0.0", "end"))
    file.write(content)
    file.close()
    text2.insert(tkinter.END,"*********************************"+"\n", '\n')
    text2.see(tkinter.END);
    text2.insert(tkinter.END,"保存記錄到recorde.txt成功!"+"\n", '\n')
    text2.see(tkinter.END);
    tkinter.messagebox.showinfo('提示','保存記錄到recorde.txt成功!')
    text2.see(tkinter.END);
        
def Introduction():
    text2.insert(tkinter.END,"*********************************"+"\n", '\n')
    text2.see(tkinter.END);
    text2.insert(tkinter.END,"版本信息:短信息通知程序 V1.0"+"\n", '\n')
    text2.see(tkinter.END);
    tkinter.messagebox.showinfo('版本信息' ,'短信息通知程序 V1.0')
    text2.see(tkinter.END);
    

def send_Button():
    global flag,phone_numbers
    appid = "你的appid"
    appkey = "你的appkey"
    template_id = "你的模板ID"
    sms_sign = "你的公眾號名稱"
    params = []
    ssl._create_default_https_context = ssl._create_unverified_context  
    ssender = SmsSingleSender(appid, appkey)    
    txt1 = str(text1.get("0.0", "end")).replace('\n', '')
    if flag==0:
        if ',' in txt1:
            phone_numbers=str(text1.get("0.0", "end")).replace('\n', '').split(',')
        elif ',' in txt1:
            phone_numbers=str(text1.get("0.0", "end")).replace('\n', '').split(',')
        else:
            phone_numbers=[]
            phone_numbers.append(txt1)
    else:
        flag = 0
    count=0
    for l in phone_numbers:
        count=count+len(str(l))
    if count%11==0:
        result = ""
        for i in range(len(phone_numbers)):
            try:
                result = ssender.send_with_param(86, phone_numbers[i],template_id, params, sign=sms_sign, extend="", ext="") 
            except HTTPError as e:  
                result=e
            except Exception as e:  
                result=e
            text2.insert(tkinter.END,"*********************************"+"\n", '\n')
            text2.see(tkinter.END);
            text2.insert(tkinter.END,"信息發(fā)送至手機號:"+"\n"+str(phone_numbers[i])+"\n")
            text2.see(tkinter.END);
            text2.insert(tkinter.END,"信息發(fā)送返回結(jié)果:"+"\n")
            text2.see(tkinter.END);
            text2.insert(tkinter.END,str(result)+"\n", '\n')
            text2.see(tkinter.END);
            if result['errmsg']=='OK':
                text2.insert(tkinter.END,"信息發(fā)送至【"+str(phone_numbers[i])+"】成功!"+"\n")
                text2.see(tkinter.END);
            else:
                text2.insert(tkinter.END,"信息發(fā)送至【"+str(phone_numbers[i])+"】失??!"+"\n")
                text2.see(tkinter.END);
    else:
        text2.insert(tkinter.END,"*********************************"+"\n", '\n')
        text2.see(tkinter.END);
        text2.insert(tkinter.END,"手機號碼格式不正確"+"\n", '\n')
        text2.see(tkinter.END);


    
def init_frame(root):   
    menu=tkinter.Menu(root)
    submenu1 = tkinter.Menu(menu, tearoff=0)
    submenu1.add_command(label='打開', command=open_file)
    submenu1.add_command(label='保存', command=save_file)
    menu.add_cascade(label='文件',menu=submenu1)
    submenu3 = tkinter.Menu(menu, tearoff=0)    
    submenu3.add_command(label='版本信息', command=Introduction)
    menu.add_cascade(label='幫助',menu=submenu3)
    root.config(menu=menu)
    global text1,text2
    label1 = tkinter.Label(root, text="手機號碼:", font=("微軟雅黑", 18))
    label1.place(x=30,y=32)
    text1 = tkinter.Text(root, wrap = 'none', font=("微軟雅黑", 18))
    text1.place(x=30+120,y=30, width=520-120-100, height=40)
    button=tkinter.Button(root, text='發(fā)送信息',width=10, height=20, bg='gray', fg='white', font=("微軟雅黑", 12),command=send_Button)
    button.place(x=480,y=30,width=70, height=40)
    sx = tkinter.Scrollbar(root,orient = tkinter.HORIZONTAL)
    sx.pack(side = tkinter.BOTTOM,fill = tkinter.X)
    sy = tkinter.Scrollbar(root)
    sy.pack(side = tkinter.RIGHT,fill = tkinter.Y)     
    text2 = tkinter.Text(root, yscrollcommand = sy.set, xscrollcommand = sx.set, wrap = 'none', font=("微軟雅黑", 10))
    text2.place(x=30,y=100, width=520, height=400)
    text2.config(wrap=tkinter.WORD)
    text2.see(tkinter.END);
    sx.config(command = text2.xview) 
    sy.config(command = text2.yview)
    root.update()

if __name__=="__main__":
    global flag
    flag = 0
    global phone_numbers
    phone_numbers = []
    root = tkinter.Tk()
    root.title("短信息發(fā)送程序")
    root.geometry('600x520')
    init_frame(root)
    root.mainloop()

以上就是基于Python制作短信發(fā)送程序的詳細內(nèi)容,更多關于Python短信發(fā)送的資料請關注腳本之家其它相關文章!

相關文章

  • Python 繪制?;鶊D全面解析

    Python 繪制?;鶊D全面解析

    桑基圖,即?;芰糠至鲌D,也叫?;芰科胶鈭D。它是一種特定類型的流程圖,圖中延伸的分支的寬度對應數(shù)據(jù)流量的大小,通常應用于能源、材料成分、金融等數(shù)據(jù)的可視化分析。試了一下用python畫?;鶊D,在這里整理了一下分享給大家
    2021-09-09
  • python中reversed與reverse的區(qū)別解析

    python中reversed與reverse的區(qū)別解析

    reverse()是python中列表的一個內(nèi)置方法(在字典、字符串和元組中沒有這個內(nèi)置方法),用于列表中數(shù)據(jù)的反轉(zhuǎn),這篇文章主要介紹了python中reversed與reverse的區(qū)別,需要的朋友可以參考下
    2023-03-03
  • Python內(nèi)置函數(shù)zip map filter的使用詳解

    Python內(nèi)置函數(shù)zip map filter的使用詳解

    這篇文章主要介紹了Python內(nèi)置函數(shù)zip map filter的使用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • python實現(xiàn)的登陸Discuz!論壇通用代碼分享

    python實現(xiàn)的登陸Discuz!論壇通用代碼分享

    這篇文章主要介紹了python實現(xiàn)的登陸Discuz!論壇通用代碼分享,需要的朋友可以參考下
    2014-07-07
  • 解決python多線程報錯:AttributeError: Can''t pickle local object問題

    解決python多線程報錯:AttributeError: Can''t pickle local object問題

    這篇文章主要介紹了解決python多線程報錯:AttributeError: Can't pickle local object問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • Numpy中的數(shù)組搜索中np.where方法詳細介紹

    Numpy中的數(shù)組搜索中np.where方法詳細介紹

    這篇文章主要介紹了Numpy中的數(shù)組搜索中np.where方法詳細介紹,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01
  • Python獲取一個用戶名的組ID過程解析

    Python獲取一個用戶名的組ID過程解析

    這篇文章主要介紹了Python獲取一個用戶名的組ID過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • 對Python實現(xiàn)累加函數(shù)的方法詳解

    對Python實現(xiàn)累加函數(shù)的方法詳解

    今天小編就為大家分享一篇對Python實現(xiàn)累加函數(shù)的方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • Python3實現(xiàn)漢語轉(zhuǎn)換為漢語拼音

    Python3實現(xiàn)漢語轉(zhuǎn)換為漢語拼音

    這篇文章主要為大家詳細介紹了Python3實現(xiàn)漢語轉(zhuǎn)換為漢語拼音,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Django在win10下的安裝并創(chuàng)建工程

    Django在win10下的安裝并創(chuàng)建工程

    本篇文章主要介紹了Django在win10下的安裝并創(chuàng)建工程,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11

最新評論

丘北县| 金堂县| 新邵县| 原阳县| 临夏市| 莒南县| 都安| 苏尼特左旗| 金湖县| 利川市| 吉安县| 扶余县| 新疆| 固原市| 临猗县| 玉树县| 突泉县| 搜索| 象州县| 化德县| 贵阳市| 龙川县| 温宿县| 奉贤区| 安陆市| 日土县| 栖霞市| 岐山县| 贺州市| 高陵县| 永兴县| 中阳县| 峡江县| 晴隆县| 天台县| 肇庆市| 南投市| 阿鲁科尔沁旗| 高尔夫| 萍乡市| 墨脱县|