newBingAPI整理

发布于 2023-03-18  655 次阅读


AI 摘要

新BingAPI整理提供了获取ConversationID的方法。如果在中国大陆境内访问,会自动重定向到https://cn.bing.com/turing/conversation/create,但不会影响使用。通过发送GET请求,可以获取到包含conversationId、clientId和conversationSignature等字段的返回数据。根据返回的数据中的value字段,可以判断请求是否成功,或者出现了权限访问问题或未登录等情况。此外,还可以通过WebSocket与NewBing进行聊天,需要在数据包末尾加上Unicode字符""。要与服务器建立连接,需要按照指定格式发送一些信息,并等待服务器回复。发送聊天消息时,需要构建特定格式的JSON数据,包括消息内容、时间戳、作者等信息。

获取ConversationID

GET https://www.bing.com/turing/conversation/create

中国大陆境内会自动301https://cn.bing.com/turing/conversation/create但是不影响使用

返回数据

返回字段 返回类型 描述
result   JsonObject  见下方#result
conversationId String 对话ID
格式为 51D|BingProd|***
clientId String 每个账号固定
conversationSignature String conversation签名
ParentJson

result 中的字段 返回类型 预期数据
value String Success
如不为 Success 则上方的字段只存在 result
message String 错误原因
result

返回数据示例

成功获取

{
	"conversationId": "51D|BingProd|***",
	"clientId": "***",
	"conversationSignature": "***",
	"result": {
		"value": "Success",
		"message": null
	}
}

账户没有权限访问

{
	"result": {
		"value": "Forbidden",
		"message": "Sorry, you are not allowed to access this service."
	}
}

未登陆

{
	"result": {
		"value": "UnauthorizedRequest",
		"message": "Sorry, you need to login first to access this service."
	}
}

与NewBing进行聊天

Websocket wss://sydney.bing.com/sydney/ChatHub

数据包发送

需要在每个数据的末尾加上一个Unicode字符""(\u001e)

连接

  1. 与服务器建立连接时发送一个{"protocol":"json","version":1}
  2. 等待服务器回复一个空的JSON字符串 {}
  3. 发送{"type":6}以及一个包含以下数据的Json字符串

Json格式

字段 预期类型 预期内容
arguments Array 见下方#arguments
invocationId String 本次聊天次数,从0开始自增
target String chat
type Int 4
ParentJson

字段 预期类型 预期内容
source String cib
optionsSets Array ["nlu_direct_response_filter", "deepleo", "disable_emoji_spoken_text", "responsible_ai_policy_235", "enablemm", "harmonyv3", "wlthrottle", "dv3sugg"]
allowedMessageTypes Array ["Chat", "InternalSearchQuery", "InternalSearchResult", "Disengaged", "InternalLoaderMessage", "RenderCardRequest", "AdsQuery", "SemanticSerp", "GenerateContentQuery", "SearchQuery"]
sliceIds Array ["anidtest", "scfraithct", "scraith70", "sydpayajaxlog", "perfinstcf", "linkimgincf", "0310wlthrot", "313localgnds0"]
traceId String 随机的32位数字+小写字母字符串
isStartOfSession Boolean 是否为本次conversation第一次聊天
message JsonObject 见下方#message
conversationSignature String 上方获取到的conversationSignature
participant JsonObject 见下方#participant
conversationId String 上方获取到的conversationId
arguments

字段 预期类型 预期内容
locale String (ISO-639 Language Code)-(ISO-3166 Country Codes)
market String (ISO-639 Language Code)-(ISO-3166 Country Codes)
region String 国家(可不填)
location String 经纬度(可不填)
locationHints JsonArray 位置(可不填)
timestamp String yyyy-MM-dd'T'hh:mm:ssZZZZZ
2023-03-18T16:04:07+08:00
author String user
inputMethod String Keyboard
text String 你要询问的内容
messageType String Chat
message

字段 预期类型 预期内容
id String 上方获取到的clientId
participant

json示例

   json示例  ==>  展开 / 收起

获取数据

  • 服务器会回复json格式的数据,其中的type为类型
  • type=1 数据更新事件
  • type=2 本次聊天结束
  • type=7 客户端数据格式出错, 服务器会自动断开
  • type=6 时需要给服务器发送{"type":6}以保持连接
  • type=3 数据响应完毕, 此时客户端断开

   type=2时的Json数据  ==>  展开 / 收起

间歇性发奋图强,持续性混吃等死
最后更新于 2024-05-04