# -*- coding: utf-8 -*- import urllib import urllib2 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.urlencode(data); req = urllib2.Request(self.apiUrl+'/sms/send.do', data); res_data = urllib2.urlopen(req); res = res_data.read(); return res; def balance(self): data = { 'appId': self.appId, 'appSecret': self.appSecret } data = urllib.urlencode(data); req = urllib2.Request(self.apiUrl+'/account/balance.do', data); res_data = urllib2.urlopen(req); res = res_data.read(); return res;