赞
踩
from wxauto import *
send_msg = '你好' # 发送消息内容
who = '文件传输助手' # 指定发送对象
# 获取当前微信客户端
wx = WeChat()
# 向某人发送消息(以`文件传输助手`为例)
wx.ChatWith(who) # 打开`文件传输助手`聊天窗口
wx.SendMsg(send_msg) # 向`文件传输助手`发送消息:你好~
样例:
import requests
from wxauto import *
import time
import re
send_msg = '你好' # 发送消息内容
who = '文件传输助手' # 指定发送对象
# 获取当前微信客户端
wx = WeChat()
# 获取会话列表
SessionList=wx.GetSessionList()
print(wx.GetAllMessage[-1][1][:4])
print(wx.GetSessionList()[4])
# 群聊白名单,此将不会触发自动回复名单内
rigthlist={"没太多对错":0,"":0}
while (True):
# 自动回复
print(wx.GetAllMessage[-1])
# wx.GetSessionList()[4] != SessionList[4] and
if ( wx.GetAllMessage[-1][0]!='你的id'
if(wx.GetSessionList()[4] in rigthlist.keys() ):
print("触发白名单,该群不做回复!")
else:
print(SessionList[4] + wx.GetSessionList()[4] + "\n")
SessionList = wx.GetSessionList()
who = wx.GetSessionList()[4]
wx.ChatWith(who)
wx.SendMsg("自动回复:我的主人暂时不在电脑前,请稍候联系!")
# ai回复
#此处利用了微信对话开放平台的api
url = 'https://openai.weixin.qq.com/openapi/sign/'
data = {
'userid': "",
}
r = requests.post(url, data, )
url = "https://openai.weixin.qq.com/openapi/aibot/"
# 最近的消息
query = wx.GetAllMessage[-1][1]
data = {
"signature":r.json()["signature"],
"query": query
}
r = requests.post(url, data, )
print(r.json()["answer"])
who = SessionList[4]
wx.ChatWith(who)
wx.SendMsg("来自助手ai小微的消息:" + r.json()["answer"])
#有人艾特你
if(wx.GetAllMessage[-1][1][:4]=="你的群昵称"
#此处使用了另一个免费的ai回复api
url = 'http://api.qingyunke.com/api.php'
data = {
'key': "free",
'appid': '0',
"msg": wx.GetAllMessage[-1][1][4:]
}
r = requests.get(url, data, )
print(r.json())
senddata=r.json()["content"]
who = wx.GetSessionList()[4]
wx.ChatWith(who)
wx.SendMsg("来自助手小皮的消息:"+senddata)
time.sleep(2)
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。