def getBalance(self): """获取账户余额信息 """ os.chdir(SEM_API_PATH) retrys = 0 # 保存重试次数 accountSvr = sms_v3_AccountService() accountSvr.setUsername(self.accountName) accountSvr.setPassword(self.accountPwd) accountSvr.setToken(self.appid) #print accountSvr #print self balance = -2 while retrys < Sem_AccountInfo.API_RETRY_TIME: try: balanceInfo = accountSvr.getAccountInfo() #print balanceInfo logging.info(str(balanceInfo)) balance = balanceInfo['body']['accountInfoType']['balance'] break # 获取成功,则退出循环 except Exception as err: logging.error(traceback.format_exc()) balance = -1 # api获取失败,设置-1 time.sleep(5) finally: retrys += 1 self.balance = balance os.chdir(BASE_PATH) return balance
#coding=utf-8 import suds import traceback as tb from ApiSDKSoapClient import ApiSDKSoapClient from ApiSDKSoapClient import printSoapResponse from sms_v3_AccountService import * if __name__ == "__main__": try: service = sms_v3_AccountService() newres = service.getAccountInfo() printJsonResponse(newres) ''' # init client stub apiSDKSoapClient = ApiSDKSoapClient('sms','v3','AccountService') newClient = apiSDKSoapClient.newSoapClient() #==== get account info ==== newClient.service.getAccountInfo() # receive response and print result res = newClient.last_received() printSoapResponse(res) ''' # request = newClient.factory.create('updateAccountInfoRequest') # accountInfoType = newClient.factory.create('updateAccountInfoRequest.accountInfoType') # excludeIp = ['192.168.2.3','10.10.10.16','1.1.1.1.1.1'] # accountInfoType.excludeIp = excludeIp
#coding=utf-8 import suds import traceback as tb from ApiSDKSoapClient import ApiSDKSoapClient from ApiSDKSoapClient import printSoapResponse from sms_v3_AccountService import * if __name__ == "__main__": try: service = sms_v3_AccountService() newres = service.getAccountInfo() printJsonResponse(newres) ''' # init client stub apiSDKSoapClient = ApiSDKSoapClient('sms','v3','AccountService') newClient = apiSDKSoapClient.newSoapClient() #==== get account info ==== newClient.service.getAccountInfo() # receive response and print result res = newClient.last_received() printSoapResponse(res) ''' # request = newClient.factory.create('updateAccountInfoRequest') # accountInfoType = newClient.factory.create('updateAccountInfoRequest.accountInfoType') # excludeIp = ['192.168.2.3','10.10.10.16','1.1.1.1.1.1']