接口文档

秒赛为开发者提供了详细的API文档和代码示例,帮助开发者快速接入短信平台

Python短信接口_Python短信发送代码示例

2020-03-10 14:51:44 栏目:代码示例 查看( )
本文分享PYTHON短信接口代码,为方便用户接入网站/app/各种系统,感兴趣的小伙伴们可以参考一下。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import requests
import json
import hashlib
import time
 
class SendCode:
 
    def send(self,account,pswd,mobile,msg,ts,state):
        url = 'http://139.196.108.241:8080'+{
            1:'/Api/HttpSendSMYzm.ashx',
            2:'/Api/HttpSendSMYx.ashx',
            3:'/Api/HttpSendSMVoice.ashx'
        }[state];
        if ts!="" :
            = hashlib.md5()
            strs = account+pswd+str(ts)
            m.update(strs.encode("utf8"))
            pswd = m.hexdigest()
        body = {"account": account, "pswd": pswd, "mobile": mobile,"msg":msg,"ts":str(ts)}
 
        header_dict = {'User-Agent''Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko',
                       "Content-Type""application/x-www-form-urlencoded"}
 
        response = requests.post(url, data=body,headers = header_dict)
 
        return  json.loads( response.text)
 
 
# account 用户账号
# pswd 必填参数。用户密码
# mobile 必填参数。合法的手机号码
# msg  必填参数。短信内容
# ts  可选参数,时间戳,格式yyyyMMddHHmmss
# state 必填参数   状态  1:验证码短信  2:营销短信  3:语音验证码
 
 
send = SendCode()
res = send.send('您的账号','您的密码','手机号','短信内容',  (int(time.time())),1)
# print(res['result'])
 

微信扫一扫

认证、签名模板审核结果通知

账号短信余额不足提醒

平台促销活动及最新资讯

郑重申明:①任何个人和或机构在未经过本人同意的情况下,不得擅自转载或大段引用到网站或者第三方平台使用,对于擅自盗用文章将通过法律诉讼途径等一切手段来解决!②部分素材来源于互联网,如有侵权,请联系作者删除!