Пример #1
0
    def OnReceivedBizMsg(self, hSend, sBuff, iLenght) -> None:
        """"""
        biz_msg = py_t2sdk.pyIBizMessage()
        biz_msg.SetBuff(sBuff, iLenght)
        ret = biz_msg.GetReturnCode()

        if not ret:
            function = biz_msg.GetFunction()
            buf, len = biz_msg.GetContent()

            unpacker = py_t2sdk.pyIF2UnPacker()
            unpacker.Open(buf, len)
            data = unpack_data(unpacker)
            self.td_api.on_callback(function, data)

            unpacker.Release()
        else:
            buf, len = biz_msg.GetContent()
            unpacker = py_t2sdk.pyIF2UnPacker()
            unpacker.Open(buf, len)

            if unpacker:
                data = unpack_data(unpacker)
                self.td_api.on_error(data)
                unpacker.Release()
            else:
                error_msg = str(biz_msg.GetErrorInfo(), encoding="gbk")
                msg = f"请求失败,信息:{error_msg}"
                self.td_api.gateway.write_log(msg)

        biz_msg.Release()
Пример #2
0
    def send_req(self, function: int, req: dict) -> int:
        """"""
        packer = py_t2sdk.pyIF2Packer()
        packer.BeginPack()

        for Field in req.keys():
            packer.AddField(Field)

        for value in req.values():
            packer.AddStr(str(value))

        packer.EndPack()

        msg = py_t2sdk.pyIBizMessage()
        msg.SetFunction(function)
        msg.SetPacketType(0)
        msg.SetContent(packer.GetPackBuf(), packer.GetPackLen())

        n = self.connection.SendBizMsg(msg, 1)

        packer.FreeMem()
        packer.Release()
        msg.Release()

        return n
Пример #3
0
    def OnReceived(self, topic, sBuff, iLen) -> None:
        """"""
        biz_msg = py_t2sdk.pyIBizMessage()
        biz_msg.SetBuff(sBuff, iLen)
        buf, len = biz_msg.GetContent()

        unpacker = py_t2sdk.pyIF2UnPacker()
        unpacker.Open(buf, len)
        data = unpack_data(unpacker)
        self.td_api.on_callback(topic, data)

        unpacker.Release()
        biz_msg.Release()