短信接口示例
這篇文章主要為大家分享Python短信接口代碼,Python短信發(fā)送、Python批量發(fā)送、Python短信驗證碼發(fā)送,感興趣的小伙伴們可以參考一下。
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests import json import hashlib import time class SendCode: def send(self,account,pswd,mobile,msg,ts,state): url = 'http://139.196.108.241:8080'+{ 1:'/Api/HttpSendSMYzm.ashx', 2:'/Api/HttpSendSMYx.ashx', 3:'/Api/HttpSendSMVoice.ashx' }[state]; if ts!="" : m = hashlib.md5() strs = account+pswd+str(ts) m.update(strs.encode("utf8")) pswd = m.hexdigest() body = {"account": account, "pswd": pswd, "mobile": mobile,"msg":msg,"ts":str(ts)} header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko', "Content-Type": "application/x-www-form-urlencoded"} response = requests.post(url, data=body,headers = header_dict) return json.loads( response.text) # account 用戶賬號 # pswd 必填參數。用戶密碼 # mobile 必填參數。合法的手機號碼 # msg 必填參數。短信內容 # ts 可選參數,時間戳,格式y(tǒng)yyyMMddHHmmss # state 必填參數 狀態(tài) 1:驗證碼短信 2:營銷短信 3:語音驗證碼 send = SendCode() res = send.send('您的賬號','您的密碼','手機號','短信內容', (int(time.time())),1) # print(res['result'])