发送短信
发送短信是现在的WEB网站不可少的一个功能,但是短信和邮件不同,短信通常是收费的,需要借助三方的短信平台进行短信发送,实际上也是接口请求的过程
这李采用云通信作为短信发送的三方
GitHub 克隆源代码,放在主文件目录中
from ronglian_sms_sdk import SmsSDK
accId = '8a216da871bf71a10171e7a5ab0e09e6'
accToken = '15a3d752748e41fab577e4e5a1ad262e'
appId = '8a216da871bf71a10171e7a5ab8009ed'
def send_message():
sdk = SmsSDK(accId, accToken, appId)
tid = '1'
mobile = '13331153360'
datas = ('9527', '60')
resp = sdk.sendMessage(tid, mobile, datas)
print(resp)
send_message()
修改代码结构
from ronglian_sms_sdk import SmsSDK
from Qshop.settings import accId,accToken,appId
def send_message(code,timer="5"):
sdk = SmsSDK(accId, accToken, appId)
tid = '1'
mobile = '13331153360'
datas = (code, timer)
resp = sdk.sendMessage(tid, mobile, datas)
print(resp)
if __name__ == '__main__':
send_message("9527")
主目录setting中
accId = '8a216da871bf71a10171e7a5ab0e09e6' #主账户ID
accToken = '15a3d752748e41fab577e4e5a1ad262e' #账户授权令牌
appId = '8a216da871bf71a10171e7a5ab8009ed' #AppID
函数中调用