包来源
@作者 :B站/抖音/微博/小红书/公众号,都叫:程序员晚枫
@微信 :CoderWanFeng : https://mp.weixin.qq.com/s/B1V6KeXc7IOEB8DgXLWv3g
@个人网站 :www.python-office.com
该文章仅用于交流学习,具体的包文件教程等请参考原作者
from PyOfficeRobot.core.WeChatType import WeChat
import requests
url = 'gptUrl'
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36",
"Origin": "gptUrl"
}
wx = WeChat()
wx.GetSessionList()
wx.ChatWith('要发送的人')
wx.SendMsg('这是一条测试消息', '要发送的人')
while True:
# 检测到对话框出现@gpt发送
if "@gpt" in wx.GetAllMessage[-1][1]:
qu = wx.GetAllMessage[-1][1].replace("@gpt", "")
wx.SendMsg(wx.GetAllMessage[-1][0]+'请稍等...', '要发送的人')
response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
result_text = response.content.decode("utf-8")
wx.SendMsg(repr(str(result_text)), '要发送的人')
else:
wx.SendMsg(wx.GetAllMessage[-1][0] + '服务链接超时', '要发送的人')