Python 短信发送类

import http.client
import urllib

#亿万无线发送短信接口
class SendSMS:
    #账号初始化
    def  __init__(self,account,password):
        self.host = "106.ihuyi.com"
        self.sms_send_uri = "/webservice/sms.php?method=Submit"
        self.account = account
        self.password = password
    #发送短信
    def send_sms(self,text, mobile):
        params = urllib.parse.urlencode(
            {'account': self.account, 'password': self.password, 'content': text, 'mobile': mobile, 'format': 'json'})
        headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
        conn = http.client.HTTPConnection(self.host, port=80, timeout=30)
        conn.request("POST", self.sms_send_uri, params, headers)
        response = conn.getresponse()
        response_str = response.read()
        conn.close()
        return response_str
    #批量发送
    def send_smss(self,text, mobilelist):
        for mobile in mobilelist:
            print(str(mobile))
            print(self.send_sms(text, str(mobile)))


sender1=SendSMS("C29408441","42d111e84be3ca82032dbfea49f36dba")
sender1.send_sms("您的验证码是:121254。请不要把验证码泄露给其他人。","12345678999")


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值