短信接口代码接入示例(Python)
发布日期:
2020-04-16
浏览次数:
0

简介: 短信接口代码接入Python示例



#!/usr/bin/python

#coding:gbk

#exp #python smsapi.py '接口Python示例'

 

import requests,sys,time

import sys

import time

 

#coding is Error so

default_encoding = 'GBK'

if sys.getdefaultencoding() != default_encoding:

    reload(sys)

    sys.setdefaultencoding(default_encoding)

 

#get localtime 2014-7-11 10:01:01 

ltime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))

 

#说明: http://www.ems88.cn:8080/sms/Send.do?spId=123&loginName=xxxxx&password=xxxx&content=1233&mobiles=13712345678&subPort=

Content = str(sys.argv[1])

payload = {

    'spId':'999',

    'loginName':'999',

    'password':'123456789',

    'mobiles':'13912345678',

    'content':'验证码:9090【路幻】'

}

 

#send msmbao message to phone

r = requests.get('http://www.ems88.cn:8080/sms/Send.do',params=payload)

date = ltime + '\t' + Content + '\t' + r.text + '\n'

 

f = open('sms.log','a')

#write log to sms.log

try:

    f.write(date)

    f.close()

except IOError,e:

    sys.exit()