1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import itchat import re,requests from urllib.parse import quote,unquote
AUTO_REPLAY=0 BASEMSG = ''
def robot(data): global AUTO_REPLAY ini="{'sessionId':'09e2aca4d0a541f88eecc77c03a8b393','robotId':'webbot','userId':'462d49d3742745bb98f7538c42f9f874','body':{'content':'" + data + "'},'type':'txt'}&ts=1529917589648" url = "http://i.xiaoi.com/robot/webrobot?&callback=__webrobot_processMsg&data=" + quote(ini) cookie = {"cnonce": "808116", "sig": "0c3021aa5552fe597bb55448b40ad2a90d2dead5","XISESSIONID": "hlbnd1oiwar01dfje825gavcn", "nonce": "273765", "hibext_instdsigdip2": "1"} r = requests.get(url, cookies=cookie) pattern = re.compile(r'\"fontColor\":0,\"content\":\"(.*?)\"') result = pattern.findall(r.text) return result[1].replace("\\r\\n",'')
import re,requests try: from urllib import quote,unquote except ImportError: from urllib.parse import quote,unquote
import json
def qingke_robot(msg): url = r"http://api.qingyunke.com/api.php?key=free&appid=0&msg=%s" % (quote(msg))
try: from urllib.request import urlopen except ImportError: from urllib2 import urlopen
result = urlopen(url) response = json.loads(result.read().decode("utf-8")) code = response['result'] if code != 0: return "error" content = response['content'].replace('{br}','\n') return content
@itchat.msg_register('Text') def text_reply(msg): global BASEMSG global AUTO_REPLAY
if msg['Text'].lower() == "open": AUTO_REPLAY=1 return "自动聊天功能已打开." elif msg['Text'].lower() == "close": AUTO_REPLAY=0 return "自动聊天功能已关闭." elif msg['Text'].lower() == "add": BASEMSG = "[主人暂时不在,我是周小秘 ]:" return "添加附加内容成功" elif msg['Text'].lower() == "del": BASEMSG = "" AUTO_REPLAY=0 return "取消附加内容成功"
if AUTO_REPLAY > 0 : if BASEMSG != "": return BASEMSG + qingke_robot(msg['Text']) return qingke_robot(msg['Text'])
if __name__ == '__main__': itchat.auto_login(enableCmdQR=2)
myUserName = itchat.get_friends(update=True)[0]["UserName"] itchat.run(debug=True)
|