依赖库:wxpy,json
代码:
from wxpy import *
import requests
import json
####windows下用下面这个登陆,用的是图片二维码
#bot = Bot()
###linux下用下面这个,用的是终端二维码
bot = Bot(console_qr=2,cache_path="botoo.pkl")
# 获取好友
name = input("好友的名字:")
# 例如:dear = bot.friends().search('往事随风')[0]
dear = bot.friends().search(name)[0]
n = len(name)+3
# 注册获得个人的图灵机器人key 填入
# 这里用的是api.qingyunke.com
#tuling = Tuling(api_key='keykeykeykeykeykeykey')
#url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg='+msg
#使用图灵机器人自动与指定好友聊天
@bot.register(dear)
def reply_my_friend(msg):
print(msg)
zz = str(msg)[n:-7]
url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg='+zz
url = url.replace("小逸","菲菲") #修改特别信息
# print(url)
k = json.loads(requests.get(url).text)['content']
k = k.replace("{br}","\n")
k = k.replace("群主",name).replace("网友",name).replace("菲菲","小逸")
print(k)
msg.reply(k)
embed()
########################################################################
qq机器人:
依赖库:qqbot
安装:pip install qqbot
”’
bot : QQBot 对象,提供 List/SendTo/Stop/Restart 等接口,详见本文档第五节
contact : QContact 对象,消息的发送者,具有 ctype/qq/uin/nick/mark/card/name 等属性
member : QContact 对象,仅当本消息为 群消息或讨论组消息 时有效,代表实际发消息的成员
content : str 对象,消息内容
”’
# -*- coding: utf-8 -*-
import json,requests
name = raw_input("好友名字:")
def onQQMessage(bot, contact, member, content):
if name == contact.name:
if (content == "小逸"):
url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg=菲菲'
else:
url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg='+content
url.replace("小逸","菲菲").replace("\u5c0f\u9038","菲菲")
print(url)
k = json.loads(requests.get(url).text)['content']
k = k.replace("{br}","\n")
k = k.replace(u"菲菲",u"小逸")
bot.SendTo(contact, k)
else:
print contact.name

