예제 #1
0
    def post(self, mobile, code, seconds, param_sign, token):
        """

        :param mobile: 手机号码
        :param code: 验证码
        :param seconds: 有效时间
        :param param_sign: 参数验证
        :param token:令牌
        :return:
        """
        if not valid_phone(mobile):
            return {'result': 'FAIL', 'reason': 'INVALID_MOBILE'}
        checked = False
        if param_sign and not Signer().check_sign(param_sign, mobile, code, seconds):
            checked = True
        if not checked and token:
            register_setting = ServiceMgrCacher.find_service(US_REGISTER)
            if not register_setting:
                return
            tcp_client = TcpRpcClient(str(register_setting['ip']), register_setting['port']['tcp'])
            result = tcp_client.fetch_async('verify_access_token', token)
            if result['result'] == error_code.ERROR_SUCCESS:
                checked = True
        if not checked:
            return {'result': 'FAIL', 'reason': 'INVALID_VERIFICATION'}

        http_client = HttpRpcClient()
        headers = {
            'Accept': 'application/json',
            'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
        }

        msg = {
            'apiKey': API_KEY,
            'appId': APP_ID,
            'templateId': TEMPLATE['GENERAL'],
            'mobile': mobile,
            'param': '%s,%s' % (code, seconds2minutes(seconds))
        }
        body = ujson.dumps(msg)
        result = ujson.loads(http_client.fetch_async(URL, headers, body))
        return result
예제 #2
0
 def new_connection(ip, port, protocol=PT_TCP):
     """
     新连接
     :param ip:服务器ip
     :param port:服务器端口
     :param protocol:服务器协议
     """
     logger.warn("ServiceMgrCacher::new_connection %s %s:%s!!!" %
                 (protocol, ip, port))
     if protocol == PT_TCP:
         return TcpRpcClient(str(ip), int(port))
     elif protocol == PT_HTTP:
         return HttpRpcClient(str(ip), int(port))
     elif protocol == PT_HTTPS:
         return HttpRpcClient(str(ip), int(port), True)
     else:
         return None
예제 #3
0
class ParamCacher(object):
    __metaclass__ = Singleton

    @property
    def sm_ip(self):
        return ArgumentParser().args.sm_ip

    @property
    def is_sm_local(self):
        return self.sm_ip == get_cur_ip()

    @property
    def sm_rpc(self):
        _sm_rpc = self.__dict__.get("_sm_rpc", None)
        if not _sm_rpc:
            self._sm_rpc = TcpRpcClient(self.sm_ip, SM_TCP_PORT)
            assert self._sm_rpc.ping()
        return self._sm_rpc

    @property
    def redis_client(self):
        return self.__dict__.get("_redis_client", None)

    @redis_client.setter
    def redis_client(self, redis_client):
        self.__dict__['_redis_client'] = redis_client

    @property
    def db_instance(self):
        return self.__dict__.get("_db_instance", None)

    @db_instance.setter
    def db_instance(self, db_instance):
        self.__dict__['_db_instance'] = db_instance

    @property
    def orm_engine(self):
        return self.__dict__.get("_orm_engine", None)

    @orm_engine.setter
    def orm_engine(self, orm_engine):
        self.__dict__['_orm_engine'] = orm_engine
예제 #4
0
class ParamCacher(object):
    __metaclass__ = Singleton

    @property
    def sm_ip(self):
        return ArgumentParser().args.sm_ip

    @property
    def is_sm_local(self):
        return self.sm_ip == get_cur_ip()

    @property
    def sm_rpc(self):
        _sm_rpc = self.__dict__.get("_sm_rpc", None)
        if not _sm_rpc:
            self._sm_rpc = TcpRpcClient(self.sm_ip, SM_TCP_PORT)
            assert self._sm_rpc.ping()
        return self._sm_rpc

    @property
    def redis_client(self):
        return self.__dict__.get("_redis_client", None)

    @redis_client.setter
    def redis_client(self, redis_client):
        self.__dict__['_redis_client'] = redis_client

    @property
    def db_instance(self):
        return self.__dict__.get("_db_instance", None)

    @db_instance.setter
    def db_instance(self, db_instance):
        self.__dict__['_db_instance'] = db_instance

    @property
    def orm_engine(self):
        return self.__dict__.get("_orm_engine", None)

    @orm_engine.setter
    def orm_engine(self, orm_engine):
        self.__dict__['_orm_engine'] = orm_engine
예제 #5
0
 def sm_rpc(self):
     _sm_rpc = self.__dict__.get("_sm_rpc", None)
     if not _sm_rpc:
         self._sm_rpc = TcpRpcClient(self.sm_ip, SM_TCP_PORT)
         assert self._sm_rpc.ping()
     return self._sm_rpc
예제 #6
0
 def sm_rpc(self):
     _sm_rpc = self.__dict__.get("_sm_rpc", None)
     if not _sm_rpc:
         self._sm_rpc = TcpRpcClient(self.sm_ip, SM_TCP_PORT)
         assert self._sm_rpc.ping()
     return self._sm_rpc