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
示例#2
0
 def __new__(cls, *args, **kwargs):
     if cls._isinstance == None:
         cls._isinstance = super(ScpS, cls).__new__(cls,*args,**kwargs)
         cls._isinstance.rest = REST(serverIP, serverPort, softVersion)
         cls._isinstance.rest.setAccount(accountSid, accountToken)
         cls._isinstance.rest.setAppId(appId)
     return cls._isinstance
示例#3
0
文件: sms.py 项目: yjn1207/iHome
 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
示例#4
0
 def __new__(cls, *args, **kwargs):
     if not hasattr(cls, "_instance"):
         # 初始化一个对象,并且使用类身上的属性 `_instance` 进行记录
         cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs)
         # 比这个对象身上添加一个rest属性
         cls._instance.rest = REST(serverIP, serverPort, softVersion)
         # 设置rest的相关属性
         cls._instance.rest.setAccount(accountSid, accountToken)
         cls._instance.rest.setAppId(appId)
     return cls._instance
示例#5
0
class CCP(object):
    """封装单例类,用于统一的发送短信验证码"""
    def __new__(cls, *args, **kwargs):
        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_sms_code(self, to, datas, tempId):
        """发送短信验证码的实例方法"""

        result = self.rest.sendTemplateSMS(to, datas, tempId)
        # 判断发送短信是否成功
        if result.get('statusCode') == '000000':
            # 这里的返回值是给调用者判断发送短信是否成功的
            return 1
        else:
            return 0

#
# # 发送模板短信
# # @param to 手机号码
# # @param datas 内容数据 格式为数组 例如:{'12','34'},如不需替换请填 ''
# # @param $tempId 模板Id
# 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)
#
# # 向17600992168发送短信验证码,内容为666666,5分钟后过期,使用id为1的模板
# sendTemplateSMS('17554333135', ['666666', '5'], '1')
示例#6
0
文件: sms.py 项目: patronsbai/yidian
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)
 def __init__(self):
     # 初始化模板短信
     # 初始化REST SDK
     self.rest = REST(serverIP, serverPort, softVersion)
     self.rest.setAccount(accountSid, accountToken)
     self.rest.setAppId(appId)