class ccpa(object): def __new__(cls, *args, **kwargs): # 定义单例初始化方法 # 判断单例师傅存在 _instance中储存的就是单例 if not hasattr(cls, '_instance'): # 如果没有就初始化单例 cls._instance = super(ccpa, 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_sms(self, to, datas, tempId): # 再定义发送短信单例方法 result = self.rest.sendTemplateSMS(to, datas, tempId) print(result) # 判断结果 if result.get('statusCode') == '000000': return 0 # 成功返回 0 else: return 1