python如何使用騰訊云發(fā)送短信
騰訊云方面的申請和流程都比較簡單,基本都是可視化操作的,這里就不在贅述了。這篇文章著重講解怎么用python實(shí)現(xiàn)調(diào)用。 我假設(shè)你已經(jīng)滿足了以下幾個前提 + 已經(jīng)開通了騰訊云短信業(yè)務(wù) + 創(chuàng)建好了短信簽名 + 也已經(jīng)審核過了短信正文模板 + 并且已經(jīng)知道自己的SDK AppID、簽名ID、短信模板ID
Python 相關(guān)需要安裝騰訊云提供的模塊或SDK 我們以qcloudsms_py模塊為準(zhǔn),首先
pip install qcloudsms_py
發(fā)送短信我們需要用到的模塊有下面2個
from qcloudsms_py import SmsMultiSender, SmsSingleSenderfrom qcloudsms_py.httpclient import HTTPError
在引入之后,就可以封裝一個函數(shù)進(jìn)行開心的發(fā)送啦~(這里不太推薦騰訊的SDK,官方對python的不是很有好,還要弄的比較復(fù)雜,直接封裝函數(shù)比較方便) 附上一個我自己的發(fā)送函數(shù)
from qcloudsms_py import SmsMultiSender, SmsSingleSenderfrom qcloudsms_py.httpclient import HTTPErrorfrom django.conf import settingsdef send_sms_single(phone_num, template_id, template_param_list): appid = ’你的appid’ appkey = ’你的appkey’ sms_sign = ’你的簽名名稱’ print(appid,appkey,sms_sign) sender = SmsSingleSender(appid, appkey) try: response = sender.send_with_param(86, phone_num, template_id, template_param_list, sign=sms_sign) except HTTPError as e: response = {’result’: 1000, ’errmsg’: '網(wǎng)絡(luò)異常發(fā)送失敗'} return response
以上就是python如何使用騰訊云發(fā)送短信的詳細(xì)內(nèi)容,更多關(guān)于python 發(fā)送短信的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)2. XML入門的常見問題(三)3. Vue3使用JSX的方法實(shí)例(筆記自用)4. vue實(shí)現(xiàn)將自己網(wǎng)站(h5鏈接)分享到微信中形成小卡片的超詳細(xì)教程5. 詳解CSS偽元素的妙用單標(biāo)簽之美6. 不要在HTML中濫用div7. 利用CSS3新特性創(chuàng)建透明邊框三角8. 多級聯(lián)動下拉選擇框,動態(tài)獲取下一級9. Vue3獲取DOM節(jié)點(diǎn)的3種方式實(shí)例10. 前端html+css實(shí)現(xiàn)動態(tài)生日快樂代碼
