def generate_test_data():
    """生成测试数据
    """
    # 填充外层包
    req_pack = packet.ReqPacket()
    req_pack.mask = 0
    req_pack.reqNo = 0
    req_pack.clientId = 1
    req_pack.udi = 'bd=l9k3vg16t3&md=unktraqexx&mf=52sem0qx0i&ei=hvr5frepbt&la=zh-cn&ai=9g8xkioj9n&wm=30:5a:3a:15:44:71&de=msm8226&sw=480&si=4ln5oxhhxb&sh=800&ui=q4z453p3cj&pv=a2ixx8t0ox&nt=1&pl=14'

    # 填充内部包
    # request = proto_packet.ReqUpdate()
    # request.packName = 'com.niuwan.launcher'
    # request.verName = '5.00.10.90'
    # request.verCode = 0
    # req_pack.action.append('ReqUpdate')
    # req_pack.params.append(request.SerializeToString())

    # 填充内部包
    request = proto_packet.ReqUpdate()
    request.packName = 'com.cs.appstore'
    request.verName = '6.01.14.20'
    request.verCode = 172
    req_pack.action.append('ReqUpdate')
    req_pack.params.append(request.SerializeToString())


    return req_pack.SerializeToString()
Exemple #2
0
 def test_parse(self, content):
     self.req_packet = packet.RspPacket()
     self.req_packet.ParseFromString(content)
     action = self.req_packet.action
     params = self.req_packet.params
     for i in xrange(len(action)):
         if action[i] == "RspAppInfo":
             rsp_appinfo = proto_packet.RspAppInfo()
             rsp_appinfo.ParseFromString(params[i])
             if rsp_appinfo.appInfo:
                 appinfo = proto_packet.AppInfo()
                 appinfo.ParseFromString(rsp_appinfo.appInfo)
                 print appinfo.appId
                 print appinfo.appTagFlag
Exemple #3
0
    def run(self):
        """开始协议处理(解析总包,提取出子包,分发给相应的类处理)

        参数:

        - finish_fuc:处理完所有包时的回调函数,用以结束请求

        返回:None
        """
        action_len = len(self.req_packet.action)
        self.dealing = action_len
        # self.finish_fuc = finish_fuc

        err_num = 0
        res_package = packet.RspPacket()
        for i in xrange(action_len):
            action = self.req_packet.action[i]
            params = self.req_packet.params[i]
            self.req_actions.append(action[3:])

            rsp_action = 'Rsp' + action[3:]
            rsp_param = ''
            try:
                self.comm_params['reqaction'] = action  # 用于记录统计数据
                self.comm_params['reqactno'] = i + 1
                handler = self.proto_map[action]()  # 初始化协议处理器
                handler.logger = self.logger
                handler.stat = self.stat
                handler.initialize(action, self.comm_params, params)
                handler.raw_request = self.tornado_handler
                yield handler.deal()
                rsp_param = handler.response.SerializeToString()
                handler.comm_params.update({'resaction': rsp_action})
                # 20150502 统计日志中增加响应码字段
                handler.comm_params.update(
                    {'rescode': handler.response.rescode})
                if IS_AUTO_LOG:
                    self.stat.record(handler.comm_params)  # 写统计日志
            except ProtoParseException, e:
                # 协议解析错误
                self.logger.write('run ProtoParseException [%s]' % action, e)
                err_num = err_num + 1
            except Exception, e:
                self.logger.write('run Exception [%s]' % action, e)
                err_num = err_num + 1
Exemple #4
0
 def get_header_comm_args(self):
     """ 解析header的通传参数
     """
     pack_content = self.request.headers.get("nw-header", None)
     if pack_content:
         import base64
         import proto.Packet_pb2 as packet
         de_pack_content = base64.b64decode(pack_content)
         req_packet = packet.ReqPacket()
         req_packet.ParseFromString(de_pack_content)
         udi = req_packet.udi
         com_param = baseutil.urldecode(udi)
         com_param['clientid'] = req_packet.clientId
         com_param['clientpos'] = req_packet.clientPos
         com_param['clientver'] = req_packet.clientVer
         com_param['rsakeyver'] = req_packet.rsaKeyVer
         com_param['chnno'] = req_packet.chnNo
         com_param['chnpos'] = req_packet.chnPos
         com_param['reqno'] = req_packet.reqNo
         com_param['ip'] = baseutil.get_real_ip(self)
         com_param['logno'] = baseutil.get_log_session(self)
         return com_param
Exemple #5
0
    def __init__(self, pack_content, tornado_handler=None):
        """构造函数

        参数:

        - pack_content:协议请求包序列化后的字符串内容

        - tornado_handler:Tornado入口Handler(用以取通传参数)
        """
        import protoroutes

        self.req_packet = packet.ReqPacket()
        self.req_packet.ParseFromString(pack_content)
        self.proto_map = protoroutes.HANDLER_MAP
        self.res_packages = {}  # 响应包
        self.res_comm_params = {}  # 响应包的通传参数
        self.req_actions = []
        self.dealing = 0  # 正在处理的包数量
        self.tornado_handler = tornado_handler
        self.comm_params = self.get_com_param(tornado_handler)  # 通传参数
        # logger.initial_log(config.GLOBAL_SETTINGS['logger'])
        self.logger = tornado_handler.logger # logger.GlobalLogger()
        self.stat = tornado_handler.stat
Exemple #6
0
def get_test_post_data():
    """获取模拟的测试数据
    """

    #import libs.pinyin as pinyin
    #py_module = pinyin.PinYin()
    #py_module.load_word()

    req_pack = packet.ReqPacket()
    req_pack.mask = 1
    req_pack.udi = 'ei=9870&ui=5&ai=1&wm=abcde&si=154565&mf=colorful&bd=onda&pv=11'
    req_pack.clientId = 13
    req_pack.clientVer = '4.09.25.90'

    ## 填充内部包  订单通知状态
    #request = proto_packet.ReqAppInform()
    #request.appId = 12
    #request.informType = '1,2'
    #request.informDetail = ''
    #req_pack.action.append('ReqAppInform')
    #req_pack.params.append(request.SerializeToString())

    global_config = apps.ReqGlobalConfig()
    global_config.groupsCacheVer = ''
    req_pack.action.append('ReqGlobalConfig')
    req_pack.params.append(global_config.SerializeToString())

    group_elem = apps.ReqGroupElems()
    group_elem.groupId = 101
    group_elem.pageSize = 30
    group_elem.pageIndex = 1
    req_pack.action.append('ReqGroupElems')
    req_pack.params.append(group_elem.SerializeToString())

    group_elem = apps.ReqGroupElems()
    group_elem.groupId = 93
    group_elem.pageSize = 30
    group_elem.pageIndex = 1
    req_pack.action.append('ReqGroupElems')
    req_pack.params.append(group_elem.SerializeToString())

    group_elem = apps.ReqGroupElems()
    group_elem.groupId = 100
    group_elem.pageSize = 30
    group_elem.pageIndex = 1
    req_pack.action.append('ReqGroupElems')
    req_pack.params.append(group_elem.SerializeToString())

    # apps_update = apps.ReqAppsUpdate()
    # #apps_update.checkUpdateType = 2
    # local = apps_update.localAppVer.add()
    # local.packName = 'com.teatimesgames.snowball'
    # local.verName = '0.1'
    # local.verCode = 1
    # local.signCode = ''
    # req_pack.action.append('ReqAppsUpdate')
    # req_pack.params.append(apps_update.SerializeToString())

    #app_search = apps.ReqAppList4SearchKey()
    #app_search.SearchKeyStr = u'百度输入法'
    #app_search.appClass = 0
    #app_search.appType = 0
    #app_search.isHotKey = 0
    #app_search.pageSize = 20
    #app_search.pageIndex = 1
    #app_search.orderType = 0
    #req_pack.action.append('ReqAppList4SearchKey')
    #req_pack.params.append(app_search.SerializeToString())

    #user_apps =  apps.ReqUserApps()
    #local =  user_apps.localAppVer.add()
    #local.packName = 'com.android.GameLua.pada'
    #local.verName = '1.6'
    #local.verCode = 1
    #req_pack.action.append('ReqUserApps')
    #req_pack.params.append(user_apps.SerializeToString())

    #down_res = apps.ReqDownRes()
    #down_res.appId = 101459
    #down_res.packId = 101459
    #down_res.downloadRes = 0
    #req_pack.action.append('ReqDownRes')
    #req_pack.params.append(down_res.SerializeToString())

    #app_info = apps.ReqAppInfo()
    #app_info.appId = 101469
    #app_info.packId = 0
    #req_pack.action.append('ReqAppInfo')
    #req_pack.params.append(app_info.SerializeToString())

    # 封包
    req_pack.reqNo = 1
    return req_pack.SerializeToString()
Exemple #7
0
#
#    Google Buffer
#

reqNo = 0
mask = 0
udi = 'ei=352272016759242'

action = 'ReqTest'
inner_pack = totest.ReqTest()
inner_pack.name = 'zhicong'
# inner_pack.age = 25
param = inner_pack.SerializeToString()
# param2 = inner_pack.SerializeToString()

pack = packet.ReqPacket()
pack.mask = mask
pack.udi = udi
pack.reqNo = 0
pack.clientId = 111
pack.action.append(action)
pack.params.append(param)

http_body = pack.SerializeToString()

res = post('http://127.0.0.1:8090/api', http_body)
res_pack = packet.RspPacket()
res_pack.ParseFromString(res)

if res_pack.rescode == 0:
    res_inner_pack = totest.RspTest()
 def write(self, msg):
     #print msg
     rsp = packet.RspPacket()
     rsp.ParseFromString(msg)
     result = self.print_obj(rsp)
     BaseHandler.write(self, result)
Exemple #9
0
def generate_test_data():
    """生成测试数据
    """
    # 填充外层包
    req_pack = packet.ReqPacket()
    req_pack.mask = 0
    req_pack.reqNo = 0
    req_pack.clientId = 6
    req_pack.clientVer = '5.09.25.70'
    req_pack.udi = 'bd=l9k3vg16t3&md=ASUS_Z00UDB&mf=52sem0qx0i&ei=hvr5frepbt&la=zh-cn&ai=9g8xkioj9n&wm=f8dt0mjbwb&de=msm8226&sw=480&si=4ln5oxhhxb&sh=800&ui=q4z453p3cj&pv=a2ixx8t0ox&nt=1&pl=14&oi=222'

    # 填充内部包
    # request = proto_packet.ReqTest()
    # request.name = 'cong2'
    # request.age = 20
    # req_pack.action.append('ReqTest')
    # req_pack.params.append(request.SerializeToString())

    # 填充内部包
    # request = proto_packet.ReqTest()
    # request.name = 'cong3'
    # request.age = 22
    # req_pack.action.append('ReqTest')
    # req_pack.params.append(request.SerializeToString())

    # GlobalConfig
    # request = proto_packet.ReqGlobalConfig()
    # req_pack.action.append('ReqGlobalConfig')
    # req_pack.params.append(request.SerializeToString())

    # group_elem
    # request = proto_packet.ReqGroupElems()
    # request.groupId = 45
    # request.pageSize = 30
    # request.pageIndex = 1
    # req_pack.action.append('ReqGroupElems')
    # req_pack.params.append(request.SerializeToString())

    # global_config = proto_packet.ReqGlobalConfig()
    # global_config.groupsCacheVer = ''
    # req_pack.action.append('ReqGlobalConfig')
    # req_pack.params.append(global_config.SerializeToString())

    group_elem = proto_packet.ReqGroupElems()
    group_elem.groupId = 101
    group_elem.pageSize = 30
    group_elem.pageIndex = 1
    req_pack.action.append('ReqGroupElems')
    req_pack.params.append(group_elem.SerializeToString())

    # group_elem = proto_packet.ReqGroupElems()
    # group_elem.groupId = 93
    # group_elem.pageSize = 30
    # group_elem.pageIndex = 1
    # req_pack.action.append('ReqGroupElems')
    # req_pack.params.append(group_elem.SerializeToString())

    # group_elem = proto_packet.ReqGroupElems()
    # group_elem.groupId = 100
    # group_elem.pageSize = 30
    # group_elem.pageIndex = 1
    # req_pack.action.append('ReqGroupElems')
    # req_pack.params.append(group_elem.SerializeToString())

    # appinfo
    # request = proto_packet.ReqAppInfo()
    # request.appId = 125816
    # request.packId = 0
    # req_pack.action.append('ReqAppInfo')
    # req_pack.params.append(request.SerializeToString())

    # # search
    # request = proto_packet.ReqAppList4SearchKey()
    # request.SearchKeyStr = u'泡泡连击'
    # request.appClass = 0
    # request.appType = 0
    # request.isHotKey = 0
    # request.pageSize = 20
    # request.pageIndex = 1
    # request.orderType = 0
    # req_pack.action.append('ReqAppList4SearchKey')
    # req_pack.params.append(request.SerializeToString())

    # # 测试协议接口 2015-09-01
    # # 用户举报
    # request = proto_packet.ReqAppInform()
    # request.appId = 1233
    # request.informType = '1,2,3'
    # request.informDetail = ''
    # req_pack.action.append('ReqAppInform')
    # req_pack.params.append(request.SerializeToString())

    # # 用户反馈
    # request = proto_packet.ReqFeedback()
    # request.feedBackContent = u'用户反馈内容'
    # request.userContact = u'74110'
    # req_pack.action.append('ReqFeedback')
    # req_pack.params.append(request.SerializeToString())

    # 用户评论或更新
    #request = proto_packet.ReqAddComment()
    #request.userName = u'wind'  # 用户名
    #request.appId = 74116   # 应用ID
    #request.userScore = 2  # 用户评分
    #request.userVerCode = 150901   # 用户本地版本代码
    #request.userVerName = u'2015.09.01.1'  # 用户本地版本名称
    #request.comments = u''  # 评论内容
    #request.commentId = 123  # 评论ID,用于更新评论时填写
    #req_pack.action.append('ReqAddComment')
    #req_pack.params.append(request.SerializeToString())

    # # 用户评分
    # request = proto_packet.ReqUserScoreInfo()
    # request.appId = 74115   # 应用ID
    # req_pack.action.append('ReqUserScoreInfo')
    # req_pack.params.append(request.SerializeToString())

    # # 应用推荐
    # request = proto_packet.ReqRecommApp()
    # request.appId = 100009   # 应用ID
    # request.appClass = ''  # 应用类别
    # request.appType =  '1201'   # 应用类型
    # request.pageSize = 20  # 页尺寸
    # request.pageIndex = 1  # 页码 (从1开始)
    # request.orderType = 0  # 排序类型:0=自动-热门,2=按时间
    # request.clientCacheVer = ''  # 终端缓存版本:如果有缓存则上传,下发时可省流量,加速度
    # req_pack.action.append('ReqRecommApp')
    # req_pack.params.append(request.SerializeToString())

    # 应用更新检测
    # apps_update = proto_packet.ReqAppsUpdate()
    # apps_update.checkUpdateType = 2
    # local = apps_update.localAppVer.add()
    # local.packName = 'com.teatimesgames.snowball'
    # local.verName = '0.1'
    # local.verCode = 1
    # local.signCode = ''
    # req_pack.action.append('ReqAppsUpdate')
    # req_pack.params.append(apps_update.SerializeToString())

    return req_pack.SerializeToString()