Ejemplo n.º 1
0
	def io(self, dictEelement):
		#在数据工厂里面对protobuf格式数据,进行如下操作
		datagramfactory = _dsb.DatagramStringBuffer()
		# 1.序列化
		datagramfactory.strbuffer = dictEelement['requestMsg'].SerializeToString()

		if not datagramfactory.strbuffer:
			dictEelement['strErrMsg'] = 'requestMsg.SerializeToString failed'
			return -1
		# 2.编码(转网络字节序) bytebuf是class ByteBuffer对象,包含一个list
		bytebuf = datagramfactory.encode()

		# 3.list转string
		requestByte = ''.join(bytebuf.bytelist)

		# 4.字典类型,用于传参
		dictByte = {'requestByte':requestByte, 'responseByte':None, 'strErrMsg':None}

		ret = self.tcp_io(dictByte)
		if ret != 0:
			dictEelement['strErrMsg'] = dictByte['strErrMsg']
			return -1		
		
		# 5.解码
		protoStrResponse = datagramfactory.decode(dictByte['responseByte'])

		stResponseMsg = _msg.Msg()
		# 6.反序列化 string -> protobuf
		stResponseMsg.ParseFromString(protoStrResponse)

		dictEelement['responseMsg'] = stResponseMsg
		return 0
Ejemplo n.º 2
0
def FetchFeedsInfo(listFeedId, iPaAppidMd5, iOpenidMd5):
    # 1.Build requestMsg protobuf
    stFeedDetailRequestMsg = _msg.Msg()

    stFeedDetailRequestMsgHead = stFeedDetailRequestMsg.head
    stFeedDetailRequestMsgHead.cmd = _msg.QUERY_FEED_DETAIL_REQ
    stFeedDetailRequestMsgHead.seq = int(time.time())

    stQueryFeedDetailReq = stFeedDetailRequestMsg.query_feed_detail_req
    stQueryFeedDetailReq.pa_appid_md5 = iPaAppidMd5
    stQueryFeedDetailReq.openid_md5 = iOpenidMd5

    for feedId in listFeedId:
        stQueryFeedDetailReq.feed_id_list.append(feedId)

    # 2.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(feedServerIP, feedServerPort)
    dictMsg = {
        'requestMsg': stFeedDetailRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('FetchFeedsInfo IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    stFeedDetailResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stFeedDetailResponseMsg)

    if stFeedDetailResponseMsg.head.cmd != _msg.QUERY_FEED_DETAIL_RES:
        logger.error('FetchFeedsInfo response.head.cmd=%d, unkown, f**k!!!',
                     stFeedDetailResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    if stFeedDetailResponseMsg.head.result != _msg.E_OK:
        logger.error('FetchFeedsInfo response.head.result=%d, not E_OK!',
                     stFeedDetailResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    # 3.Parse
    listFeedId = []  #clear
    res = stFeedDetailResponseMsg.query_feed_detail_res
    dictFeedInfo = {}
    for i in range(len(res.feed_list)):
        stFeedInfo = res.feed_list[i]
        listFeedId.append(stFeedInfo.feed_id)

        dictFeedInfo[str(stFeedInfo.feed_id)] = FeedInfoPB2Dict(stFeedInfo)

    if len(dictFeedInfo) > 0:
        mycgi.addBody('feed_info', dictFeedInfo)

    return 0
Ejemplo n.º 3
0
def InnerProcess():
    # 1.Get HTTP params
    openid_md5 = int(mycgi.getEnvValue('openid_md5', 0))

    # 2.Params check
    if 0 == openid_md5:
        logger.error('INVALID PARAM!')
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)
        return True

    # 3.Build requestMsg protobuf
    stRequestMsg = _msg.Msg()

    stRequestMsgHeader = stRequestMsg.head
    stRequestMsgHeader.cmd = _msg.QUERY_MSG_NEWMSG_STATUS_REQ
    stRequestMsgHeader.seq = int(time.time())

    stRequestMsgBody = stRequestMsg.msg_query_newmsg_status_req
    stRequestMsgBody.openid_md5 = openid_md5

    logger.debug('requestMsg: \n %s', stRequestMsg)

    # 4.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

    dictMsg = {
        'requestMsg': stRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('ProtoIOTcpClient IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    stResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stResponseMsg)

    if stResponseMsg.head.cmd != _msg.QUERY_MSG_NEWMSG_STATUS_RES:
        logger.error('response.head.cmd=%d, unkown, f**k!!!',
                     stResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    if stResponseMsg.head.result != _msg.E_OK:
        logger.error('response.head.result=%d, not E_OK!',
                     stResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    # 5.protobuf -> json, and do reply
    stMsgQueryRes = stResponseMsg.msg_query_newmsg_status_res
    mycgi.addBody('newmsg_status', stMsgQueryRes.newmsg_status)

    mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
    return True
def InnerProcess():
	# 1.Get HTTP params	
	openid_md5 = int(mycgi.getEnvValue('openid_md5', 0))
	pa_appid_md5 = int(mycgi.getEnvValue('pa_appid_md5', 0))
	iType = int(mycgi.getEnvValue('type', 0))
	opt = int(mycgi.getEnvValue('opt', 0))
	
	# 2.Params check
	if 0 == openid_md5 or 0 == pa_appid_md5 or (iType < 1 or iType > 4) or (opt < 0 or opt > 2):
		logger.error('INVALID PARAM: openid_md5=%d, pa_appid_md5=%d, type=%d, opt=%d!', openid_md5, pa_appid_md5, iType, opt)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)		
		return True

	# 3.Build requestMsg protobuf
	stRequestMsg = _msg.Msg()

	stRequestMsgHeader = stRequestMsg.head
	stRequestMsgHeader.cmd = _msg.UPDATE_SYSTEM_RED_POINT_REQ
	stRequestMsgHeader.seq = int(time.time())

	stRequestMsgBody = stRequestMsg.update_system_red_point_req
	stRequestMsgBody.openid_md5 = openid_md5
	stRequestMsgBody.pa_appid_md5 = pa_appid_md5
	stRequestMsgBody.type = iType
	stRequestMsgBody.opt = opt

	logger.debug('requestMsg: \n %s', stRequestMsg)

	# 4.Send to server, and recv responseMsg protobuf	
	ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

	dictMsg = {'requestMsg':stRequestMsg, 'responseMsg':None, 'strErrMsg':None}

	ret = ioclient.io(dictMsg)

	if ret != 0:	
		logger.error('ProtoIOTcpClient IO failed, errmsg = %s', dictMsg['strErrMsg'])
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	stResponseMsg = dictMsg['responseMsg']
	logger.debug('responseMsg: \n %s', stResponseMsg)

	if stResponseMsg.head.cmd != _msg.UPDATE_SYSTEM_RED_POINT_RES:
		logger.error('response.head.cmd=%d, unkown, f**k!!!', stResponseMsg.head.cmd)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	if stResponseMsg.head.result != _msg.E_OK:
		logger.error('response.head.result=%d, not E_OK!', stResponseMsg.head.result)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	# 5.protobuf -> json, and do reply
	
	mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
	return True
Ejemplo n.º 5
0
def FetchUserInfo(listOpenidMd5):
    # 1.Build requestMsg protobuf
    stUserInfoRequestMsg = _msg.Msg()

    stUserInfoRequestMsgHead = stUserInfoRequestMsg.head
    stUserInfoRequestMsgHead.cmd = _msg.QUERY_USER_DETAIL_INFO_REQ
    stUserInfoRequestMsgHead.seq = int(time.time())

    stQueryUserDetailInfoReq = stUserInfoRequestMsg.query_user_detail_info_req
    for openidMd5 in listOpenidMd5:
        stQueryUserDetailInfoReq.openid_md5_list.append(openidMd5)

    # 2.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(userServerIP, userServerPort)
    dictMsg = {
        'requestMsg': stUserInfoRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('FetchFeedsInfo IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    stUserInfoResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stUserInfoResponseMsg)

    if stUserInfoResponseMsg.head.cmd != _msg.QUERY_USER_DETAIL_INFO_RES:
        logger.error('FetchUserInfo response.head.cmd=%d, unkown, f**k!!!',
                     stUserInfoResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    if stUserInfoResponseMsg.head.result != _msg.E_OK:
        logger.error('FetchUserInfo response.head.result=%d, not E_OK!',
                     stUserInfoResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    # 3.Parse
    listOpenidMd5 = []  #clear
    res = stUserInfoResponseMsg.query_user_detail_info_res
    dictUserInfo = {}
    for i in range(len(res.user_detail_info_list)):
        stUserInfo = res.user_detail_info_list[i]
        listOpenidMd5.append(stUserInfo.openid_md5)

        dictUserInfo[str(stUserInfo.openid_md5)] = UserInfoPB2Dict(stUserInfo)

    if len(dictUserInfo) > 0:
        mycgi.addBody('user_info', dictUserInfo)

    return 0
Ejemplo n.º 6
0
def InnerProcess():
    # 1.Get HTTP params
    #'''
    strMsgContent = mycgi.getEnvValue('content', '')
    openid_md5_from = int(mycgi.getEnvValue('openid_md5_from', 0))
    openid_md5_to = int(mycgi.getEnvValue('openid_md5_to', 0))

    # for test
    '''
	strMsgContent = '你好!world'
	openid_md5_from = 123
	openid_md5_to = 456
	'''

    # 2.Params check
    if strMsgContent == '' or openid_md5_from == 0 or openid_md5_to == 0:
        logger.error('INVALID PARAM!')
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)
        return True

    # 3.Build requestMsg protobuf
    stRequestMsg = _msg.Msg()

    stRequestMsgHeader = stRequestMsg.head
    stRequestMsgHeader.cmd = _msg.ADD_MSG_REQ
    stRequestMsgHeader.seq = int(time.time())

    stRequestMsgBody = stRequestMsg.msg_add_req
    msgcontent = stRequestMsgBody.msg_content
    msgcontent.content = strMsgContent.decode('utf-8')
    msgcontent.openid_md5_from = openid_md5_from
    msgcontent.openid_md5_to = openid_md5_to

    logger.debug('requestMsg: \n %s', stRequestMsg)

    # 4.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

    dictMsg = {
        'requestMsg': stRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('ProtoIOTcpClient IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    stResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stResponseMsg)

    if stResponseMsg.head.cmd != _msg.ADD_MSG_RES:
        logger.error('response.head.cmd=%d, unkown, f**k!!!',
                     stResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    if stResponseMsg.head.result != _msg.E_OK:
        logger.error('response.head.result=%d, not E_OK!',
                     stResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    # 5.protobuf -> json, and do reply
    msg_id = stResponseMsg.msg_add_res.msg_id
    create_ts = stResponseMsg.msg_add_res.create_ts

    mycgi.addBody('msg_id', msg_id)
    mycgi.addBody('create_ts', create_ts)

    mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
    return True
Ejemplo n.º 7
0
def InnerProcess():
	# 1.Get HTTP params
	openid_md5 = int(mycgi.getEnvValue('openid_md5', 0))

	# 2.Params check
	if 0 == openid_md5:
		logger.error('INVALID PARAM!')
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)		
		return True

	# 3.Build requestMsg protobuf
	stRequestMsg = _msg.Msg()

	stRequestMsgHeader = stRequestMsg.head
	stRequestMsgHeader.cmd = _msg.QUERY_MSG_SESSION_LIST_REQ
	stRequestMsgHeader.seq = int(time.time())

	stRequestMsgBody = stRequestMsg.msg_query_session_list_req
	stRequestMsgBody.openid_md5 = openid_md5

	logger.debug('requestMsg: \n %s', stRequestMsg)

	# 4.Send to server, and recv responseMsg protobuf	
	ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

	dictMsg = {'requestMsg':stRequestMsg, 'responseMsg':None, 'strErrMsg':None}

	ret = ioclient.io(dictMsg)

	if ret != 0:	
		logger.error('ProtoIOTcpClient IO failed, errmsg = %s', dictMsg['strErrMsg'])
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	stResponseMsg = dictMsg['responseMsg']
	logger.debug('responseMsg: \n %s', stResponseMsg)

	if stResponseMsg.head.cmd != _msg.QUERY_MSG_SESSION_LIST_RES:
		logger.error('response.head.cmd=%d, unkown, f**k!!!', stResponseMsg.head.cmd)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	if stResponseMsg.head.result != _msg.E_OK:
		logger.error('response.head.result=%d, not E_OK!', stResponseMsg.head.result)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	# 5.Get UserInfo
	listOpenidMd5 = []
	listOpenidMd5.append(openid_md5)
	stMsgQueryRes = stResponseMsg.msg_query_session_list_res
	for session in stMsgQueryRes.session:
		if openid_md5 == session.openid_md5_from:
			listOpenidMd5.append(session.openid_md5_to)
		else:
			listOpenidMd5.append(session.openid_md5_from)

	pbUserInfoList = []
	if FetchUserInfo(listOpenidMd5, pbUserInfoList) < 0:
		logger.error('FetchUserInfo failed!!!')
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
		return True

	stHostUserInfo = UserInfoPB2Dict(pbUserInfoList[0])

	session_list = []
	for i in range(len(stMsgQueryRes.session))[::-1]:
		tSession = stMsgQueryRes.session[i]
		flag = False

		for j in range(len(pbUserInfoList))[::-1]:
			stGuestUserInfo = None
			tUserInfo = pbUserInfoList[j]
			if openid_md5 == tSession.openid_md5_from:
				if tUserInfo.openid_md5 == tSession.openid_md5_to:
					continue
				else:
					stGuestUserInfo = UserInfoPB2Dict(tUserInfo)
					flag = True
					break
			elif openid_md5 == tSession.openid_md5_to:
				if tUserInfo.openid_md5 == tSession.openid_md5_from:
					continue
				else:
					stGuestUserInfo = UserInfoPB2Dict(tUserInfo)
					flag = True
					break

		if flag is not True:
			continue

		dictItem = {}
		dictItem['openid_md5_from'] = str(tSession.openid_md5_from)
		dictItem['openid_md5_to'] = str(tSession.openid_md5_to)

		if openid_md5 == tSession.openid_md5_from:
			dictItem['userinfo_from'] = stHostUserInfo
			dictItem['userinfo_to'] = stGuestUserInfo
		else:
			dictItem['userinfo_from'] = stGuestUserInfo
			dictItem['userinfo_to'] = stHostUserInfo

		dictItem['content'] = tSession.content
		dictItem['create_ts'] = str(tSession.create_ts)
		dictItem['newmsg_status'] = tSession.newmsg_status

		session_list.append(dictItem)

	mycgi.addBody('session_list', session_list)

	mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
	return True
Ejemplo n.º 8
0
def InnerProcess():
    # 1.Get HTTP params
    msg_id = int(mycgi.getEnvValue('msg_id', 0))
    amount = int(mycgi.getEnvValue('amount', 0))
    openid_md5_from = int(mycgi.getEnvValue('openid_md5_from', 0))
    openid_md5_to = int(mycgi.getEnvValue('openid_md5_to', 0))

    # 2.Params check
    if 0 == openid_md5_from or 0 == openid_md5_to:
        logger.error(
            'INVALID OPENID MD5! openid_md5_from = %d, openid_md5_to = %d',
            openid_md5_from, openid_md5_to)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)
        return True
    if amount > getMsgAmountLimit:
        logger.error('amount: %d > getMsgAmountLimit: %d', amount,
                     getMsgAmountLimit)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)
        return True

    # 3.Build requestMsg protobuf
    stRequestMsg = _msg.Msg()

    stRequestMsgHeader = stRequestMsg.head
    stRequestMsgHeader.cmd = _msg.QUERY_MSG_REQ
    stRequestMsgHeader.seq = int(time.time())

    stRequestMsgBody = stRequestMsg.msg_query_req
    stRequestMsgBody.msg_id = msg_id
    stRequestMsgBody.amount = amount
    stRequestMsgBody.openid_md5_from = openid_md5_from
    stRequestMsgBody.openid_md5_to = openid_md5_to

    logger.debug('requestMsg: \n %s', stRequestMsg)

    # 4.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

    dictMsg = {
        'requestMsg': stRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('ProtoIOTcpClient IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    stResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stResponseMsg)

    if stResponseMsg.head.cmd != _msg.QUERY_MSG_RES:
        logger.error('response.head.cmd=%d, unkown, f**k!!!',
                     stResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    if stResponseMsg.head.result != _msg.E_OK:
        logger.error('response.head.result=%d, not E_OK!',
                     stResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    # 5.protobuf -> json, and do reply
    strMsgQueryRes = stResponseMsg.msg_query_res
    msgContentList = []
    preTime = 0
    for i in range(len(strMsgQueryRes.msg_content)):
        dictItem = {}
        msgContent = strMsgQueryRes.msg_content[i]
        dictItem['id'] = str(msgContent.id)
        dictItem['content'] = msgContent.content
        dictItem['openid_md5_from'] = str(msgContent.openid_md5_from)
        dictItem['openid_md5_to'] = str(msgContent.openid_md5_to)

        if i == 0:
            dictItem['create_ts'] = str(msgContent.create_ts)
        else:
            if msgContent.create_ts - preTime >= interval:
                dictItem['create_ts'] = str(msgContent.create_ts)
            else:
                dictItem['create_ts'] = '0'

        preTime = msgContent.create_ts

        msgContentList.append(dictItem)

    # 6.Get UserInfo
    listOpenidMd5 = []
    listOpenidMd5.append(openid_md5_from)
    listOpenidMd5.append(openid_md5_to)
    if FetchUserInfo(listOpenidMd5) < 0:
        logger.error('FetchUserInfo failed!!!')
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    # 7.Reply
    mycgi.addBody('msg_content_list', msgContentList)
    mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
    return True
def InnerProcess():
	# 1.Get HTTP params	
	openid_md5 = int(mycgi.getEnvValue('openid_md5', 0))
	pa_appid_md5 = int(mycgi.getEnvValue('pa_appid_md5', 0))
	
	# 2.Params check
	if 0 == openid_md5 or 0 == pa_appid_md5:
		logger.error('INVALID PARAM: openid_md5=%d, pa_appid_md5=%d!', openid_md5, pa_appid_md5)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)		
		return True

	# 3.Build requestMsg protobuf
	stRequestMsg = _msg.Msg()

	stRequestMsgHeader = stRequestMsg.head
	stRequestMsgHeader.cmd = _msg.QUERY_SYSTEM_RED_POINT_REQ
	stRequestMsgHeader.seq = int(time.time())

	stRequestMsgBody = stRequestMsg.query_system_red_point_req
	stRequestMsgBody.openid_md5 = openid_md5
	stRequestMsgBody.pa_appid_md5 = pa_appid_md5

	logger.debug('requestMsg: \n %s', stRequestMsg)

	# 4.Send to server, and recv responseMsg protobuf	
	ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

	dictMsg = {'requestMsg':stRequestMsg, 'responseMsg':None, 'strErrMsg':None}

	ret = ioclient.io(dictMsg)

	if ret != 0:	
		logger.error('ProtoIOTcpClient IO failed, errmsg = %s', dictMsg['strErrMsg'])
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	stResponseMsg = dictMsg['responseMsg']
	logger.debug('responseMsg: \n %s', stResponseMsg)

	if stResponseMsg.head.cmd != _msg.QUERY_SYSTEM_RED_POINT_RES:
		logger.error('response.head.cmd=%d, unkown, f**k!!!', stResponseMsg.head.cmd)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	if stResponseMsg.head.result != _msg.E_OK:
		logger.error('response.head.result=%d, not E_OK!', stResponseMsg.head.result)
		mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)		
		return True

	# 5.protobuf -> json, and do reply
	# init RED POINT LIST
	redinfo_list = {}
	for i in range(1, 6):
		redinfo_list[str(i)] = 0

	stMsgQueryRes = stResponseMsg.query_system_red_point_res
	for msg in stMsgQueryRes.red_point_info:
		redinfo_list[str(msg.type)] = msg.value
	
	mycgi.addBody('redinfo_list', redinfo_list)
	mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
	return True
Ejemplo n.º 10
0
def InnerProcess():
    # 1.Get HTTP params
    openid_md5 = int(mycgi.getEnvValue('openid_md5', 0))
    pa_appid_md5 = int(mycgi.getEnvValue('pa_appid_md5', 0))
    begin_ts = int(mycgi.getEnvValue('begin_ts', 0))
    limit = int(mycgi.getEnvValue('limit', 0))

    # 2.Params check
    if 0 == openid_md5 or 0 == pa_appid_md5 or (limit <= 0 or limit >= 100):
        logger.error(
            'INVALID PARAM: openid_md5=%d, pa_appid_md5=%d, limit=%d !',
            openid_md5, pa_appid_md5, limit)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)
        return True

    # 3.Build requestMsg protobuf
    stRequestMsg = _msg.Msg()

    stRequestMsgHeader = stRequestMsg.head
    stRequestMsgHeader.cmd = _msg.QUERY_SYSTEM_MSG_REQ
    stRequestMsgHeader.seq = int(time.time())

    stRequestMsgBody = stRequestMsg.system_msg_query_req
    stRequestMsgBody.openid_md5 = openid_md5
    stRequestMsgBody.pa_appid_md5 = pa_appid_md5
    stRequestMsgBody.begin_ts = begin_ts
    stRequestMsgBody.limit = limit

    logger.debug('requestMsg: \n %s', stRequestMsg)

    # 4.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

    dictMsg = {
        'requestMsg': stRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('ProtoIOTcpClient IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    stResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stResponseMsg)

    if stResponseMsg.head.cmd != _msg.QUERY_SYSTEM_MSG_RES:
        logger.error('response.head.cmd=%d, unkown, f**k!!!',
                     stResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    if stResponseMsg.head.result != _msg.E_OK:
        logger.error('response.head.result=%d, not E_OK!',
                     stResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    # 5.protobuf -> json, and do reply
    stMsgQueryRes = stResponseMsg.system_msg_query_res
    system_msg_list = []
    for systemMsg in stMsgQueryRes.system_msg_list:
        dictItem = {}
        dictItem['pa_appid_md5'] = systemMsg.pa_appid_md5
        dictItem['create_ts'] = systemMsg.create_ts
        dictItem['title'] = systemMsg.title
        dictItem['content'] = systemMsg.content
        system_msg_list.append(dictItem)

    mycgi.addBody('system_msg_list', system_msg_list)
    mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
    return True
Ejemplo n.º 11
0
def InnerProcess():
    # 1.Get HTTP params
    # string -> uint64_t, long or int? however both test OK!
    # "python 自带大数整数运算,整数不会溢出,只要内存足够, 3.x后不再区分int/long,去除了long,统称int"
    #'''
    pa_appid_md5 = int(mycgi.getEnvValue('pa_appid_md5', 0))
    openid_md5 = int(mycgi.getEnvValue('openid_md5', 0))
    iType = int(mycgi.getEnvValue('type', 0))
    limit_ts = int(mycgi.getEnvValue('limit_ts', 0))
    pagesize = int(mycgi.getEnvValue('pagesize', 0))
    '''
	pa_appid_md5 = 6353185739184837437
	openid_md5 = 8363909989775180263
	iType = 2
	limit_ts = 0
	pagesize = 10
	'''

    # 2.Params check
    if pa_appid_md5 == 0 or openid_md5 == 0:
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)
        logger.error('invalid pa_appid_md5=%d, or openid_md5=%d', pa_appid_md5,
                     openid_md5)
        return True

    if iType < 1 or iType > 3:
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_INVALID_PARAM)
        logger.error('invalid type=%d', iType)
        return True

    # 3.Build requestMsg protobuf
    stRequestMsg = _msg.Msg()

    stRequestMsgHeader = stRequestMsg.head
    stRequestMsgHeader.cmd = _msg.QUERY_NOTICE_RECORD_REQ
    stRequestMsgHeader.seq = int(time.time())

    stRequestMsgBody = stRequestMsg.notice_record_query_req
    stRequestMsgBody.pa_appid_md5 = pa_appid_md5
    stRequestMsgBody.openid_md5 = openid_md5
    stRequestMsgBody.type = iType
    stRequestMsgBody.limit_ts = limit_ts
    stRequestMsgBody.pagesize = pagesize

    logger.debug('requestMsg: \n %s', stRequestMsg)

    # 4.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(msgServerIP, msgServerPort)

    dictMsg = {
        'requestMsg': stRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('ProtoIOTcpClient IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    stResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stResponseMsg)

    if stResponseMsg.head.cmd != _msg.QUERY_NOTICE_RECORD_RES:
        logger.error('response.head.cmd=%d, unkown, f**k!!!',
                     stResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    if stResponseMsg.head.result != _msg.E_OK:
        logger.error('response.head.result=%d, not E_OK!',
                     stResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return True

    # 5.protobuf -> json, and do reply
    if iType == _comm_enum.NOTICE_RECORD_TYPE_COMMENT:
        listFollowId = []
        res = stResponseMsg.notice_record_query_res
        for i in range(len(res.notice_record_list)):
            listFollowId.append(int(res.notice_record_list[i].extra_data_2))

        #Get CommentInfo
        if FetchCommentInfo(listFollowId, pa_appid_md5, openid_md5) < 0:
            logger.error('FetchCommentInfo failed!')
            return True

        #Gen notice record list
        for i in range(len(res.notice_record_list)):
            tmp_follow_id = int(res.notice_record_list[i].extra_data_2)
            if tmp_follow_id not in listFollowId:
                continue
            dictNoticeRecord = {}
            dictNoticeRecord['pa_appid_md5'] = str(
                res.notice_record_list[i].pa_appid_md5)
            dictNoticeRecord['openid_md5'] = str(
                res.notice_record_list[i].openid_md5)
            dictNoticeRecord['create_ts'] = str(
                res.notice_record_list[i].create_ts)
            dictNoticeRecord['type'] = res.notice_record_list[i].type
            dictNoticeRecord['status'] = res.notice_record_list[i].status
            dictNoticeRecord['extra_data_0'] = res.notice_record_list[
                i].extra_data_0
            dictNoticeRecord['extra_data_1'] = res.notice_record_list[
                i].extra_data_1
            dictNoticeRecord['extra_data_2'] = res.notice_record_list[
                i].extra_data_2

            mycgi.addBody('notice_record_list', dictNoticeRecord)

    elif iType == _comm_enum.NOTICE_RECORD_TYPE_FAVORITE:
        listFeedId = []
        listOpenidMd5 = []
        res = stResponseMsg.notice_record_query_res
        for i in range(len(res.notice_record_list)):
            listFeedId.append(int(res.notice_record_list[i].extra_data_0))
            listOpenidMd5.append(int(res.notice_record_list[i].extra_data_1))

        #Get FeedInfo
        if FetchFeedsInfo(listFeedId, pa_appid_md5, openid_md5) < 0:
            logger.error('FetchFeedsInfo failed!')
            return True

        #Get UserInfo
        if FetchUserInfo(listOpenidMd5) < 0:
            logger.error('FetchUserInfo failed!')
            return True

        #Gen notice record list
        for i in range(len(res.notice_record_list)):
            tmp_feed_id = int(res.notice_record_list[i].extra_data_0)
            tmp_openid_md5 = int(res.notice_record_list[i].extra_data_1)

            if tmp_feed_id not in listFeedId or tmp_openid_md5 not in listOpenidMd5:
                continue
            dictNoticeRecord = {}
            dictNoticeRecord['pa_appid_md5'] = str(
                res.notice_record_list[i].pa_appid_md5)
            dictNoticeRecord['openid_md5'] = str(
                res.notice_record_list[i].openid_md5)
            dictNoticeRecord['create_ts'] = str(
                res.notice_record_list[i].create_ts)
            dictNoticeRecord['type'] = res.notice_record_list[i].type
            dictNoticeRecord['status'] = res.notice_record_list[i].status
            dictNoticeRecord['extra_data_0'] = res.notice_record_list[
                i].extra_data_0
            dictNoticeRecord['extra_data_1'] = res.notice_record_list[
                i].extra_data_1
            dictNoticeRecord['extra_data_2'] = res.notice_record_list[
                i].extra_data_2

            mycgi.addBody('notice_record_list', dictNoticeRecord)

    elif iType == _comm_enum.NOTICE_RECORD_TYPE_SYSTEM_MSG:
        res = stResponseMsg.notice_record_query_res
        for i in range(len(res.notice_record_list)):
            dictNoticeRecord = {}
            dictNoticeRecord['pa_appid_md5'] = str(
                res.notice_record_list[i].pa_appid_md5)
            dictNoticeRecord['openid_md5'] = str(
                res.notice_record_list[i].openid_md5)
            dictNoticeRecord['create_ts'] = str(
                res.notice_record_list[i].create_ts)
            dictNoticeRecord['type'] = res.notice_record_list[i].type
            dictNoticeRecord['status'] = res.notice_record_list[i].status
            dictNoticeRecord['extra_data_0'] = res.notice_record_list[
                i].extra_data_0
            dictNoticeRecord['extra_data_1'] = res.notice_record_list[
                i].extra_data_1
            dictNoticeRecord['extra_data_2'] = res.notice_record_list[
                i].extra_data_2

            mycgi.addBody('notice_record_list', dictNoticeRecord)

    mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_OK)
    return True
Ejemplo n.º 12
0
def FetchCommentInfo(listFollowId, iPaAppidMd5, iOpenidMd5):
    # 1.Build requestMsg protobuf
    stRequestMsg = _msg.Msg()

    stRequestMsgHead = stRequestMsg.head
    stRequestMsgHead.cmd = _msg.QUERY_FOLLOW_DETAIL_REQ
    stRequestMsgHead.seq = int(time.time())

    stRequestMsgBody = stRequestMsg.query_follow_detail_req
    stRequestMsgBody.pa_appid_md5 = iPaAppidMd5
    stRequestMsgBody.openid_md5 = iOpenidMd5
    for followid in listFollowId:
        stRequestMsgBody.follow_id_list.append(followid)

    # 2.Send to server, and recv responseMsg protobuf
    ioclient = _tcp_client.ProtoIOTcpClient(feedServerIP, feedServerPort)
    dictMsg = {
        'requestMsg': stRequestMsg,
        'responseMsg': None,
        'strErrMsg': None
    }

    ret = ioclient.io(dictMsg)

    if ret != 0:
        logger.error('FetchCommentInfo IO failed, errmsg = %s',
                     dictMsg['strErrMsg'])
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    stResponseMsg = dictMsg['responseMsg']
    logger.debug('responseMsg: \n %s', stResponseMsg)

    if stResponseMsg.head.cmd != _msg.QUERY_FOLLOW_DETAIL_RES:
        logger.error('FetchCommentInfo response.head.cmd=%d, unkown, f**k!!!',
                     stResponseMsg.head.cmd)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    if stResponseMsg.head.result != _msg.E_OK:
        logger.error('FetchCommentInfo response.head.result=%d, not E_OK!',
                     stResponseMsg.head.result)
        mycgi.DoReply(CGI_RET_CODE.CGI_RET_CODE_SERVER_BUSY)
        return -1

    # 3.Parse
    listOpenidMd5 = []
    listFeedId = []
    stResponseMsgBody = stResponseMsg.query_follow_detail_res
    for follower in stResponseMsgBody.follow_list:
        listOpenidMd5.append(follower.openid_md5_from)
        listFeedId.append(follower.feed_id)
    # list去重
    # listOpenidMd5 = list(set(listOpenidMd5))

    # Get FeedsInfo
    if FetchFeedsInfo(listFeedId, iPaAppidMd5, iOpenidMd5) < 0:
        return -1

    # Get UserInfo
    if FetchUserInfo(listOpenidMd5) < 0:
        return -1

    # Gen FollowId set & FollowInfo list
    listFollowId = []
    listFollowInfo = []

    #倒序[::-1]
    for i in range(len(stResponseMsgBody.follow_list))[::-1]:
        tmp_follow_feed_id = stResponseMsgBody.follow_list[i].feed_id
        tmp_follow_openid_md5 = stResponseMsgBody.follow_list[
            i].openid_md5_from
        if tmp_follow_feed_id in listFeedId and tmp_follow_openid_md5 in listOpenidMd5:
            listFollowId.append(stResponseMsgBody.follow_list[i].follow_id)
            listFollowInfo.append(
                FollowInfoPB2Dict(stResponseMsgBody.follow_list[i]))

    mycgi.addBody('follow_list', listFollowInfo)
    return 0