Vue + Django 2.0.6 学习笔记 7.7云片网发送短信

首先要去 云片网注册:

https://www.yunpian.com/

然后开发者信息认证

然后就是新增签名和新增模板。

然后查看api文档:

https://www.yunpian.com/doc/zh_CN/introduction/brief.html

本次用的是单发短信 所以只需要看单发短信的api就可以了

https://www.yunpian.com/doc/zh_CN/domestic/single_send.html

这三个参数是必传:

接下来就是根据该api写一个短信发送的程序

apps/utils/yunpian.py

# -*- encoding: utf-8 -*-


import json
import requests

class YunPian(object):

    def __init__(self, api_key):
        self.api_key = api_key
        self.single_send_url = "https://sms.yunpian.com/v2/sms/single_send.json"

    def send_sms(self, code, mobile):
        params = {
            "apikey": self.api_key,
            "mobile": mobile,
            "text": "dfsfa{code}fewfe".format(code=code),
        }

        response = requests.post(self.single_send_url, data=params)
        re_dict = json.loads(response.text)
        print(re_dict)

# 测试用

if __name__ == '__main__':
    yun_pian = YunPian("key")
    yun_pian.send_sms("fwf",'15164440792')

其中有用到requests模块,这个在爬虫方面用得多 具体使用看文档

https://2.python-requests.org//zh_CN/latest/user/quickstart.html

如果发送被拒那就吧IP添加入白名单中

这样发送短信的工具类就写好了 本篇完结

注:没有测试结果 因为云片网那小婊砸要我上传公司营业执照 谁会有啊

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@凌晨三点半

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值