接口文檔

秒賽為開發(fā)者提供了詳細(xì)的API文檔和代碼示例,幫助開發(fā)者快速接入短信平臺(tái)

Python短信接口_Python短信發(fā)送代碼示例

2020-03-10 14:51:44 欄目:代碼示例 查看( )
本文分享PYTHON短信接口代碼,為方便用戶接入網(wǎng)站/app/各種系統(tǒng),感興趣的小伙伴們可以參考一下。

#!/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 用戶賬號(hào)
# pswd 必填參數(shù)。用戶密碼
# mobile 必填參數(shù)。合法的手機(jī)號(hào)碼
# msg  必填參數(shù)。短信內(nèi)容
# ts  可選參數(shù),時(shí)間戳,格式y(tǒng)yyyMMddHHmmss
# state 必填參數(shù)   狀態(tài)  1:驗(yàn)證碼短信  2:營銷短信  3:語音驗(yàn)證碼
 
 
send = SendCode()
res = send.send('您的賬號(hào)','您的密碼','手機(jī)號(hào)','短信內(nèi)容',  (int(time.time())),1)
# print(res['result'])
 

微信掃一掃

認(rèn)證、簽名模板審核結(jié)果通知

賬號(hào)短信余額不足提醒

平臺(tái)促銷活動(dòng)及最新資訊

鄭重申明:①任何個(gè)人和或機(jī)構(gòu)在未經(jīng)過本人同意的情況下,不得擅自轉(zhuǎn)載或大段引用到網(wǎng)站或者第三方平臺(tái)使用,對(duì)于擅自盜用文章將通過法律訴訟途徑等一切手段來解決!②部分素材來源于互聯(lián)網(wǎng),如有侵權(quán),請聯(lián)系作者刪除!