python发送短信

目的:

使用手机号验证码形式登陆。

使用的接口平台(大概3分钱一条,免费送了500条):

https://www.twilio.com

# 进入这个网站,注册账户,验证手机号,填写信息,之后会分配给你一个发送验证码的手机号及两个密钥

# 发送短信不太稳定 ,有时候收不到

安装模块:

pip install twilio

封装好的代码:

def send_veri_code(to_phone, code):
    from twilio.rest import Client
    account_sid = "平台获取"
    auth_token = "平台获取"
    client = Client(account_sid, auth_token)
    client.messages.create(
        to=to_phone,
        from_="平台获取这个主动发送短信的手机号",
        body="您的验证码是:%s" % code
    )

if __name__ == '__main__':
    # 发送给的手机号
    phone = '+86152*********'
    verification_code = '1234'
    send_veri_code(phone, verigication_code)
原文地址:https://www.cnblogs.com/zezhou/p/13157039.html