ai项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
3.6 KiB

import time
import requests
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import base64, json
KEY = b"qikgqemuuiukckyc"
IV = b"1234567887654321"
def encrypt_payload(e):
data = json.dumps(e, separators=(",", ":")).encode()
cipher = AES.new(KEY, AES.MODE_CBC, IV)
enc = cipher.encrypt(pad(data, 16))
return base64.b64encode(enc).decode()
t = int(time.time()*1000)
def index():
url = "https://yiyan.baidu.com/"
headers = {
"Host": "yiyan.baidu.com",
"Connection": "keep-alive",
# "sec-ch-ua": ""Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"",
"sec-ch-ua-mobile": "?0",
# "sec-ch-ua-platform": ""Windows"",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "zh-CN,zh;q=0.9",
# "Cookie": "RT="z=1&dm=baidu.com&si=7dba0974-80fd-4072-874e-e0350e75fdf3&ss=mkuvum3j&sl=7&tt=77k&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=5qoc&ul=9d2k&hd=9dub"",
}
resp = requests.request(method="GET",url=url, headers=headers, verify=False)
return '; '.join([f'{name}={value}' for name, value in resp.cookies.items()]),resp.headers.get("Set-Cookie")
def wxyy(Token,text,cookie_str):
url = "https://yiyan.baidu.com/eb/chat/conversation/v2"
headers = {
"Host": "yiyan.baidu.com",
"Connection": "keep-alive",
"sec-ch-ua-platform": "Windows",
"Device-Type": "pc",
"sec-ch-ua": '"Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
"sec-ch-ua-mobile": "?0",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
"Accept": "text/event-stream,application/json, text/event-stream",
"Acs-Token": Token,
"Content-Type": "application/json",
"Origin": "https://yiyan.baidu.com",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Referer": "https://yiyan.baidu.com/chat/",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cookie": cookie_str
}
#
post_data = {"sign":Token,"timestamp":int(time.time()*1000),"deviceType":"pc","jt":"","text":text,"sessionId":"","sessionName":text,"pluginIds":"","type":10,"plugins":[],"pluginInfo":[],"deepThoughtStatus":2,"isAgentSquare":False,"model":"EB45T","newAppSessionId":None,"file_ids":[],"assistantId":"","enableNewTextCreationGoal":False,"isSlowThought":False,"parentChatId":"0","isNewYiyan":True}
resp = requests.request(method="POST",url=url, json=post_data, headers=headers, verify=True)
print(resp.text)
# cookie_str,baiduid =index()
# e ={"d0":"ka0oitptemc1jfshcdsx","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36","baiduid":baiduid,"platform":"Win32","d23":0,"d1":"","d2":0,"hf":"","hfe":"","h0":"","d78":57815,"d420":0,"clientTs":t,"version":"1.4.0.3","extra":"","odkp":0}
# a= encrypt_payload(e)
# Token = '1769396406334_'+str(t)+"_"+a
# # print(Token)
# text = '苹果手机怎么样'
# wxyy(Token,text,cookie_str)