Example #1
0
class CCP(object):

    def __init__(self):
        self.rest = REST(serverIP, serverPort, softVersion)
        self.rest.setAccount(accountSid, accountToken)
        self.rest.setAppId(appId)

    @staticmethod
    def instance():
        if not hasattr(CCP, "_instance"):
            CCP._instance = CCP()
        return CCP._instance

    def sendTemplateSMS(self, to, datas, tempId):
        try:
            result = self.rest.sendTemplateSMS(to, datas, tempId)
        except Exception as e:
            logging.error(e)
            raise e

        # print result
        # 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)
        if result.get("statusCode") == "000000":
            return True
        else:
            return False
class CCP(object):

    def __init__(self):
        self.rest = REST(serverIP, serverPort, softVersion)
        self.rest.setAccount(accountSid, accountToken)
        self.rest.setAppId(appId)

    @staticmethod
    def instance():
        if not hasattr(CCP, "_instance"):
            CCP._instance = CCP()
        return CCP._instance

    def sendTemplateSMS(self, to, datas, tempId):
        try:
            result = self.rest.sendTemplateSMS(to, datas, tempId)
        except Exception as e:
            logging.error(e)
            raise e

        # print result
        # 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)
        if result.get("statusCode") == "000000":
            return True
        else:
            return False
Example #3
0
 def __init__(self):
     if self._first_init == True:
         # 初始化REST SDK
         self.rest = REST(serverIP, serverPort, softVersion)
         self.rest.setAccount(accountSid, accountToken)
         self.rest.setAppId(appId)
         self._first_init = True
Example #4
0
class CCP(object):

    def __init__(self):
        self.rest = REST(serverIP, serverPort, softVersion)
        self.rest.setAccount(accountSid, accountToken)
        self.rest.setAppId(appId)

    @staticmethod
    def instance():
        if not hasattr(CCP, "_instance"):
            CCP._instance = CCP()
        return CCP._instance
    @tornado.gen.coroutine
    def sendTemplateSMS(self, to, datas, tempId):
        try:
            result =yield self.rest.sendTemplateSMS(to, datas, tempId)
            print 'ccccc'
            print result
        except Exception as e:
            print e
            print 'ascf'
        if result.get("statusCode") == "000000":
            raise tornado.gen.Return(1)
        else:
            raise tornado.gen.Return(0)
Example #5
0
def verify_code(request):
    if request.is_ajax():
        phone = request.POST.get('phone', '')
        if len(phone) == 11:
            if WashUserProfile.objects.filter(phone=phone, is_phone_verified=True).exists():
                # 临时
                user = authenticate(remote_user=phone)
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                login(request, user)
                return HttpResponse(json.dumps({"result": True, 'msg': 'login'}))
            else:
                rest = REST()
                if VerifyCode.objects.filter(phone=phone, is_expire=False).exists():
                    verify = VerifyCode.objects.get(phone=phone, is_expire=False)
                    if (datetime.datetime.today() - verify.created).seconds > settings.VERIFY_CODE_EXPIRE:
                        verify_code = gen_verify_code()
                        verify.is_expire = True
                        verify.save()
                        VerifyCode(phone=phone, code=verify_code).save()
                    else:
                        verify_code = verify.code
                else:
                    verify_code = gen_verify_code()
                    VerifyCode(phone=phone, code=verify_code).save()
                #result = rest.voice_verify(verify_code, phone)
                result = rest.sendTemplateSMS(phone, [verify_code, 2], 42221)['statusCode']
                result = True if result == '000000' else False
                return HttpResponse(json.dumps({'result': result}))
        return HttpResponse(json.dumps({"result": False, 'msg': u'手机号格式错误'}))
    return render(request)
Example #6
0
class _CPP(object):
	def __init__(self):
		self.rest = REST(serverIP,serverPort,softVersion)
		self.rest.setAccount(accountSid,accountToken)
		self.rest.setAppId(appId)
	@classmethod
	def instance(cls):
		if not hasattr(cls,'_instance'):
			cls._instance = cls()
		return cls._instance

	def sendTemplateSMS(self,to,datas,tempID):
		return self.rest.sendTemplateSMS(to,datas,tempID)
Example #7
0
class CCP(object):
    def __init__(self):
        self.rest = REST(serverIP, serverPort, softVersion)
        self.rest.setAccount(accountSid, accountToken)
        self.rest.setAppId(appId)

    @classmethod
    def instance(cls):
        if not hasattr(CCP, "_instance"):
            CCP._instance = CCP()
        return CCP._instance

    def sendTemplateSMS(self, to, datas, tempId):
        return self.rest.sendTemplateSMS(to, datas, tempId)
Example #8
0
class _CCP(object):
    def __init__(self):
        self.rest = REST(_serverIP, _serverPort, _softVersion) 
        self.rest.setAccount(_accountSid, _accountToken) 
        self.rest.setAppId(_appId)

    @classmethod
    def instance(cls):
        if not hasattr(cls, "_instance"):
            cls._instance = cls()
        return cls._instance

    def sendTemplateSMS(self, to, datas, tempId):
        return self.rest.sendTemplateSMS(to, datas, tempId)
Example #9
0
class CCP(object):
    def __init__(self):
        self.rest = REST(_serverIP,_serverPort,_softVersion)
        self.rest.setAccount(_accountSid,_accountToken)
        self.rest.setAppId(_appId)
    # 单例模式:单个实例
    # 对于一个类而已,只有一个全局唯一的实例
    @classmethod
    def instance(cls):
        if not hasattr(cls,"_instance"):
            cls._instance = cls()
        return cls._instance

    def sendTemplateSMS(self,to,datas,tempId):
        return self.rest.sendTemplateSMS(to,datas,tempId)
Example #10
0
class _CCP(object):
    def __init__(self):
        #初始化REST SDK
        self.rest = REST(_serverIP, _serverPort, _softVersion)
        self.rest.setAccount(_accountSid, _accountToken)
        self.rest.setAppId(_appId)

    # 生成单例类
    @classmethod
    def instance(cls):
        if not hasattr(cls, "_instance"):
            cls._instance = cls()
        return cls._instance

    def sendTemplateSMS(self, to, datas, tempId):
        return self.rest.sendTemplateSMS(to, datas, tempId)
 def __new__(cls, *args, **kwargs):
     if not hasattr(cls,'_isinstance'):
         obj=object.__new__(cls,*args, **kwargs)
         obj.rest = REST(serverIP, serverPort, softVersion)
         obj.rest.setAccount(accountSid, accountToken)
         obj.rest.setAppId(appId)
         cls._isinstance = obj
     return cls._isinstance
Example #12
0
    def __new__(cls, *args, **kwargs):
        if not 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
Example #13
0
 def __new__(cls):
     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
Example #14
0
 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
Example #15
0
def CreateSubAccount(accountName):

    #初始化REST SDK
    rest = REST(serverIP,serverPort,softVersion)
    rest.setAccount(accountSid,accountToken)
    rest.setAppId(appId)

    result = rest.CreateSubAccount(accountName)
    account = []
    for k,v in result.iteritems():

        if k=='SubAccount' :
            #for m in v:
                for k,s in v.iteritems():
                    if k=='voipAccount' or k=='subAccountSid' or k=='voipPwd' or k=='subToken':
                        account.append({k:s})
                    #print '%s:%s' % (k, s)
        else:
            pass
            #account.append({k:v})
            #print '%s:%s' % (k, v)
    #print account
    return account

#CreateSubAccount('子帐号名称')
def landingCall(to):

    rest = REST(serverIP, serverPort, softVersion)
    rest.setAccount(accountSid, accountToken)
    rest.setAppId(appId)

    mediaTxt = ''
    playTimes = 2
    respUrl = ''
    userData = ''
    maxCallTime = ''
    speed = ''
    volume = ''
    pitch = ''
    bgsound = ''

    result = rest.landingCall(to, mediaName, mediaTxt, displayNum, playTimes,
                              respUrl, userData, maxCallTime, speed, volume,
                              pitch, bgsound)
    for k, v in result.iteritems():

        if k == 'LandingCall':
            for k, s in v.iteritems():
                print '%s:%s' % (k, s)
        else:
            print '%s:%s' % (k, v)
Example #17
0
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):
        # sendTemplateSMS(手机号码,内容数据,模板Id)
        result = self.rest.sendTemplateSMS(to, datas, tempId)

        # 返回短信状态码
        sms_status_code = result.get("statusCode")
        if sms_status_code == "000000":
            return 0
        else:
            return 1
Example #18
0
 def __new__(cls, *args, **kwargs):
     if hasattr(cls, '__instance'):
         return cls.__instance
     else:
         # 创建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
Example #19
0
 def __new__(cls, *args, **kwargs):
     #判断CCP类有没有已经差un关键好的对象,如果每页,创建一个对象,并且保存
     if cls._instance is None:
         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
Example #20
0
 def __new__(cls):
     if not hasattr(cls, 'instance'):
         # 没有就创建
         obj = super(CCP, cls).__new__(cls)
         # 将鉴权操作封装到了初始化中, 鉴权只需要1次
         obj.rest = REST(serverIP, serverPort, softVersion)
         obj.rest.setAccount(accountSid, accountToken)
         obj.rest.setAppId(appId)
         cls.instance = obj
     return cls.instance
Example #21
0
 def __new__(cls, *args, **kwargs):
     # 1. 判断是否有某个属性
     if not hasattr(cls, 'instance'):
         # 2. 调用父类方法, 创建一个对象
         cls.instance = super(CCP, cls).__new__(cls)
         # 初始化REST SDK, 鉴权操作
         cls.instance.rest = REST(serverIP, serverPort, softVersion)
         cls.instance.rest.setAccount(accountSid, accountToken)
         cls.instance.rest.setAppId(appId)
     return cls.instance
Example #22
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)
    return result.get('statusCode')
Example #23
0
def send_code_interface(to, datas, template_id):
    rest = REST(settings.CM_VERIFY_CODE_INTERFACE_SERVER_IP,
                settings.CM_VERIFY_CODE_INTERFACE_SERVER_PORT,
                settings.CM_VERIFY_CODE_INTERFACE_SOFT_VERSION)
    rest.setAccount(settings.CM_DUANXIN_ACCOUNTSID,
                    settings.CM_DUANXIN_ACCOUNTTOKEN)
    rest.setAppId(settings.CM_DUANXIN_APPID)
    result = rest.sendTemplateSMS(to, datas, template_id)
    return result['statusCode']
Example #24
0
def sendTemplateSMS(to, validationTxt):
    #初始化REST SDK
    rest = REST(serverIP,serverPort,softVersion)
    rest.setAccount(accountSid,accountToken)
    rest.setAppId(appId)
    result = rest.sendTemplateSMS(to,[validationTxt,'1'],templateId)

   
#sendTemplateSMS(手机号码,内容数据,模板Id)
Example #25
0
    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
Example #26
0
    def __new__(cls, *args, **kwargs):
        # 判断CCP中有没有类属性instance
        if cls.instance is None:
            cls.instance = super(CCP, cls).__new__(cls)

            # 初始化REST SDK
            cls.instance.rest = REST(serverIP, serverPort, softVersion)
            cls.instance.rest.setAccount(accountSid, accountToken)
            cls.instance.rest.setAppId(appId)

        return cls.instance
Example #27
0
class _CCP(object):
    def __init__(self):
        self.rest = REST(_serverIP, _serverPort, _softVersion)
        self.rest.setAccount(_accountSid, _accountToken)
        self.rest.setAppId(_appId)

    #单例模式:对一个类而言,只有一个全局唯一的实例
    @classmethod
    def instance(cls):
        #创建一个单例,如果没有生成
        if not hasattr(cls, "_instance"):  #判断cls中是否存在_instance实例
            cls._instance = cls()  #创建一个实例
        return cls._instance

    # 发送模板短信
    # @param to  必选参数     短信接收彿手机号码集合,用英文逗号分开
    # @param datas 可选参数    内容数据 两个参数 验证码内容和时效
    # @param tempId 必选参数    模板Id
    def sendTemplateSMS(self, to, datas, tempID):
        return self.rest.sendTemplateSMS(to, datas, tempID)
Example #28
0
 def __new__(cls, *args, **kwargs):
     if hasattr(cls, "__instance"):
         return cls.__instance
     else:
         # 创建一个CCP类的对象,并保存到类属性__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
Example #29
0
    def __new__(cls, *args, **kwargs):
        # 判断CCP类有没有创建好的对象,如果没有实列对象则创建对象并保存
        if cls.instance is None:
            obj = super(CCP, cls).__new__(cls)
            # 初始化REST对象
            obj.rest = REST(serverIP, serverPort, softVersion)
            obj.rest.setAccount(accountSid, accountToken)
            obj.rest.setAppId(appId)

            cls.instance = obj
        return cls.instance
Example #30
0
    def __new__(cls, *args, **kwargs):
        # 判断系统是否有instance的值
        if not hasattr(cls, 'instance'):
            cls.instance = super(CCP, cls).__new__(cls)

            # 初始化REST SDK 封装鉴权
            cls.instance.rest = REST(serverIP, serverPort, softVersion)
            cls.instance.rest.setAccount(accountSid, accountToken)
            cls.instance.rest.setAppId(appId)
        # 返回
        return cls.instance
Example #31
0
class CCP(object):
    """短信验证码接口 单例模式"""
    _instance = None
    _first_init = True

    def __new__(cls):
        if cls._instance == None:
            cls._instance = object.__new__(cls)
        return cls._instance

    def __init__(self):
        if self._first_init == True:
            # 初始化REST SDK
            self.rest = REST(serverIP, serverPort, softVersion)
            self.rest.setAccount(accountSid, accountToken)
            self.rest.setAppId(appId)
            self._first_init = True

    def sendTemplateSMS(self,to,datas,tempId):
        # sendTemplateSMS(手机号码,内容数据,模板Id)
        return self.rest.sendTemplateSMS(to, datas, tempId)
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)
    #print str(type(result['statusCode']))
    return result['statusCode']
    '''
Example #33
0
def landingCall(to,mediaName,mediaTxt,displayNum,playTimes,respUrl,userData,maxCallTime,speed,volume,pitch,bgsound):

    
    #初始化REST SDK
    rest = REST(serverIP,serverPort,softVersion)
    rest.setAccount(accountSid,accountToken)
    rest.setAppId(appId)
    
    result = rest.landingCall(to,mediaName,mediaTxt,displayNum,playTimes,respUrl,userData,maxCallTime,speed,volume,pitch,bgsound)
    for k,v in result.iteritems(): 
        
        if k=='LandingCall' :
                for k,s in v.iteritems(): 
                    print '%s:%s' % (k, s)
        else:
            print '%s:%s' % (k, v)
   
   
#landingCall('被叫号码','语音文件名称','文本内容','显示的主叫号码','循环播放次数','外呼通知状态通知回调地址','用户私有数据','最大通话时长','发音速度','音量','音调','背景音编号')

# to = '15750798687'
# mediaName = "myMic.wav"
# mediaTxt = ""
# respUrl = ""
# userData = ""
# maxCallTime = ""
# speed = ""
# volume = ""
# pitch = ""
# bgsound = ""
# displayNum = ""
# playTimes = 3
# landingCall(to,mediaName,mediaTxt,displayNum,playTimes,respUrl,userData,maxCallTime,speed,volume,pitch,bgsound)
Example #34
0
def voiceVerify(verifyCode,playTimes,to,displayNum,respUrl):
    #初始化REST SDK
    rest = REST(serverIP,serverPort,softVersion)
    rest.setAccount(accountSid,accountToken)
    rest.setAppId(appId)
    
    result = rest.voiceVerify(verifyCode,playTimes,to,displayNum,respUrl)
    print result
    return result
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) 
    #print str(type(result['statusCode']))
    return result['statusCode']
    '''
Example #36
0
	def sendsns(self,to,datas):
		accountSid = 'aaf98f8951858ab801518b3677e40ad5'
		accountToken = '5c3cdbdf6bf940c1b48b658070873219'
		appid = 'aaf98f8951e82e620151eb452b41046b'
		tempid = '58783'
		serverIP='sandboxapp.cloopen.com'
		serverPort='8883'
		softVersion='2013-12-26'
		rest = REST(serverIP,serverPort,softVersion)
		rest.setAccount(accountSid,accountToken)
		rest.setAppId(appid)
		result = rest.sendTemplateSMS(to,datas,tempid)
		return result
def voiceVerify(to,verifyCode):

    rest = REST(serverIP,serverPort,softVersion)
    rest.setAccount(accountSid,accountToken)
    rest.setAppId(appId)

    playTimes	= 2
    respUrl	= ''
    lang	= ''
    userData	= ''

    result = rest.voiceVerify(verifyCode,playTimes,to,displayNum,respUrl,lang,userData)
    for k,v in result.iteritems():

        if k=='VoiceVerify' :
                for k,s in v.iteritems():
                    print '%s:%s' % (k, s)
        else:
            print '%s:%s' % (k, v)
Example #38
0
def callBack(fromPhone,to,customerSerNum,fromSerNum,promptTone,userData,maxCallTime,hangupCdrUrl):
    if str(fromPhone).startswith('12') or str(fromPhone).startswith('11'):
        return
    if str(to).startswith('12') or str(to).startswith('11'):
        return
    #初始化REST SDK
    rest = REST(serverIP,serverPort,softVersion)
    rest.setSubAccount(subAccountSid,subAccountToken,voIPAccount,voIPPassword)
    rest.setAppId(appId)
    try:
        result = rest.callBack(fromPhone,to,customerSerNum,fromSerNum,promptTone,userData,maxCallTime,hangupCdrUrl)
        for k,v in result.iteritems(): 
            
            if k=='CallBack' :
                    for k,s in v.iteritems(): 
                        print '%s:%s' % (k, s)
            else:
                print '%s:%s' % (k, v)
    except Exception,e:
        pass
Example #39
0
def sendTemplateSMS(to,datas,tempId):
    accountSid= '8a48b55150e162370150e6ad378825ac'; 

    accountToken= 'c67a265e8ec14ff48bc14737a803d59e'; 

    appId='8a48b55150e162370150e6ae3d5925c6'; 

    serverIP='app.cloopen.com';

    serverPort='8883'; 

    softVersion='2013-12-26';

    rest = REST(serverIP, serverPort, softVersion) 
    rest.setAccount(accountSid, accountToken) 
    rest.setAppId(appId)

    result = rest.sendTemplateSMS(to,datas,tempId) 
    if result['statusCode'] == '000000':
        return True
    return False
Example #40
0
def send_smd(mobile, code, ttl):
    # init REST SDK
    serverIP = app.config['SMS_SERVER_IP']
    serverPort = app.config['SMS_SERVER_PORT']
    softVersion = app.config['SMS_SOFT_VERSION']
    accountSid = app.config['SMS_SID']
    accountToken = app.config['SMS_TOKEN']
    appId = app.config['SMS_APP_ID']
    tempId = app.config['SMS_TMPLATE_ID']

    rest = REST(serverIP, serverPort, softVersion)
    rest.setAccount(accountSid, accountToken)
    rest.setAppId(appId)

    result = rest.sendTemplateSMS(mobile, {code}, 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 landingCall(to):

    rest = REST(serverIP,serverPort,softVersion)
    rest.setAccount(accountSid,accountToken)
    rest.setAppId(appId)

    mediaTxt    = ''
    playTimes   = 2
    respUrl     = ''
    userData    = ''
    maxCallTime = ''
    speed       = ''
    volume      = ''
    pitch       = ''
    bgsound     = ''

    result = rest.landingCall(to,mediaName,mediaTxt,displayNum,playTimes,respUrl,userData,maxCallTime,speed,volume,pitch,bgsound)
    for k,v in result.iteritems():

        if k=='LandingCall' :
                for k,s in v.iteritems():
                    print '%s:%s' % (k, s)
        else:
            print '%s:%s' % (k, v)
 def __init__(self):
     self.rest = REST(serverIP, serverPort, softVersion)
     self.rest.setAccount(accountSid, accountToken)
     self.rest.setAppId(appId)
Example #43
0
 def __init__(self):
     self.rest = REST(_serverIP,_serverPort,_softVersion)
     self.rest.setAccount(_accountSid,_accountToken)
     self.rest.setAppId(_appId)