Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

请问这个公众号查题如何使用?原理是什么?没太看懂... #1

Closed
huanghaozi opened this issue Sep 28, 2018 · 8 comments

Comments

@huanghaozi
Copy link

膜拜...非常感谢您的工具...
这段代码不太懂(wechatsearch.py里的17~39行):

# def qrcode_wechat(uuid, status, qrcode):
#     with open('wxlogin.png', 'wb') as f:
#         f.write(qrcode)


bot = Bot(cache_path=True, console_qr=1)
target = [ensure_one(bot.search(x)) for x in wechat_mp]


def run_wechat():
    @bot.register(target, SHARING)
    def handle_receive_msg(msg):
        global messages
        try:
            answer = minidom.parseString(msg.raw['Content'].replace('\x01', '&')).getElementsByTagName('des')[0].firstChild.nodeValue
            if answer:
                messages.append(answer)
        except:
            pass
    # embed()
    t = threading.Thread(target=bot.join)
    t.setDaemon(True)
    t.start()

谢谢!

@bankroft
Copy link
Owner

handle_reveive_msg处理接收到的sharing类型消息,将其中的内容(题目和回答)放入message,其他的代码你可以看看wxpy文档就清楚了

@huanghaozi
Copy link
Author

哦,这样啊,我发现控制台里打印不出二维码,现在正尝试去掉console=1

@huanghaozi
Copy link
Author

貌似还是一样调不出二维码...

@bankroft
Copy link
Owner

需要在config.ini中配置微信公众号名称才会调用那段代码

@huanghaozi
Copy link
Author

嗯,加到config.ini里了,单引号括起来的
有什么方法能改成TEXT类型的消息处理吗
或者能不能把TEXT转成sharing的再直接调代码...

@huanghaozi
Copy link
Author

我不太熟悉python...刚刚看了下wxpy的文档,试着学了几行代码...看不太懂那个sharing类型消息的结构...

@bankroft
Copy link
Owner

sharing类型消息是一段格式固定xml,如果改成text类型,文本内容太过丰富处理起来比较麻烦

@huanghaozi
Copy link
Author

哦,原来如此,我发现公众号里的回复格式是固定的,应该能转成xml
这样就可以直接套用了,知识我不知道这个xml的格式
我看了下源码,这个xml是不是包含titile和answer两部分?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants