import itchat
import requests
def get_response(msg):
apiUrl ='http://www.tuling123.com/openapi/api'? #改成你自己的圖靈機(jī)器人的api
? ? data={
'key':'1d889b1679024d10893254dee2f3fe49',? # Tuling Key
? ? ? ? 'info': msg,? # 這是我們發(fā)出去的消息
? ? ? ? 'userid':'墨道',? # 這里可隨意修改
? ? }
# 通過如下命令發(fā)送一個post請求
? ? r = requests.post(apiUrl, data=data).json()
print(r.get('text'))
return r.get('text')
#用于接收個人信息
@itchat.msg_register([itchat.content.TEXT,itchat.content.PICTURE,itchat.content.RECORDING,itchat.content.ATTACHMENT,itchat.content.VIDEO,itchat.content.MAP,itchat.content.VOICE,itchat.content.ATTACHMENT,itchat.content.NOTE,itchat.content.CARD],isFriendChat=True)
def print_content(msg):
user = msg['User']
groupNickName = user['NickName']
groupId = user['UserName']
msg_id = msg['MsgId']
msg_from_user = msg['User']['NickName']
msg_content = msg['Content']
msg_create_time = msg['CreateTime']
msg_type = msg['Type']
temp_msg ="無語"
? ? if u'Text' in msg_type:
temp_msg = msg['Text']
elif u'Recording' in msg_type:
temp_msg ='說的什么啊'
? ? elif u'Picture' in msg_type:
temp_msg ='這是黃圖嗎'
? ? else:
temp_msg ="這是什么啊"
? ? return get_response(temp_msg)
#用于接收群里面的對話消息#
@itchat.msg_register([itchat.content.TEXT,itchat.content.PICTURE,itchat.content.RECORDING,itchat.content.ATTACHMENT,itchat.content.VIDEO,itchat.content.MAP,itchat.content.VOICE,itchat.content.ATTACHMENT,itchat.content.NOTE,itchat.content.CARD], isGroupChat=True)
def print_content_group(msg):
msg_actualUserName = msg['ActualUserName']
msg_actual_nick_name = msg['ActualNickName']
from_user_name = msg['FromUserName']
toUserid = msg['ToUserName']
group = msg['User']
groupNickName = group['NickName']
groupId = group['UserName']
# if '@@f14e67cf03e051016ab2f7fb9e65c4cc7dbf070ab576782476c036fda89e3c11' in toUserid:#金家
? ? #? ? return '哦'
? ? # if '@@ffdfb0126f4b674e538c6fbd852e0f80f713801cab2dfd981645b7d2a84a05bd' in toUserid:#高層
? ? #? ? return '哦'
# if '@@3beb912db64a8faf7061e18a269ed8acdd0e08a4c975987044aea6c53f3d8f1e' in toUserid:
? ? #? ? return '哦'
? ? flag =0
? ? if '投資' not in groupNickName:
flag = flag +1
? ? if '屌絲' not in groupNickName:
flag = flag +1
? ? if '360' not in groupNickName:
flag = flag +1
? ? if flag ==3:
# 不可發(fā)送的群
? ? ? ? return None
? ? msg_id = msg['MsgId']
msg_from_user = msg['User']['NickName']
msg_content = msg['Content']
msg_create_time = msg['CreateTime']
msg_type = msg['Type']
temp_msg ="無語"
? ? if u'Text' in msg_type:
temp_msg = msg['Text']
elif u'Recording' in msg_type:
temp_msg ='說的什么啊'
? ? elif u'Picture' in msg_type:
temp_msg ='這是黃圖嗎'
? ? else:
temp_msg ="這是什么啊"
? ? return get_response(msg['Text'])
itchat.auto_login(True)
itchat.run()