鱼C论坛

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

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

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

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

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

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

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

        # Setting the window size
        window_width = 500
        window_height = 500

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

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

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

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

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

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

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

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

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

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

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

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

    def get_signature(self):
        data = {
            "userid": self.userid
        }
        response = requests.post(self.signature_url, json=data)
        response_data = response.json()
        return response_data['signature']

    def post_chat_message(self, query):
        data = {
            "signature": self.signature,
            "query": query
        }
        response = requests.post(self.chat_url, json=data)
        response_data = response.json()
        return response_data['answer']

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

root = Tk()
my_gui = ChatApp(root)
root.mainloop()

最佳答案

查看完整内容

一个简单的 GUI 界面:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

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

        # Setting the window size
        window_width = 500
        window_height = 500

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

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

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

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

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

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

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

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

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

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

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

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

    def get_signature(self):
        data = {
            "userid": self.userid
        }
        response = requests.post(self.signature_url, json=data)
        response_data = response.json()
        return response_data['signature']

    def post_chat_message(self, query):
        data = {
            "signature": self.signature,
            "query": query
        }
        response = requests.post(self.chat_url, json=data)
        response_data = response.json()
        return response_data['answer']

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

root = Tk()
my_gui = ChatApp(root)
root.mainloop()

评分

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

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 10:51:59 | 显示全部楼层
看不懂你在说啥
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

GPT都能看懂,你看不懂(虽然他说的是错的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

我正在开发最佳脚本(不知道为什么之前的失效了,打开程序正常,可就是不肯回答问题)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-6-27 12:10:24 | 显示全部楼层
就这么把你的token放出来了?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

你别想干什么坏事,不然你就惨了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

哇!!1不错!!!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

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

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

        # Setting the window size
        window_width = 500
        window_height = 500

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

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

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

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

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

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

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

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

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

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

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

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

    def get_signature(self):
        data = {
            "userid": self.userid
        }
        response = requests.post(self.signature_url, json=data)
        response_data = response.json()
        return response_data['signature']

    def post_chat_message(self, query):
        data = {
            "signature": self.signature,
            "query": query
        }
        response = requests.post(self.chat_url, json=data)
        response_data = response.json()
        return response_data['answer']

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

root = Tk()
my_gui = ChatApp(root)
root.mainloop()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

其实就算你不把token放出来,访问你那个机器人然后抓包也能抓得到
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

你!想!干!啥!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-22 17:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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