#coding:utf-8
"""
Function:itchat的使用
Author:cici
"""
import itchat
#登录
itchat.auto_login(hotReload=True)
#给文件助手发消息
#itchat.send("你好,我是郭",toUserName="filehelper")
#给好友发消息
print(itchat.get_friends()[1])
#获取NickName
nickname=itchat.get_friends()[1]["NickName"]
#获取Username
username=itchat.get_friends()[1]["UserName"]
print(nickname)
print(username)
#给最近的好友发消息
#注意UserNmae是微信生成的一个字符串
#itchat.send("hello,world",toUserName=username)
#通过search方法找到指定的联系人,并发送消息,比如我的好友韩鹏
st=itchat.search_friends(name='boss')
user=st[0].UserName
for i in range(50):
itchat.send("有没有绝望", toUserName=user)



篇二

import itchat
import requests
from itchat.content import *
KEY = "3017f365768c406e97eb99019cdc4a2d"
UID = "gzd714155624"
#发文本类型的数据
# @itchat.msg_register('Text')
# def text_reply(msg):
# if msg['Text']=="你好":
# return "你好,很高兴认识您"
# elif msg['Text']=='傻逼':
# return "我是傻逼,你是什么?"

# else:
# return "[自动回复]我现在不在,稍后联系您"
# #发文件类型的数据
# @itchat.msg_register('File')
# def file_reply(msg):
# return '你发个文件让我说什么好呢!'
def get_reply(msg):
api_tuling = "http://www.tuling123.com/openapi/api"
data = {
'key': KEY,
'info': msg,
'userid': UID,
}
ret = requests.post(api_tuling, data=data).json()
return ret.get('text')
@itchat.msg_register('Text')
def text_reply(msg):
#返回调用图灵机器人的返回消息
return get_reply(msg['Text'])
@itchat.msg_register([TEXT,MAP,CARD,NOTE,""",PICTURE,RECORDING,ATTACHMENT,VIDEO"""],isGroupChat=True)
def group_reply(msg):

if msg['isAt']:
return get_reply(msg['Text'])
return # '@%s@%s' % (typeSymbol,msg.fileName)
itchat.auto_login(hotReload=True)
itchat.run()



posted on 2018-05-10 10:03  guodashen  阅读(85)  评论(0)    收藏  举报