class CCP(object): def __init__(self): # 初始化REST SDK self.rest = REST(serverIP, serverPort, softVersion) self.rest.setAccount(accountSid, accountToken) self.rest.setAppId(appId) def send_template_sms(self,to, datas, tempId): result = self.rest.sendTemplateSMS(to, datas, tempId) if result.get('statusCode') == '000000': return 1 #发送成功 else: return 0 #发送失败
def __new__(cls, *args, **kwargs): if not hasattr(cls, "_instance"): cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs) cls._instance.rest = REST(serverIP, serverPort, softVersion) cls._instance.rest.setAccount(accountSid, accountToken) cls._instance.rest.setAppId(appId) return cls._instance
def __new__(cls, *args, **kwargs): # 判断是否存在类属性_instance,_instance是类CCP的唯一对象,即单例 if not hasattr(CCP, "_instance"): cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs) cls._instance.rest = REST(_serverIP, _serverPort, _softVersion) cls._instance.rest.setAccount(_accountSid, _accountToken) cls._instance.rest.setAppId(_appId) return cls._instance
def __new__(cls, *args, **kwargs): if not cls.__instance: obj = super().__new__(cls, *args, **kwargs) # 初始化REST SDK obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.__instance = obj return cls.__instance
class CCP(object): '''自己封装的发送短信的辅助类''' def __init__(self): # 初始化REST SDK self.rest = REST(serverIP, serverPort, softVersion) self.rest.setAccount(accountSid, accountToken) self.rest.setAppId(appId) def send_Template_sms(self, to, datas, temp_Id): # 初始化REST SDK result = self.rest.sendTemplateSMS(to, datas, temp_Id) for k, v in result.items(): if k == 'templateSMS': for k, s in v.items(): print('%s:%s' % (k, s)) else: print('%s:%s' % (k, v))
def __new__(cls): if cls.isinstance is None: obj=super(CCP,cls).__new__(cls) # 初始化REST SDK obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.isinstance=obj return obj
def __new__(cls, *args, **kwargs): # 判断ccp类有没有已经创建好的对象,如果没有,创建一个对象,并保存 # 如果有,则将保存的对象直接返回 if cls.instance is None: obj = super(CCP, cls).__new__(cls) obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.instance = obj return cls.instance
def __new__(cls, *args, **kwargs): if cls.__instance is None: #没被实例化,记录第一次实例对象 cls.__instance=super(CCP, cls).__new__(cls,*args, **kwargs) # 初始化REST SDK cls.__instance.rest = REST(serverIP, serverPort, softVersion) cls.__instance.rest.setAccount(accountSid, accountToken) cls.__instance.rest.setAppId(appId) return cls.__instance
def __new__(cls): # 判断CCP类有没有已经创建好的类,如果没有,创建一个并保存 # 如果有, 则将保存对象直接返回 if cls.instance is None: obj = super(CCP, cls).__new__(cls) # 初始化REST SDK obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.instance = obj return cls.instance
def __new__(cls, *args, **kwargs): #判断cls是否有_instance属性,如果没有创建对象属性 if not hasattr(cls,"_instance"): cls._instance = super(CCP, cls).__new__(cls,*args,**kwargs) # 初始化REST SDK cls._instance.rest = REST(serverIP, serverPort, softVersion) cls._instance.rest.setAccount(accountSid, accountToken) cls._instance.rest.setAppId(appId) return cls._instance return cls._instance
def __new__(cls, *args, **kwargs): if cls.__instance is None: # 判断cpp类有没有已经创建的对象,如果没有创建一个对象,并且保存 # 如果有返回保存的对象 cls.__instance=super(CCP, cls).__new__(cls,*args, **kwargs) # 初始化EST SDK cls.__instance.rest = REST(serverIP, serverPort, softVersion) cls.__instance.rest.setAccount(accountSid, accountToken) cls.__instance.rest.setAppId(appId) return cls.__instance
def __new__(cls, *args, **kwargs): # 判断cls是否拥有属性_instance,此属性用来保存这个类的唯一对象(单例对象) if not hasattr(cls,"_instance"): # 创建一个单例对象 obj = super(CCP, cls).__new__(cls, *args, **kwargs) # 初始化REST SDK obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls._instance = obj # 直接返回 return cls._instance
def __new__(cls): # 初始化REST SDK # 判断CCP类是否创建好了对象,如果没有创建,就创建一个 # 如果创建好了,则将保存的对象直接返回 if cls.instance is None: obj = super(CCP, cls).__new__(cls) # 初始化数据 REST SDk obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.instance = obj return cls.instance
class CCP(object): def __init__(self): # 初始化REST SDK self.rest = REST(serverIP, serverPort, softVersion) self.rest.setAccount(accountSid, accountToken) self.rest.setAppId(appId) # 发送模板短信 # @param to 手机号码 # @param datas 内容数据 格式为数组 例如:{'12','34'},如不需替换请填 '' # @param $tempId 模板Id def send_template_sms(self, to, datas, tempId): result = self.rest.sendTemplateSMS(to, datas, tempId) if result.get('statusCode') == '000000': # 发送成功 return 1 else: # 发送失败 return 0
def __new__(cls): # 判断CCP类有没有创建好的对象,如果没有,创建一个对象,如果有,直接返回 if cls.instance is None: obj = super(CCP, cls).__new__(cls) # 初始化REST yuntongxun obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.instance = obj return cls.instance
def __new__(cls): if not hasattr(cls, "instance"): # 判断该类中有没有类属性instance # 如果没有类属性instance,重写父类的方法,并设置对象属性 obj = super().__new__(cls) # 初始化REST SDK obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.instance = obj return cls.instance
def __new__(cls): # 判断CCP类有没有已经创建好的对象,如果没有,创建一个对象,并且保存 # 如果有,则将保存的对象直接返回 if cls.instance is None: obj = super(CCP, cls).__new__(cls) # 初始化REST SDK from ihome.libs.yuntongxun.CCPRestSDK import REST obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) cls.instance = obj return cls.instance
def __new__(cls): """单例方法,减少原有请求REST的次数,请求一次,之后直接返回""" # 判断CCP类有没有已经创建的对象,如果没有,创建一个对象,并且保存 if cls.instance is None: obj = super(CCP, cls).__new__(cls) # 初始化REST SDK obj.rest = REST(serverIP, serverPort, softVersion) obj.rest.setAccount(accountSid, accountToken) obj.rest.setAppId(appId) # 设置类属性创建类对象 cls.instance = obj # 如果有,则将保存的对象直接返回 return cls.instance
def __init__(self): # 初始化REST SDK self.rest = REST(serverIP, serverPort, softVersion) self.rest.setAccount(accountSid, accountToken) self.rest.setAppId(appId)