python的短信接口调用代码示例模板

这篇文章主要为大家分享PYTHON短信接口代码,PYTHON短信发送、PYTHON批量发送、PYTHON短信验证码发送,感兴趣的小伙伴们可以参考一下。
支持语言:PYTHON
功能:PYTHON短信接口、PYTHON发送短信
用途:短信验证码、会员营销短信、各类通知短信

注意事项:该代码仅供接入秒赛短信接口参考使用,客户可根据实际需要自行编写;

#!/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'])

猜你喜欢

转载自blog.csdn.net/qq_42388208/article/details/80667915