Python调用飞信接口发送短信
2013-09-18 09:53
543 查看
主要参考了两篇文章:(对原作者表示感谢~)
发送飞信的Python脚本:http://www.cnblogs.com/fatway/archive/2009/08/07/1693813.html
中国移动飞信发送接口(Fetion API):http://blog.quanhz.com/archives/273
2013年9月18日亲测可用。
下面是代码:【使用前将账号密码换为自己的】
发送飞信的Python脚本:http://www.cnblogs.com/fatway/archive/2009/08/07/1693813.html
中国移动飞信发送接口(Fetion API):http://blog.quanhz.com/archives/273
2013年9月18日亲测可用。
下面是代码:【使用前将账号密码换为自己的】
# -*- coding:utf-8 -*- # file: SendFetion.py # by Lee 2013-9-18 """----------------------------------------------------------------------------- 使用HTTPS调用飞信接口: https://quanapi.sinaapp.com/fetion.php?u=飞信登录手机号&p=飞信登录密码&to=接收飞信的手机号&m=飞信内容 返回结果为Json格式,result=0时表示发送成功 {“result”:0,”message”:”\u53d1\u9001\u6210\u529f”} -----------------------------------------------------------------------------""" import sys import httplib import urllib import re import time import json class Fetion: """ model to call fetionapi. attribute:url, fromTel, pwd, toTel, msg function:Trans, format_url, SendMsg """ url = "https://quanapi.sinaapp.com/fetion.php?u=" def __init__(self, toTel, msg, fromTel = '151xxxxxxxx', # default my phone pwd = 'pxxxxxxxx'): self.fromTel = fromTel self.pwd = pwd self.toTel = toTel self.msg = self.Trans(msg) def Trans(self, msg): # change space to '%20', otherwise error raised return re.sub(" ", "%20", str(msg)) def format_url(self): url_address = self.url + self.fromTel \ + "&p=" + self.pwd \ + "&to=" + self.toTel \ + "&m=" + self.msg return url_address def SendMsg(self): # call the api by http get method return urllib.urlopen(self.format_url()) def msg2log(msg): logfile = open('MyFetion.log', 'a') now = time.strftime('%Y%m%d %H:%M:%S') logfile.write('\n'+ now + '\n' + msg + '\n') logfile.close() def main(): # format mutual message print "\n" + " "*10 + "*"*60 print " "*10 + " Personal Fetion" print " "*10 + " Enter the number and message what you want to send to." print " "*10 + " blank number means yourself," print " "*10 + " and a blank message line to exit." print " "*10 + "*"*60 # get the destination phone number toTel = raw_input("Input the target telphone number:") if toTel == "": toTel = "151xxxxxxxx" # none input for a target most used # get the message and send by Fetion class while True: msg = raw_input("Message:") if msg == "": break # none input to quit else: print "Sending...." msg2log(msg) ff = Fetion(toTel, msg) answer = ff.SendMsg() data = answer.read() jdata=json.loads(data) if jdata['result']==0: print 'Done.^_^\n' else: print 'Fail.-_=\n' if __name__ == '__main__': main()
相关文章推荐
- Python调用飞信接口发送短信
- Python调用飞信接口发送短信
- python 发送飞信-短信接口
- 调用飞信网关服务器HTTP接口发送短信的ASP源码
- java调用飞信接口免费短信发送到对方手机
- Python调用第三方接口实现nagios短信报警
- 调用系统接口发送短信
- Python调用第三方接口实现nagios短信报警 推荐
- Java调用WebService接口实现发送手机短信验证码功能
- Python向飞信好友发送短信
- 调用发送短信接口经验总结
- java程序实现短信发送(可调用免费短信接口)
- 基于python的短信接口调用代码示例模板
- 发送短信验证码及调用短信接口与C# 后台 post 发送
- android 中调用接口发送短信
- android 中调用接口发送短信
- 飞信免费发送短信接口
- java调接口实现发送手机短信验证码功能,手机验证码,接口调用
- android 中调用接口发送短信
- 中国网建SMS短信接口调用(java发送和接收手机短信)