秒嘀(miaodi)短信群发平台demo(python版)
2018-02-08 14:31
471 查看
#!/usr/bin/python #-*-coding:utf-8-*- #秒嘀短信API实现 # Refer to: http://www.miaodiyun.com/doc/guide.html import httplib,urllib,hashlib,datetime,time,json,ssl; #加载模块 #发送行业短信 def sendIndustrySms(tos, smsContent): #定义账号和密码,开户之后可以从用户中心得到这两个值 accountSid = 'xxx'; acctKey = 'xxx'; #定义地址,端口等 serverHost = "api.miaodiyun.com"; serverPort = 443; industryUrl = "/20150822/industrySMS/sendSMS"; #格式化时间戳,并计算签名 timeStamp = datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d%H%M%S'); rawsig = accountSid + acctKey + timeStamp; m = hashlib.md5(); m.update(rawsig); sig = m.hexdigest(); #定义需要进行发送的数据表单 params = urllib.urlencode({'accountSid':accountSid, 'smsContent':smsContent, 'to':tos, 'timestamp':timeStamp, 'sig':sig}); #定义header headers = {"Content-Type":"application/x-www-form-urlencoded", "Accept":"application/json"}; #与构建https连接 conn = httplib.HTTPSConnection(serverHost, serverPort); #Post数据 conn.request(method = "POST", url = industryUrl, body = params, headers = headers); #返回处理后的数据 response = conn.getresponse(); #读取返回数据 jsondata = response.read().decode('utf-8'); #打印完整的返回数据 print jsondata; #解析json,获取特定的几个字段 jsonObj = json.loads(jsondata); respCode = jsonObj['respCode']; print "错误码:" , respCode; respDesc = jsonObj['respDesc']; print "错误描述:" , respDesc; #关闭连接 conn.close(); #tos可以是一个或者多个号码,若是多个号码,以英文逗号分开 tos = '18665152605'; #短信内容 smsContent = '【秒嘀科技】您的秒嘀科技验证码是888888,5分钟有效。'; #提交短信 sendIndustrySms(tos, smsContent);
相关文章推荐
- python+flask+SAE 微信公共平台开发的小小的demo
- Python---短信接口demo,对接创蓝253云通讯paas平台
- Python使用pip安装第三方库时出现UnicodeError的解决办法(Windows平台下)
- Python下的自然语言处理利器-LTP语言技术平台 pyltp 学习手札
- python的平台编码、默认编码、解码直接的联系的一些个人理解
- 在Ubuntu下开始搭建Python开发平台
- 关于云打码平台的'PythonHttp'调用实例的使用
- 多因子模型之因子(信号)测试平台----python中Pandas做处理时内存节省的技巧
- python编写windows平台下脚本二三事
- iis日志分析和tomcat日志分析(python)demo
- Windows7x64平台安装Python2.x
- 用 Python 开发一个企业级的监控平台
- python在不同平台下的安装方法
- Python识别平台登录验证码
- hadoop平台使用python编写mapreduce二次排序小程序
- 【数据平台】python语言NLP库Gensim初识
- python获取操作系统平台、版本及架构
- Windows平台下为Python添加MySQL支持
- 金山词霸每日一句开放平台 .NET demo
- python 使用 passlib 库在 windows 平台实现 crypt