在作测试的过程当中,同事们常常须要获取一个帐户的token和我的信息,我本身利用spring boot写了一个接口,可是对于APP测试同窗来讲不是很方便,由于须要复制这个token到APP里面去,因此我作了一个微信自动应答的机器人,来实现这个需求。java
思路以下:利用wxpy拿到对方发来的信息,而后简单判断,在用requests去请求我本身写的测试接口,拿到信息,发送给消息来源。python
代码以下:spring
#!/usr/bin/python # coding=utf-8 from wxpy import * import os import time import requests import json bot = Bot(cache_path=True) @bot.register(Friend, TEXT) def print_group_msg(msg): m = msg.text friend = msg.sender if "@" not in m: m = "你发错帐号了!" print m friend.send(m.decode("utf-8")) return r = requests.post("http://10.10.32.155:8081/uname/"+m) b = json.loads(r.text)["data"][u"用户token:"] friend.send(b) embed()