コード例 #1
0
    def pack_leaveReq(self, token):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.LEAVE_ROOM_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 9999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId  # 12976231 老师ID
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 0
        reqCommFrame.version = 101000012
        # reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造聊天请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.leave_room
        reqBody.reason = logical_pb2.LeaveReason
        reqBody.errmsg= ""

        # 对聊天请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        leaveReqMessage = reqPack.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        leaveReqMessage = struct.pack('!IH', Msg_len, Msg_flag) + leaveReqMessage
        return leaveReqMessage
コード例 #2
0
    def pack_rejoin(self, token):
        reqPack = logical_pb2.RequestPackage()
        commFrame = reqPack.head_frame
        commFrame.msg_type = msg_type_pb2.RE_JOIN_REQ
        commFrame.msg_no = 'wk_test_' + str(random.randint(1,
                                                           99999))  # 暂时采用随机数
        commFrame.msg_from_user_id = self.userId
        commFrame.msg_to_user_id = ""
        commFrame.device_type = 0
        commFrame.version = 101000012
        #commFrame.timestamp = int(time.time() * 1000)
        commFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        commFrame.client_info.os_name = "windows"
        commFrame.client_info.client_version = "wkai2133"
        commFrame.extended_fields['from'] = 'multiuser_test'

        # 设置请求包是否压缩标志,0 不压缩,1 压缩
        msg_flag = int('0x0000', 16)

        rejoin_message = logical_pb2.RequestMessage()
        rejoin_message.token = token
        joinRoom = rejoin_message.re_join

        # 对RequestPackage请求数据包进行序列化
        reqPack.logical_frame = rejoin_message.SerializeToString()
        rejoin_pack = reqPack.SerializeToString()

        # 计算请求封包的长度
        msg_len = reqPack.ByteSize() + 2
        final_message = struct.pack('!IH', msg_len, msg_flag) + rejoin_pack
        return final_message
コード例 #3
0
    def pack_getExaminationbyid(self, token, examination_id):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.GET_EXAMINATION_BY_ID_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4
        reqCommFrame.version = 101000012
        reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))

        # 构造答题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.get_examination_by_id_req
        reqBody.examination_id = examination_id

        # 对答题请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        getexamMessage = struct.pack('!IH', Msg_len,
                                     Msg_flag) + reqPack.SerializeToString()
        return getexamMessage
コード例 #4
0
    def pack_completeExamination(self, token, answer, score):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.STUDENT_COMPLETE_EXAMINATION_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4
        reqCommFrame.version = 101000012
        reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))

        # 构造答题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.student_complete_examination_req
        reqBody.examination_id = self.examination_id
        reqBody.examination_answer = answer
        reqBody.examination_score = score
        reqBody.examination_start_time = self.examination_start_time

        # 对答题请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        completeMessage = struct.pack('!IH', Msg_len,
                                      Msg_flag) + reqPack.SerializeToString()
        return completeMessage
コード例 #5
0
    def pack_checkExaminationstatus(self, token):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.CHECK_EXAMINATION_STATUS_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4
        reqCommFrame.version = 101000012
        reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))

        # 构造请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.check_examination_status_req

        # 对请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        checkMessage = struct.pack('!IH', Msg_len,
                                   Msg_flag) + reqPack.SerializeToString()
        return checkMessage
コード例 #6
0
    def pack_publicUserStageup(self, token):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.PUBLIC_CLASS_USER_STAGE_UP_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1,
                                                            999999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4  ## 设备类型,0 pc 1 ios 2 android 3 手机网页 4 pc网页
        reqCommFrame.version = 102000017
        # reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造上报奖励请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.public_class_user_stage_up_req
        reqBody.stage_id = self.stage_id
        reqBody.channel_user_id = random.randint(12345678, 87654321)
        # reqBody.channel_user_id = self.userId
        reqBody.teacher_id = self.teacher_id

        # 对请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        stageupMessage = reqPack.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        finalMessage = struct.pack('!IH', Msg_len, Msg_flag) + stageupMessage
        return finalMessage
コード例 #7
0
    def pack_nobookExperimentationstatus(self, token):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.CHECK_NOBOOK_EXPERIMENTATION_STATUS_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4
        reqCommFrame.version = 101000012
        # reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造答题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.check_nobook_experimentation_status_req

        # 对请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        checkMessage = struct.pack('!IH', Msg_len, Msg_flag) + reqPack.SerializeToString()
        return checkMessage
コード例 #8
0
    def pack_rewardReport(self, token):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.REWARD_REPORT_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 999999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4 ## 设备类型,0 pc 1 ios 2 android 3 手机网页 4 pc网页
        reqCommFrame.version = 101013017
        # reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造上报奖励请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.reward_report
        reqBody.count = random.randint(self.min_reward, self.max_reward)
        print("获得奖励数:", reqBody.count)
        reqBody.teacher_id = self.teacher_id

        # 对请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        rewardMessage = reqPack.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        reportMessage = struct.pack('!IH', Msg_len, Msg_flag) + rewardMessage
        return reportMessage
コード例 #9
0
    def pack_submitContest(self, token):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.SUBMIT_CONTEST_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 0
        reqCommFrame.version = 101000012
       #reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(socket.gethostbyname(socket.gethostname()))
        ## 客户端系统和版本信息
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造上报语音答题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.submit_contest
        reqBody.question_id = self.questionId

        # 对答题请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        voiceMessage = reqPack.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        reportMessage = struct.pack('!IH', Msg_len, Msg_flag) + voiceMessage
        return reportMessage
コード例 #10
0
    def pack_joinReq(self):
        reqPack = logical_pb2.RequestPackage()
        commFrame = reqPack.head_frame
        commFrame.msg_type = msg_type_pb2.JOIN_ROOM_REQ
        commFrame.msg_no = 'wk_test_' + str(random.randint(1,
                                                           99999))  # 暂时采用随机数
        commFrame.msg_from_user_id = self.userId  # 12976231 老师ID
        commFrame.msg_to_user_id = ""
        commFrame.device_type = 2  # 设备类型,0 pc 1 ios 2 android 3 手机网页 4 pc网页
        commFrame.version = 101000012
        #commFrame.timestamp = int(time.time() * 1000)
        commFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        commFrame.client_info.os_name = "windows"
        commFrame.client_info.client_version = "wkai2133"
        commFrame.extended_fields['from'] = 'multiuser_test'

        # 设置请求包是否压缩标志,0 不压缩,1 压缩
        msg_flag = int('0x0000', 16)
        avatar_url_list = [
            "https://cdn.17xueba.com/test/server/image/2018/01/20180112111219210950.jpg",
            "https://static.17xueba.com/test/server/image/2018/11/20181123153814607345.jpg?x-oss-process=image/resize,m_mfit,h_120,w_120/auto-orient,1/quality,q_80",
            "https://cdn.17xueba.com/test/server/image/2018/03/20180308171128983894.jpg?x-oss-process=image/resize,m_mfit,h_120,w_120/auto-orient,1/quality,q_80",
            "https://cdn.17xueba.com/test/server/image/2018/01/20180112111219210950.jpg?x-oss-process=image/resize,m_mfit,h_120,w_120/auto-orient,1/quality,q_80",
            "https://cdn.17xueba.com//pro/server/image/2018/01/20180122134340183387.png"
        ]
        join_Room_message = logical_pb2.RequestMessage()
        joinRoom = join_Room_message.join_room
        joinRoom.nickname = self.nickName  # u'令狐冲0112'
        joinRoom.user_id = self.userId
        joinRoom.avatar_url = random.choice(avatar_url_list)
        joinRoom.live_id = self.liveId
        joinRoom.user_type = self.userType  # 可选值 1学生,2助教,3老师
        joinRoom.room_index = self.roomIndex
        joinRoom.timestamp = int(time.time() * 1000)
        joinRoom.app_id = self.appId

        # 将所有参数赋值给字典变量,计算签名
        para_dict = dict()
        para_dict['nickname'] = joinRoom.nickname
        para_dict['user_id'] = joinRoom.user_id
        para_dict['avatar_url'] = joinRoom.avatar_url
        para_dict['live_id'] = joinRoom.live_id
        para_dict['user_type'] = joinRoom.user_type
        para_dict['room_index'] = joinRoom.room_index
        para_dict['timestamp'] = joinRoom.timestamp
        para_dict['app_id'] = joinRoom.app_id
        joinRoom.sign = addMd5.addSign(para_dict, self.appSecret)

        # 对RequestPackage请求数据包进行序列化
        reqPack.logical_frame = join_Room_message.SerializeToString()
        joinReqPack = reqPack.SerializeToString()

        # 计算请求封包的长度
        msg_len = reqPack.ByteSize() + 2
        joinReq_message = struct.pack('!IH', msg_len, msg_flag) + joinReqPack
        return joinReq_message
コード例 #11
0
    def pack_submitRead(self, token, audioUrl):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.READ_SENTENCE_SUBMIT_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1,
                                                            999999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 0
        reqCommFrame.version = 101000012
        # reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造上报朗读题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.read_sentence_submit
        reqBody.question_id = self.questionId
        reqBody.text = self.text
        reqBody.record_time = 9000
        reqBody.audio_url = audioUrl
        reqBody.teacher_id = self.teacherId
        # reqBody.err_code = random.sample([0, 1, 2, 3, 4], 1)[0]
        reqBody.err_code = 0
        # reqBody.err_msg = "ok"
        if reqBody.err_code == 0:
            reqBody.err_msg = ""
        elif reqBody.err_code == 1:
            reqBody.err_msg = "录音时间过短"
            reqBody.record_time = 0
            reqBody.audio_url = ""
        elif reqBody.err_code == 2:
            reqBody.err_msg = "未授权录音功能"
            reqBody.record_time = 0
            reqBody.audio_url = ""
        elif reqBody.err_code == 3:
            reqBody.err_msg = "其他"
            reqBody.record_time = 0
            reqBody.audio_url = ""
        elif reqBody.err_code == 4:
            reqBody.err_msg = u"上传时网络错误"
            reqBody.record_time = 0
            reqBody.audio_url = ""

        # 对答题请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        readMessage = reqPack.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        reportMessage = struct.pack('!IH', Msg_len, Msg_flag) + readMessage
        return reportMessage
コード例 #12
0
    def pack_coursewareQuestionReport(self, token, courseware_exercise_id,
                                      question_index,
                                      courseware_exercise_answers,
                                      right_answers, courseware_question_type,
                                      complete_level, submit_type, retry_times,
                                      wrong_answer_history):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.COURSEWARE_QUESTION_REPORT_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4
        reqCommFrame.version = 101000012
        #reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.courseware_question_report_req
        reqBody.courseware_exercise_id = courseware_exercise_id
        reqBody.courseware_id = self.courseware_id
        reqBody.question_index = question_index

        for element in courseware_exercise_answers:
            reqBody.courseware_exercise_answers.append(element)

        for answer in right_answers:
            reqBody.courseware_exercise_right_answers.append(answer)
        reqBody.courseware_question_type = courseware_question_type
        reqBody.complete_level = complete_level
        reqBody.page_num = self.page_num
        reqBody.original_answer_json = ""
        # 设置重试次数和错误答案历史
        reqBody.retry_times = retry_times
        for wrong_answer in wrong_answer_history:
            reqBody.wrong_answer_history.append(wrong_answer)
        reqBody.submit_type = submit_type
        reqBody.courseware_exercise_start_time = self.courseware_exercise_start_time

        # 对请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        reportMessage = struct.pack('!IH', Msg_len,
                                    Msg_flag) + reqPack.SerializeToString()
        return reportMessage
コード例 #13
0
    def pack_submitVote(self, token, submitOptions, stu_id):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.SUBMIT_VOTE_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 9999))  # 采用随机数
        reqCommFrame.msg_from_user_id = ""
        reqCommFrame.device_type = 0
        reqCommFrame.version = 1
        reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'double_teacher_test'
        reqCommFrame.extended_fields['zylive_hand_device_user_id'] = stu_id

        # 构造答题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.submit_vote
        reqBody.question_id = self.questionId

        if len(submitOptions) != 0:
            for name in submitOptions:
                # reqBody.option_names.extend(name)
                reqBody.option_names.append(name)

            if submitOptions == self.rightOptions:
                reqBody.is_right = True
            else:
                reqBody.is_right = False
        else:
            print("提交的选项为空!")

        reqBody.teacher_id = self.teacher_id
        reqBody.type = self.type
        # 若是双师题,则封装难度字段
        if self.currency_channel_name:
            reqBody.currency_channel_name = self.currency_channel_name

        # 对答题请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        voteMessage = reqPack.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        submitVoteMessage = struct.pack('!IH', Msg_len, Msg_flag) + voteMessage
        return submitVoteMessage
コード例 #14
0
    def pack_submitVoice(self, token, code, voiceUrl, level, voice_duration):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.VOICE_READ_REPORT_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 0
        reqCommFrame.version = 101000012
        # reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造上报语音答题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.voice_read_report
        reqBody.question_id = self.questionId
        reqBody.code = code
        reqBody.message = "ok"
        reqBody.original_score = random.sample([1, 2, 3, 4, 5, 6, 7, 8], 1)[0]
        reqBody.voice_url = voiceUrl
        reqBody.level = level
        reqBody.score = reqBody.level
        reqBody.voice_duration = voice_duration

        # 对答题请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()
        voiceMessage = reqPack.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        reportMessage = struct.pack('!IH', Msg_len, Msg_flag) + voiceMessage
        return reportMessage
コード例 #15
0
    def pack_Examinationresult(self, token, question_index, result,
                               examination_options, examination_answer):
        reqPack = logical_pb2.RequestPackage()
        reqCommFrame = reqPack.head_frame
        reqCommFrame.msg_type = msg_type_pb2.REPORT_EXAMINATION_RESULT_REQ
        reqCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 99999))  # 采用随机数
        reqCommFrame.msg_from_user_id = self.userId
        reqCommFrame.msg_to_user_id = ""
        reqCommFrame.device_type = 4
        reqCommFrame.version = 101000012
        # reqCommFrame.timestamp = int(time.time() * 1000)
        reqCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        reqCommFrame.client_info.os_name = "windows"
        reqCommFrame.client_info.client_version = "wkai2133"
        reqCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造答题请求逻辑帧
        req_message = logical_pb2.RequestMessage()
        req_message.token = token
        reqBody = req_message.report_examination_result_req
        reqBody.examination_id = self.examination_id
        reqBody.question_index = question_index
        reqBody.is_right = result
        for option in examination_options:
            reqBody.examination_options.append(option)
        reqBody.teacher_id = self.teacher_id
        reqBody.examination_answer = examination_answer
        # 对答题请求数据包进行序列化
        reqPack.logical_frame = req_message.SerializeToString()

        Msg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        Msg_len = reqPack.ByteSize() + 2
        resultMessage = struct.pack('!IH', Msg_len,
                                    Msg_flag) + reqPack.SerializeToString()
        return resultMessage
コード例 #16
0
    def pack_stuChat(self, token, is_mvp, continue_right_num):
        # 构造学生聊天req消息
        chatPack = logical_pb2.RequestPackage()
        chatCommFrame = chatPack.head_frame
        chatCommFrame.msg_type = msg_type_pb2.STUDENT_CHAT_REQ
        chatCommFrame.msg_no = 'wk_tt_' + str(random.randint(1, 9999))  # 采用随机数
        chatCommFrame.msg_from_user_id = self.userId  # 12976231 老师ID
        chatCommFrame.msg_to_user_id = ""
        chatCommFrame.device_type = 0
        chatCommFrame.version = 101000012
        #chatCommFrame.timestamp = int(time.time() * 1000)
        chatCommFrame.ip = IPConver.ip2int(
            socket.gethostbyname(socket.gethostname()))
        chatCommFrame.client_info.os_name = "windows"
        chatCommFrame.client_info.client_version = "wkai2133"
        chatCommFrame.extended_fields['from'] = 'multiuser_test'

        # 构造聊天请求逻辑帧
        chat_message = logical_pb2.RequestMessage()
        chat_message.token = token
        chat_reqMsg = chat_message.chat
        chat_reqMsg.chat_id = random.randint(1, 9999)
        chat_reqMsg.content = self.content
        chat_reqMsg.to = self.user_group
        chat_reqMsg.is_mvp = is_mvp
        chat_reqMsg.continue_right_num = continue_right_num

        # 对聊天请求数据包进行序列化
        chatPack.logical_frame = chat_message.SerializeToString()
        chat_ReqMessage = chatPack.SerializeToString()

        chatMsg_flag = int('0x0000', 16)
        # 计算请求封包的长度
        chatMsg_len = chatPack.ByteSize() + 2
        chat_ReqMessage = struct.pack('!IH', chatMsg_len,
                                      chatMsg_flag) + chat_ReqMessage
        return chat_ReqMessage