示例#1
0
    def post(self):
        try:
            self.tracker.logging_request_header(self)
            self.tracker.logging_request_body(self)

            self.token_verify()  # 验证头部签名
            self._parse_request()
            # 分发 processor
            processor = urls.processor_mapping.get(self.cmdid)
            # print processor
            if not processor:
                # 协议不存在
                raise BaseException(BaseError.ERROR_COMMON_CMD_NOT_EXISTS)
            # 协议处理
            if processor[1]:
                # 内部调用的协议
                raise BaseException(
                    BaseError.ERROR_COMMON_PROTOCOL_FOR_INTERNAL_ONLY)
            processor = processor[0]
            data = yield processor(self).process()

            # 成功
            self.res = ResponseBuilder.build_success(self, data)
        except BaseException, e:
            # 根据捕获的UFOException返回错误信息
            self.res = ResponseBuilder.build_error(self, e)
示例#2
0
    def process(self):
        '''
        process protocol
        '''

        data = self.ammodel.login_am(self.params['username'],
                                     self.params['passwd'])
        if not EncryptPassword(data[0]['passwd']).auth_password(
                self.params['passwd']):
            raise BaseException(BaseError.ERROR_PASSWORD_ERROR)
        else:
            if int(data[0]['status']) == 1:

                retdata = {
                    'am_id': data[0]['id'],
                    'is_logined': 1,
                }
                row = self.ammodel.set_login_time(self.params['username'])
                # if row:
                #     self.set_current_user(data[0]['id'])
                return_data = retdata
                return return_data
            else:
                retdata = {
                    'is_logined': 0,
                }
                return_data = retdata
                return return_data
示例#3
0
 def _verify_app_status(self, app_id):
     '''
         # 验证下游的 APP 状态是否可用
     '''
     verify_app = None
     data = self.chnmodel.verify_app_status(chn_id, app_id)[0]
     if not data:
         raise BaseException(BaseError.ERROR_APP_NOT_EXIST)
     elif int(data['app_status']) == 0 and int(data['app_status']) is None:
         raise BaseException(BaseError.ERROR_APP_VERIFY_NOT_PASS)
     elif data['chn_status'] == 0 or data['chn_status'] is None:
         raise BaseException(BaseError.ERROR_CHN_VERIFY_NOT_PASS)
     elif int(data['app_status']) == 1 and int(data['chn_status']) == 1:
         verify_app = True
         return verify_app
     else:
         raise BaseException(BaseError.ERROR_COMMON_DATABASE_EXCEPTION)
示例#4
0
class BaseHandler(tornado.web.RequestHandler):
    def __init__(self, *request, **kwargs):
        super(BaseHandler, self).__init__(request[0], request[1])
        self.set_header("Content-Type", "application/json")
        self.tracker = self.application.tracker
        self.sys_logger = self.application.sys_logger
        self.Token = None
        self.tag = None
        self.params = dict()
        self.res = dict()

    def get_current_user(self):
        return self.get_secure_cookie("user_id", 0)

    def set_current_user(self, user_id):
        if user_id:
            self.set_secure_cookie('user_id',
                                   tornado.escape.json_encode(user_id))
        else:
            self.clear_cookie("user_id")

    def clear_current_user(self):
        self.clear_cookie("user_id")

    @tornado.web.asynchronous
    @tornado.gen.coroutine
    def get(self):
        try:
            self.tracker.logging_request_header(self)
            self.tracker.logging_request_body(self)

            self.token_verify()  # 验证头部签名
            self._parse_request()
            # 分发 processor
            processor = urls.processor_mapping.get(self.cmdid)
            # print processor
            if not processor:
                # 协议不存在
                raise BaseException(BaseError.ERROR_COMMON_CMD_NOT_EXISTS)
            # 协议处理
            if processor[1]:
                # 内部调用的协议
                raise BaseException(
                    BaseError.ERROR_COMMON_PROTOCOL_FOR_INTERNAL_ONLY)
            processor = processor[0]
            data = yield processor(self).process()

            # 成功
            self.res = ResponseBuilder.build_success(self, data)
        except BaseException, e:
            # 根据捕获的UFOException返回错误信息
            self.res = ResponseBuilder.build_error(self, e)
        except DBException, e:
            # 如果是底层未处理的DBException, 在这里转化为UFOException
            self.tracker.trace_error()
            e = BaseException(BaseError.ERROR_COMMON_DATABASE_EXCEPTION)
            self.res = ResponseBuilder.build_error(self, e)
示例#5
0
 def process(self):
     data = self.offermodel.get_all_offer(self.params['page_size'], self.params['page'])
     if data:
         retdata = {
             'offers': data
         }
         return_data = retdata
         return return_data
     else:
         raise BaseException(BaseError.ERROR_COMMON_DATABASE_EXCEPTION)
示例#6
0
    def process(self):
        '''
        process protocol
        '''
        ader_id = self.params['ader_id']
        app_id = self.params['app_id']

        checkout_data = self.appmodel.get_application_tranform(app_id)
        if not checkout_data[0]['divide']:
            raise BaseException(BaseError.ERROR_DP_NOT_SETTING)
        else:
            transform_advertise = yield self.tranOffer(
                ader_id, app_id, checkout_data[0]['divide'])
示例#7
0
    def token_verify(self):

        self.Token = self.request.headers.get('X-XSRFToken')
        if not self.Token:
            raise ParamException('X-XSRFToken')
        self.tag = self.request.headers.get('tag')
        if not self.tag:
            raise ParamException('params')
        verify = getToken()
        # print self.Token, self.tag
        data = verify.get_token(self.Token, self.tag)
        if not data:
            raise BaseException(BaseError.ERROR_COMMON_ACCESS_DENIED)
示例#8
0
    def _parse_request(self):
        # json解析
        try:
            json_body = json.loads(self.request.body)
            print json_body
        except:
            raise BaseException(BaseError.ERROR_COMMON_PARSE_JSON_FAILED)

        # 设定参数字典
        self.params['tag'] = json_body.get('tag')
        # print self.params
        if not verify_utils.is_dict(self.params):
            raise ParamException('params')
示例#9
0
    def process(self):
        app_id = self.params['app_id']
        chn_id = self.params['chn_id']
        status = self.params['status']

        data = self.appmodel.get_application_detail(app_id, chn_id)
        if data:
            if data[0]['status'] == 0 or data[0]['status'] == '0' or data[0][
                    'status'] == 1 or data[0]['status'] == '1':
                row = self.appmodel.set_applicaiton_status(status, app_id)
                return_data = row
                return return_data
        else:
            raise BaseException(BaseError.ERROR_COMMON_DATABASE_EXCEPTION)
示例#10
0
 def process(self):
     '''
     process protocol
     '''
     default_expires = 24
     # print type(self.params)
     tag = self.params.get('tag')
     # print tag
     if self._verify_params(tag):
         row = self.adminmodel.set_secret_sign(tag, self.token,
                                               default_expires)
         return_data = {'token': self.token}
         return return_data
     else:
         raise BaseException(BaseError.ERROR_COMMON_ACCESS_DENIED)
示例#11
0
    def _parse_request(self):
        # json解析
        try:
            # print self.request.body
            # print self.request.body_arguments
            # print type(self.request.body)
            json_body = json.loads(self.request.body)
            # print json_body
        except:
            raise BaseException(BaseError.ERROR_COMMON_PARSE_JSON_FAILED)

        # self.params = json_body.get('chn_id')
        self.params['chn_id'] = json_body.get('chn_id')
        # print self.params
        if not verify_utils.is_dict(self.params):
            raise ParamException('chn_id')
示例#12
0
    def process(self):

        global  chn_id

        app_id = self.params.get('app_id')
        sign = self.params.get('accesskey')
        page = self.params.get('page')
        page_size = self.params.get('page_size')

        if self._verify_sign(app_id, sign) and self._verify_app_status(app_id):
            data = self.offermodel.get_offer_by_app(app_id, sign, page_size, page)
            retdata = {
                'offers': data
            }
            return_data = retdata
            return return_data
        else:
            raise BaseException(BaseError.ERROR_COMMON_UNKNOWN)
示例#13
0
    def _parse_request(self):
        # json解析
        try:
            json_body = json.loads(self.request.body)
            # print json_body
        except:
            raise BaseException(BaseError.ERROR_COMMON_PARSE_JSON_FAILED)

        # 设定参数字典
        self.params['api_name'] = json_body.get('api_name')
        self.params['name'] = json_body.get('name')
        self.params['resp_callback_url'] = json_body.get('resp_callback_url')
        self.params['resp_callback_token'] = json_body.get(
            'resp_callback_token')
        self.params['is_pulled'] = json_body.get('is_pulled')
        # print self.params
        if not verify_utils.is_dict(self.params):
            raise ParamException('params')
示例#14
0
    def _parse_request(self):
        # json解析
        try:
            json_body = json.loads(self.request.body)
            # print json_body
        except:
            raise BaseException(BaseError.ERROR_COMMON_PARSE_JSON_FAILED)

        # 设定参数字典
        self.params['app_name'] = json_body.get('app_name')
        self.params['pkg_name'] = json_body.get('pkg_name')
        self.params['category'] = json_body.get('category')
        self.params['platform'] = json_body.get('platform')
        self.params['url'] = json_body.get('url')
        self.params['description'] = json_body.get('description')
        self.params['chn_id'] = json_body.get('chn_id')
        # print self.params
        if not verify_utils.is_dict(self.params):
            raise ParamException('params')
示例#15
0
    def _parse_request(self):

        # headers 匹配
        try:
            headers = self.request.headers
            if re.search(ur'(iPhone)', str(headers)) or re.search(
                    ur'(Android)', str(headers)):
                # json解析
                try:
                    json_body = json.loads(self.request.body)
                    # print json_body
                except:
                    raise BaseException(
                        BaseError.ERROR_COMMON_PARSE_JSON_FAILED)

                # 设定参数字典
                self.params['offer_id'] = json_body.get('offer_id')
                self.params['app_id'] = json_body.get('app_id')
                self.params['app_click_id'] = json_body.get('app_click_id')
                self.params['pid'] = json_body.get('pid')
                # print self.params
                if not verify_utils.is_dict(self.params):
                    raise ParamException('params')
            else:
示例#16
0
            processor = processor[0]
            data = yield processor(self).process()

            # 成功
            self.res = ResponseBuilder.build_success(self, data)
        except BaseException, e:
            # 根据捕获的UFOException返回错误信息
            self.res = ResponseBuilder.build_error(self, e)
        except DBException, e:
            # 如果是底层未处理的DBException, 在这里转化为UFOException
            self.tracker.trace_error()
            e = BaseException(BaseError.ERROR_COMMON_DATABASE_EXCEPTION)
            self.res = ResponseBuilder.build_error(self, e)
        except Exception, e:
            self.tracker.trace_error()
            e = BaseException(BaseError.ERROR_COMMON_UNKNOWN)
            self.res = ResponseBuilder.build_error(self, e)

        # 记录响应
        self.tracker.logging_response(self)

        # 响应
        self.write(json.dumps(self.res, cls=ComplexEncoder))
        self.finish()

    @tornado.web.asynchronous
    @tornado.gen.coroutine
    def post(self):
        try:
            self.tracker.logging_request_header(self)
            self.tracker.logging_request_body(self)
示例#17
0
                    json_body = json.loads(self.request.body)
                    # print json_body
                except:
                    raise BaseException(
                        BaseError.ERROR_COMMON_PARSE_JSON_FAILED)

                # 设定参数字典
                self.params['offer_id'] = json_body.get('offer_id')
                self.params['app_id'] = json_body.get('app_id')
                self.params['app_click_id'] = json_body.get('app_click_id')
                self.params['pid'] = json_body.get('pid')
                # print self.params
                if not verify_utils.is_dict(self.params):
                    raise ParamException('params')
            else:
                raise BaseException(BaseError.ERROR_USERAGENT_NOT_MOBILE)
        except:
            raise BaseException(BaseError.ERROR_COMMON_UNKNOWN)


class CreateClickUrl(object):
    """
        http://api.bensonzhi.co/track?ad=xxxx&app_id=xxxx&pid=xxxx&click_id=xxxx
    """
    def __init__(self, app_id, ad_id, pid):
        self.ad_id = ad_id
        self.app_id = app_id
        self.pid = pid
        self.base_url = 'http://api.bensonzhi.co/v1/track'

    def createUrl(self):