鱼C论坛

 找回密码
 立即注册
查看: 1687|回复: 10

[已解决]设计连接自然一号(ChatGaoshan)的Python程序

[复制链接]
发表于 2023-6-27 10:50:46 | 显示全部楼层 |阅读模式
15鱼币
前些天不是制作了自然一号嘛
现在要用Python搞个接口,要求:
1、GUI或非GUI都可以
2、至少保证输入输出、人称
3、接口数据:
APPID:
  1. kqyU4h4uUDsSkwn
复制代码

Token:
  1. n1l6sJwy5MLw3SiQTtqDCMqV54XIev
复制代码

Encoding AESKey:
  1. tF6XFqWLAh6hXuICjGL3oAsT4S2yrMfU7GaZZGf9KVY
复制代码

认证模式:POST

(以上接口喜欢的人也可以调用哦)

GPT回答也可以,就一个要求:请仔细核查后再进行!!!!!
自然一号体验连接:https://chatbot.weixin.qq.com/we ... 6%E4%B8%80%E5%8F%B7

这是微信对话开放平台提供的
最佳答案
2023-6-27 10:50:47
一个简单的 GUI 界面:
  1. import json
  2. import requests
  3. from tkinter import *

  4. class ChatApp:
  5.     def __init__(self, master):
  6.         self.master = master
  7.         master.title("Chatbot GUI")

  8.         # Setting the window size
  9.         window_width = 500
  10.         window_height = 500

  11.         # Gets both half the screen width/height and window width/height
  12.         position_right = int(master.winfo_screenwidth()/2 - window_width/2)
  13.         position_down = int(master.winfo_screenheight()/2 - window_height/2)

  14.         # Positions the window in the center of the page.
  15.         master.geometry(f'{window_width}x{window_height}+{position_right}+{position_down}')

  16.         self.userid = 'alsjdasf12'  # replace with your user id
  17.         self.signature_url = 'https://chatbot.weixin.qq.com/openapi/sign/n1l6sJwy5MLw3SiQTtqDCMqV54XIev'
  18.         self.chat_url = 'https://chatbot.weixin.qq.com/openapi/aibot/n1l6sJwy5MLw3SiQTtqDCMqV54XIev'
  19.         self.signature = self.get_signature()

  20.         self.chat_frame = Frame(master)
  21.         self.chat_frame.pack(fill=BOTH, expand=True)

  22.         self.scrollbar = Scrollbar(self.chat_frame)
  23.         self.chat_listbox = Listbox(self.chat_frame, yscrollcommand=self.scrollbar.set)
  24.         self.scrollbar.config(command=self.chat_listbox.yview)
  25.         self.chat_listbox.pack(side="left", fill="both", expand=True)
  26.         self.scrollbar.pack(side="right", fill="y")

  27.         self.entry_frame = Frame(master)
  28.         self.entry_frame.pack(fill=X, side=BOTTOM)

  29.         self.entry_text = StringVar()
  30.         self.entry_field = Entry(self.entry_frame, text=self.entry_text)
  31.         self.entry_field.bind("<Return>", self.send_message_event)
  32.         self.entry_field.pack(side="left", fill="x", expand=True)

  33.         self.send_button = Button(self.entry_frame, text="发送", command=self.send_message)
  34.         self.send_button.pack(side="right")

  35.         self.new_chat_button = Button(self.entry_frame, text="开始新的对话", command=self.start_new_chat)
  36.         self.new_chat_button.pack(side="right")

  37.     def send_message_event(self, event):
  38.         self.send_message()

  39.     def send_message(self):
  40.         message = self.entry_text.get()
  41.         self.chat_listbox.insert(END, "你: " + message)
  42.         self.entry_text.set("")

  43.         response = self.post_chat_message(message)
  44.         self.chat_listbox.insert(END, "机器人: " + response)

  45.     def get_signature(self):
  46.         data = {
  47.             "userid": self.userid
  48.         }
  49.         response = requests.post(self.signature_url, json=data)
  50.         response_data = response.json()
  51.         return response_data['signature']

  52.     def post_chat_message(self, query):
  53.         data = {
  54.             "signature": self.signature,
  55.             "query": query
  56.         }
  57.         response = requests.post(self.chat_url, json=data)
  58.         response_data = response.json()
  59.         return response_data['answer']

  60.     def start_new_chat(self):
  61.         self.chat_listbox.delete(0, END)
  62.         self.signature = self.get_signature()

  63. root = Tk()
  64. my_gui = ChatApp(root)
  65. root.mainloop()
复制代码

最佳答案

查看完整内容

一个简单的 GUI 界面:
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 10:50:47 | 显示全部楼层    本楼为最佳答案   
一个简单的 GUI 界面:
  1. import json
  2. import requests
  3. from tkinter import *

  4. class ChatApp:
  5.     def __init__(self, master):
  6.         self.master = master
  7.         master.title("Chatbot GUI")

  8.         # Setting the window size
  9.         window_width = 500
  10.         window_height = 500

  11.         # Gets both half the screen width/height and window width/height
  12.         position_right = int(master.winfo_screenwidth()/2 - window_width/2)
  13.         position_down = int(master.winfo_screenheight()/2 - window_height/2)

  14.         # Positions the window in the center of the page.
  15.         master.geometry(f'{window_width}x{window_height}+{position_right}+{position_down}')

  16.         self.userid = 'alsjdasf12'  # replace with your user id
  17.         self.signature_url = 'https://chatbot.weixin.qq.com/openapi/sign/n1l6sJwy5MLw3SiQTtqDCMqV54XIev'
  18.         self.chat_url = 'https://chatbot.weixin.qq.com/openapi/aibot/n1l6sJwy5MLw3SiQTtqDCMqV54XIev'
  19.         self.signature = self.get_signature()

  20.         self.chat_frame = Frame(master)
  21.         self.chat_frame.pack(fill=BOTH, expand=True)

  22.         self.scrollbar = Scrollbar(self.chat_frame)
  23.         self.chat_listbox = Listbox(self.chat_frame, yscrollcommand=self.scrollbar.set)
  24.         self.scrollbar.config(command=self.chat_listbox.yview)
  25.         self.chat_listbox.pack(side="left", fill="both", expand=True)
  26.         self.scrollbar.pack(side="right", fill="y")

  27.         self.entry_frame = Frame(master)
  28.         self.entry_frame.pack(fill=X, side=BOTTOM)

  29.         self.entry_text = StringVar()
  30.         self.entry_field = Entry(self.entry_frame, text=self.entry_text)
  31.         self.entry_field.bind("<Return>", self.send_message_event)
  32.         self.entry_field.pack(side="left", fill="x", expand=True)

  33.         self.send_button = Button(self.entry_frame, text="发送", command=self.send_message)
  34.         self.send_button.pack(side="right")

  35.         self.new_chat_button = Button(self.entry_frame, text="开始新的对话", command=self.start_new_chat)
  36.         self.new_chat_button.pack(side="right")

  37.     def send_message_event(self, event):
  38.         self.send_message()

  39.     def send_message(self):
  40.         message = self.entry_text.get()
  41.         self.chat_listbox.insert(END, "你: " + message)
  42.         self.entry_text.set("")

  43.         response = self.post_chat_message(message)
  44.         self.chat_listbox.insert(END, "机器人: " + response)

  45.     def get_signature(self):
  46.         data = {
  47.             "userid": self.userid
  48.         }
  49.         response = requests.post(self.signature_url, json=data)
  50.         response_data = response.json()
  51.         return response_data['signature']

  52.     def post_chat_message(self, query):
  53.         data = {
  54.             "signature": self.signature,
  55.             "query": query
  56.         }
  57.         response = requests.post(self.chat_url, json=data)
  58.         response_data = response.json()
  59.         return response_data['answer']

  60.     def start_new_chat(self):
  61.         self.chat_listbox.delete(0, END)
  62.         self.signature = self.get_signature()

  63. root = Tk()
  64. my_gui = ChatApp(root)
  65. root.mainloop()
复制代码

评分

参与人数 1荣誉 +5 鱼币 +5 贡献 +3 收起 理由
高山 + 5 + 5 + 3 谢谢!

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 10:51:59 | 显示全部楼层
看不懂你在说啥
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-6-27 11:01:56 | 显示全部楼层

GPT都能看懂,你看不懂(虽然他说的是错的
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 11:03:11 | 显示全部楼层
高山 发表于 2023-6-27 11:01
GPT都能看懂,你看不懂(虽然他说的是错的

我正在开发最佳脚本(不知道为什么之前的失效了,打开程序正常,可就是不肯回答问题)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 12:10:24 | 显示全部楼层
就这么把你的token放出来了?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-6-27 12:26:04 | 显示全部楼层
isdkz 发表于 2023-6-27 12:10
就这么把你的token放出来了?

你别想干什么坏事,不然你就惨了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-6-27 12:45:26 | 显示全部楼层
isdkz 发表于 2023-6-27 12:38
一个简单的 GUI 界面:

哇!!1不错!!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 12:47:11 | 显示全部楼层
高山 发表于 2023-6-27 12:45
哇!!1不错!!!!

那个不会滚动到最新的对话,这个改进了一下下:
  1. import json
  2. import requests
  3. from tkinter import *

  4. class ChatApp:
  5.     def __init__(self, master):
  6.         self.master = master
  7.         master.title("Chatbot GUI")

  8.         # Setting the window size
  9.         window_width = 500
  10.         window_height = 500

  11.         # Gets both half the screen width/height and window width/height
  12.         position_right = int(master.winfo_screenwidth()/2 - window_width/2)
  13.         position_down = int(master.winfo_screenheight()/2 - window_height/2)

  14.         # Positions the window in the center of the page.
  15.         master.geometry(f'{window_width}x{window_height}+{position_right}+{position_down}')

  16.         self.userid = 'alsjdasf12'  # replace with your user id
  17.         self.signature_url = 'https://chatbot.weixin.qq.com/openapi/sign/n1l6sJwy5MLw3SiQTtqDCMqV54XIev'
  18.         self.chat_url = 'https://chatbot.weixin.qq.com/openapi/aibot/n1l6sJwy5MLw3SiQTtqDCMqV54XIev'
  19.         self.signature = self.get_signature()

  20.         self.chat_frame = Frame(master)
  21.         self.chat_frame.pack(fill=BOTH, expand=True)

  22.         self.scrollbar = Scrollbar(self.chat_frame)
  23.         self.chat_listbox = Listbox(self.chat_frame, yscrollcommand=self.scrollbar.set)
  24.         self.scrollbar.config(command=self.chat_listbox.yview)
  25.         self.chat_listbox.pack(side="left", fill="both", expand=True)
  26.         self.scrollbar.pack(side="right", fill="y")

  27.         self.entry_frame = Frame(master)
  28.         self.entry_frame.pack(fill=X, side=BOTTOM)

  29.         self.entry_text = StringVar()
  30.         self.entry_field = Entry(self.entry_frame, text=self.entry_text)
  31.         self.entry_field.bind("<Return>", self.send_message_event)
  32.         self.entry_field.pack(side="left", fill="x", expand=True)

  33.         self.send_button = Button(self.entry_frame, text="发送", command=self.send_message)
  34.         self.send_button.pack(side="right")

  35.         self.new_chat_button = Button(self.entry_frame, text="开始新的对话", command=self.start_new_chat)
  36.         self.new_chat_button.pack(side="right")

  37.     def send_message_event(self, event):
  38.         self.send_message()

  39.     def send_message(self):
  40.         message = self.entry_text.get()
  41.         self.chat_listbox.insert(END, "你: " + message)
  42.         self.entry_text.set("")

  43.         response = self.post_chat_message(message)
  44.         self.chat_listbox.insert(END, "机器人: " + response)
  45.         self.chat_listbox.see(END)  # This line makes sure the latest message is visible

  46.     def get_signature(self):
  47.         data = {
  48.             "userid": self.userid
  49.         }
  50.         response = requests.post(self.signature_url, json=data)
  51.         response_data = response.json()
  52.         return response_data['signature']

  53.     def post_chat_message(self, query):
  54.         data = {
  55.             "signature": self.signature,
  56.             "query": query
  57.         }
  58.         response = requests.post(self.chat_url, json=data)
  59.         response_data = response.json()
  60.         return response_data['answer']

  61.     def start_new_chat(self):
  62.         self.chat_listbox.delete(0, END)
  63.         self.signature = self.get_signature()

  64. root = Tk()
  65. my_gui = ChatApp(root)
  66. root.mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 12:52:13 | 显示全部楼层
高山 发表于 2023-6-27 12:26
你别想干什么坏事,不然你就惨了

其实就算你不把token放出来,访问你那个机器人然后抓包也能抓得到
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-6-27 12:58:59 | 显示全部楼层
isdkz 发表于 2023-6-27 12:52
其实就算你不把token放出来,访问你那个机器人然后抓包也能抓得到

你!想!干!啥!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-24 04:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表