首页 Python修行正文

Python发短信如何?非twilio(外国的打不开操蛋)

欲儿 Python修行 2020-03-19 354 0

不是用什么东西twilio


采用榛子云:http://smsow.zhenzikj.com/news/detail/16.html





自己注册然后,我的应用(想白嫖的兄弟,你放心新用户会自动创建一个应用)

image.png




得到AppID和AppSecret

send.py

#send.py
import zhenzismsclient as smsclient
client = smsclient.ZhenziSmsClient('https://sms_developer.zhenzikj.com', 'AppID', 'AppSecret')
print(client.send('15730307867', '欲儿大帅比'))

zhenzismsclient.py

import urllib.request
import urllib.parse
import ssl


class ZhenziSmsClient(object):
def __init__(self, apiUrl, appId, appSecret):
self.apiUrl = apiUrl
self.appId = appId
self.appSecret = appSecret

def send(self, number, message, messageId=''):
data = {
'appId': self.appId,
'appSecret': self.appSecret,
'message': message,
'number': number,
'messageId': messageId
}

data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(self.apiUrl+'/sms/send.do', data=data)
context = ssl._create_unverified_context()
res_data = urllib.request.urlopen(req, context=context)
res = res_data.read()
res = res.decode('utf-8')
return res

def balance(self):
data = {
'appId': self.appId,
'appSecret': self.appSecret
}
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(self.apiUrl+'/account/balance.do', data=data)
res_data = urllib.request.urlopen(req)
res = res_data.read()
return res

def findSmsByMessageId(self, messageId):
data = {
'appId': self.appId,
'appSecret': self.appSecret,
'messageId': messageId
}
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(self.apiUrl+'/smslog/findSmsByMessageId.do', data=data)
res_data = urllib.request.urlopen(req)
res = res_data.read()
return res



两个文件放到一个目录下运行send.py就行



转载转载:https://blog.csdn.net/weixin_40576010/article/details/89976773

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论