def parser_mxid(mxid): """ 根据jid,accesstoken产生maadap的mxid :param access_token: register的访问token :param jid: jabber id :return:字符串 """ mxid = XXTEACrypto.instance(MxidMgr.xxtea_key).decrypt(mxid) return mxid.split(MxidMgr.separator)
def mqtt_onmessage_param_decorator(self, mqttc, userdata, msg): logger.info("MQTT:onmessage msg:%s" % msg) msg.payload = XXTEACrypto.instance(xxtea_key).decrypt(msg.payload) \ if xxtea_key and msg.payload\ else msg.payload msg.payload = ujson.loads(msg.payload) \ if use_json_loads and msg.payload \ else msg.payload return fun(self, mqttc, userdata, msg)
def mqtt_publish_param_decorator(self, topic, payload=None, *args, **kwargs): logger.info("MQTT:publish topic:%s, payload:%s" % (topic, payload)) payload.__setitem__('sign', mqtt_sign) if mqtt_sign else None payload = ujson.dumps(payload) \ if use_json_dumps and payload is not None\ else payload payload = XXTEACrypto.instance(xxtea_key).encrypt(payload) \ if xxtea_key and payload is not None\ else payload return fun(self, topic, payload, *args, **kwargs)
def gen_mxid(access_token, jid): """ 根据jid,accesstoken产生maadap的mxid :param access_token: register的访问token :param jid: jabber id :return:字符串 """ assert isinstance(jid, str) mxid = "%s%s%s" % (jid, MxidMgr.separator, access_token) return XXTEACrypto.instance(MxidMgr.xxtea_key).encrypt(mxid)
def mqtt_onmessage_param_decorator(self, mqttc, userdata, msg): try: msg.payload = XXTEACrypto.instance(xxtea_key).decrypt(msg.payload) \ if xxtea_key and msg.payload\ else msg.payload msg.payload = ujson.loads(msg.payload) \ if use_json_loads and msg.payload \ else msg.payload except: logger.warn("mqtt_onmessage_decorator Error!!! topic:%s payload:%s" % (msg.topic, msg.payload)) return return fun(self, mqttc, userdata, msg)
def mqtt_onmessage_param_decorator(self, mqttc, userdata, msg): try: msg.payload = XXTEACrypto.instance(xxtea_key).decrypt(msg.payload) \ if xxtea_key and msg.payload\ else msg.payload msg.payload = ujson.loads(msg.payload) \ if use_json_loads and msg.payload \ else msg.payload except: logger.warn( "mqtt_onmessage_decorator Error!!! topic:%s payload:%s" % (msg.topic, msg.payload)) return return fun(self, mqttc, userdata, msg)