Python 短信Api接口调用

本文介绍了如何使用Python调用全球短信网的API接口,包括获取时间点、MD5加密、URL编码内容以及以POST方式提交JSON数据的关键步骤。
摘要由CSDN通过智能技术生成

仅供参考
接口文档api地址:https://www.globalsms.cn/api.html
需要注意的点:

  1. 时间点的获取及md5加密
  2. 内容的urlencode编码 post请求
  3. 数据以json方式提交
#!python3
#sms api test
import time, hashlib, urllib, urllib.parse, urllib.request, json, requests
headers = {'Content-Type': 'application/json;charset=UTF-8'}

for i in range(6):
    time.sleep(5)
    account = 'xxxxx'
    password = 'xxxxx'
    senderid = 'xxxxx'
    time_str = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
    
    sign_str = account+password+time_str
    m = hashlib.md5()
    b = sign_str.encode(encoding='utf-8')
    m.update(b)
    sign = m.hexdigest()

    numbers = '84123456789'
    content = 'hello, test.'

    #python3.0后的编码器urlencode更新后改为quote_plus   data = urllib.parse.urlencode(values)
    content = urllib.parse.quote_plus(conte
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python可以使用twilio库来调用短信接口。在运行代码之前,需要确保已经安装了twilio库。可以使用pip命令来安装twilio库,命令为pip install twilio。 twilio是一个常见的发送短信的平台之一,它允许免费发送500条短信,并且可以发送任意内容的短信。另外,腾讯云也是一个常见的发送短信的平台,它允许免费发送100条短信,但需要申请短信发送内容模板。 如果你希望使用Python制作一个发送短信的小工具,可以借助twilio库来实现。可以编写代码来连接twilio平台,并使用其提供的API来发送短信。可以使用以下代码作为参考: ``` from***ilio.rest import Client # Your Account SID and Auth Token from***ilio.com/console account_sid = 'your_account_sid' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) # Send a message message = client.messages.create( body='Hello, this is a test message!', from_='+1234567890', # Replace with your***ilio number to='+9876543210' # Replace with your recipient's number ) print(message.sid) ``` 在上述代码中,需要将`your_account_sid`和`your_auth_token`替换为你的twilio账号的SID和Auth Token。同时,需要将`from_`和`to`替换为正确的发送方和接收方的电话号码。这样就可以通过twilio平台发送短信了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [谁说程序员不懂浪漫?用Python每天自动给女朋友免费发短信](https://blog.csdn.net/m0_37615390/article/details/102890987)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值