Python-向飞信好友发送短信,可用于日常监控程序

代码分享

当前位置:
代码分享 »  Python  »  Web编程
分享到 
收藏 +14
0
参照oschina上某位大牛写的php代码,改成python版本,实现向飞信好友下发短信功能。
该功能可用于日常监控脚本中,当发现系统异常时主动向自己的手机上发送短信,避免邮件告警处理不及时的问题。
标签: <无>

代码片段(1)[全屏查看所有代码]

1. [代码][Python]代码    

01#coding:utf-8
02#调用飞信
03 
04import urllib2
05import urllib
06 
07 
08class fetion:
09    msisdn = ''
10    passwd = ''
11    baseurl = 'http://quanapi.sinaapp.com/fetion.php'
12 
13    #设置登陆用户
14    def setuser(self,msisdn,passwd):
15        self.msisdn = msisdn
16        self.passwd = passwd
17 
18    #发送短信
19    def sendsms(self,recmsisdn,content):
20        cod = 1
21        if self.msisdn == '' :
22            cod = 0
23            return 'msisdn is null'
24 
25        if self.passwd == '' :
26            cod = 0
27            return 'passwd is null'
28 
29        if recmsisdn == '' :
30            cod = 0
31            return 'recmsisdn is null'
32 
33        if content == '':
34            cod = 0
35            return 'content is null'
36 
37        if cod == 1 :
38            smsurl = self.baseurl + '?u=' + self.msisdn + '&p=' + self.passwd + '&to='+recmsisdn +'&m=' + content
39            print smsurl
40 
41            res = urllib2.urlopen(smsurl).read()
42            #反馈调用结果
43            return res.split(',')[0].split(':')[1]
44 
45 
46newfetion = fetion()
47 
48#设置登陆飞信的用户
49newfetion.setuser('13812341234','123456')
50#发送短信
51print newfetion.sendsms('13812341235','测试')
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值