class CCP(object): def __new__(cls, *args, **kwargs): if not hasattr(cls, '_instance'): # 创建实例对象 obj = super(CCP, cls).__new__(cls, *args, **kwargs) cls._instance = obj return obj 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): # 发送模板短信 # @param to 手机号码 # @param datas 内容数据 格式为数组 例如:{'12','34'},如不需替换请填 '' # @param $tempId 模板Id result = self.rest.sendTemplateSMS(to, datas, temp_id) if result.get('statusCode') == '000000': return 1 else: return 0
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) for k, v in result.iteritems(): if k == 'templateSMS': for k, s in v.iteritems(): print '%s:%s' % (k, s) else: print '%s:%s' % (k, v)