# 互亿无线  https://www.ihuyi.com/
import requests

# 用户名 查看用户名请登录用户中心->验证码、通知短信->帐户及签名设置->APIID
account  = "C80604386"
# 密码 查看密码请登录用户中心->验证码、通知短信->帐户及签名设置->APIKEY
password = "16874f2ed0a2d0bb225747370f9aedc4"
mobile = "18566218480"
text = "您的验证码是:121254。请不要把验证码泄露给其他人。"

url = 'http://106.ihuyi.com/webservice/sms.php?method=Submit'
data = {'account': account, 'password' : password, 'content': text, 'mobile':mobile,'format':'json'}

res = requests.post(url, data=data)
print(res.text)
发送短信-互亿无线
# 云之讯  https://www.ucpaas.com/

import requests
import random


def send_sms(phone, vcode):
    '''
    发送短信
    :param phone: 手机号
    :param vcode: 验证码
    '''

    # 云之讯的短信接口
    url = "https://open.ucpaas.com/ol/sms/sendsms"

    data = {
        "sid": "7d946861e6b2d74b2db38a442a19fd38",
        "token": "8712938e22c34a179b3cea43ff783b68",
        "appid": "36c083fcfdcf47b5b50d6a94fbb0e50c",

        "templateid": "422930",  # 短信模板id
        "param": vcode,  # 验证码
        "mobile": phone,  # 接收验证码的手机号
    }

    # requests
    res = requests.post(url, json=data)
    return res.text


def generate_vcode():
    '''
    生成随机6位验证码
    '''
    vcode = ""
    for _ in range(6):
        vcode += str(random.randint(0, 9))
    return vcode


if __name__ == '__main__':
    vcode = generate_vcode()
    print("vcode:", vcode)

    res = send_sms('18566218480', vcode)
    print(res)
发送短信-云之讯

 

posted on 2021-03-25 14:46  始终不够啊  阅读(210)  评论(0)    收藏  举报