def __new__(cls, *args, **kwargs): 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): # 判断是否存在类属性_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 sendTemplateSMS(to, datas, tempId): # 初始化REST SDK rest = REST(_serverIP, _serverPort, _softVersion) rest.setAccount(_accountSid, _accountToken) rest.setAppId(_appId) result = rest.sendTemplateSMS(to, datas, tempId)
def __new__(cls, *args, **kwargs): if not hasattr(cls, "_instants"): cls._instants = super(CCP, cls).__new__(cls, *args, **kwargs) # 单例在使用完会销毁,那么当我们初始化发送短信验证的的对象后,也需要销毁 cls._instants.rest = REST(_serverIP, _serverPort, _softVersion) cls._instants.rest.setAccount(_accountSid, _accountToken) cls._instants.rest.setAppId(_appId) return cls._instants
def __new__(cls, *args, **kwargs): # new方法初始化并提供单例 # 判断是否存在类属性_instance,_instance是类CCP的唯一对象,即单例 # hasattr('要判断的类对象', '单例属性名') if not hasattr(CCP, "_instance"): # 如果没有单例,就new一个 # cls:表示当前类对象CCP,我们将创建出来的对象绑定到CCP cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs) # rest = REST(_serverIP, _serverPort, _softVersion) # cls._instance.rest = rest # 初始化REST_SDK:保证rest对象跟单例是同生共死的 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): """ 定义单例的初始化方法 :return: 单例 """ # 判断单例是否存在:_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
def send_template_sms(to, datas, tempId): """ 云通讯官方提供的发送短信代码实例 :param to: 手机号码 :param datas: 内容数据 格式为列表 例如:['123456', '5'],如不需替换请填 '' :param tempId: 模板Id :return: 成功、失败 """ # 初始化REST SDK rest = REST(_serverIP, _serverPort, _softVersion) rest.setAccount(_accountSid, _accountToken) rest.setAppId(_appId) # 调用发送短信的接口函数 result = rest.sendTemplateSMS(to, datas, tempId) print(result)