Skip to content

Commit

Permalink
处理跃问域名修改和登录态策略变更
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed May 16, 2024
1 parent bc34eef commit ee861b7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,18 @@ https://udify.app/chat/RGqDVPHspgQgGSgf

[stepchat.cn](https://stepchat.cn) 获取Oasis-Token

进入StepChat随便发起一个对话,然后F12打开开发者工具,从Application > Cookies中找到`Oasis-Token`的值,这将作为Authorization的Bearer Token值:`Authorization: Bearer TOKEN`
进入StepChat随便发起一个对话,然后F12打开开发者工具。

1. 从Application > LocalStorage中找到 `deviceId` 的值(去除双引号),如:`267bcc81a01c2032a11a3fc6ec3e372c380eb9d1`

![example7](./doc/example-7.png)

2. 从Application > Cookies中找到 `Oasis-Token` 的值,如:`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...`

![example5](./doc/example-5.png)

3.`deviceId``Oasis-Token` 使用 `@` 拼接为Token,这将作为Authorization的Bearer Token值:`Authorization: Bearer 267bcc81a01c2032a11a3fc6ec3e372c380eb9d1@eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...`

### 多账号接入

你可以通过提供多个账号的refresh_token并使用`,`拼接提供:
Expand Down Expand Up @@ -425,7 +433,7 @@ Authorization: Bearer [refresh_token]
请求数据:
```json
{
"token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9..."
"token": "267bcc81a01c2032a11a3fc6ec3e372c380eb9d1@eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
```

Expand Down
Binary file added doc/example-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 22 additions & 21 deletions src/api/controllers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const FAKE_HEADERS = {
Accept: "*/*",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "zh-CN,zh;q=0.9",
Origin: "https://stepchat.cn",
Origin: "https://yuewen.cn",
"Connect-Protocol-Version": "1",
"Oasis-Appid": "10200",
"Oasis-Platform": "web",
"Oasis-Webid": util.uuid(),
"Oasis-Webid": "265bcc81a05c2032a11a6fc6ec3e372c380eb9d2",
"Sec-Ch-Ua":
'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
"Sec-Ch-Ua-Mobile": "?0",
Expand Down Expand Up @@ -59,23 +59,24 @@ async function requestToken(refreshToken: string) {
accessTokenRequestQueueMap[refreshToken] = [];
logger.info(`Refresh token: ${refreshToken}`);
const result = await (async () => {
const [deviceId, token] = refreshToken.split('@');
const result = await axios.post(
"https://stepchat.cn/passport/proto.api.passport.v1.PassportService/RegisterDevice",
"https://yuewen.cn/passport/proto.api.passport.v1.PassportService/RegisterDevice",
{},
{
headers: {
Cookie: `Oasis-Token=${refreshToken}`,
Referer: "https://stepchat.cn/chats/new",
Cookie: `Oasis-Token=${token}`,
Referer: "https://yuewen.cn/chats/new",
...FAKE_HEADERS,
"Oasis-Webid": deviceId
},
timeout: 15000,
validateStatus: () => true,
}
);
const {
accessToken: { raw: accessTokenRaw },
refreshToken: { raw: refreshTokenRaw },
device: { deviceID: deviceId },
refreshToken: { raw: refreshTokenRaw }
} = checkResult(result, refreshToken);
return {
deviceId,
Expand Down Expand Up @@ -140,15 +141,15 @@ async function acquireToken(refreshToken: string) {
async function createConversation(name: string, refreshToken: string) {
const { deviceId, token } = await acquireToken(refreshToken);
const result = await axios.post(
"https://stepchat.cn/api/proto.chat.v1.ChatService/CreateChat",
"https://yuewen.cn/api/proto.chat.v1.ChatService/CreateChat",
{
chatName: name,
},
{
headers: {
Cookie: generateCookie(deviceId, token),
"Oasis-Webid": deviceId,
Referer: "https://stepchat.cn/chats/new",
Referer: "https://yuewen.cn/chats/new",
...FAKE_HEADERS,
},
timeout: 15000,
Expand All @@ -169,15 +170,15 @@ async function createConversation(name: string, refreshToken: string) {
async function removeConversation(convId: string, refreshToken: string) {
const { deviceId, token } = await acquireToken(refreshToken);
const result = await axios.post(
`https://stepchat.cn/api/proto.chat.v1.ChatService/DelChat`,
`https://yuewen.cn/api/proto.chat.v1.ChatService/DelChat`,
{
chatIds: [convId],
},
{
headers: {
Cookie: generateCookie(deviceId, token),
"Oasis-Webid": deviceId,
Referer: `https://stepchat.cn/chats/${convId}`,
Referer: `https://yuewen.cn/chats/${convId}`,
...FAKE_HEADERS,
},
timeout: 15000,
Expand Down Expand Up @@ -220,14 +221,14 @@ async function createCompletion(
// 请求流
const { deviceId, token } = await acquireToken(refreshToken);
const result = await axios.post(
`https://stepchat.cn/api/proto.chat.v1.ChatMessageService/SendMessageStream`,
`https://yuewen.cn/api/proto.chat.v1.ChatMessageService/SendMessageStream`,
messagesPrepare(convId, messages, refs),
{
headers: {
"Content-Type": "application/connect+json",
Cookie: generateCookie(deviceId, token),
"Oasis-Webid": deviceId,
Referer: `https://stepchat.cn/chats/${convId}`,
Referer: `https://yuewen.cn/chats/${convId}`,
...FAKE_HEADERS,
},
// 120秒超时
Expand Down Expand Up @@ -300,14 +301,14 @@ async function createCompletionStream(
// 请求流
const { deviceId, token } = await acquireToken(refreshToken);
const result = await axios.post(
`https://stepchat.cn/api/proto.chat.v1.ChatMessageService/SendMessageStream`,
`https://yuewen.cn/api/proto.chat.v1.ChatMessageService/SendMessageStream`,
messagesPrepare(convId, messages, refs),
{
headers: {
"Content-Type": "application/connect+json",
Cookie: generateCookie(deviceId, token),
"Oasis-Webid": deviceId,
Referer: `https://stepchat.cn/chats/${convId}`,
Referer: `https://yuewen.cn/chats/${convId}`,
...FAKE_HEADERS,
},
// 120秒超时
Expand Down Expand Up @@ -771,7 +772,7 @@ async function uploadFile(fileUrl: string, refreshToken: string) {
const { deviceId, token } = await acquireToken(refreshToken);
let result = await axios.request({
method: "PUT",
url: `https://stepchat.cn/api/storage?file_name=${filename}`,
url: `https://yuewen.cn/api/storage?file_name=${filename}`,
data: fileData,
// 100M限制
maxBodyLength: FILE_MAX_SIZE,
Expand All @@ -781,7 +782,7 @@ async function uploadFile(fileUrl: string, refreshToken: string) {
'Content-Type': mimeType,
Cookie: generateCookie(deviceId, token),
"Oasis-Webid": deviceId,
Referer: "https://stepchat.cn/chats/new",
Referer: "https://yuewen.cn/chats/new",
"Stepchat-Meta-Width": "undefined",
"Stepchat-Meta-Height": "undefined",
"Stepchat-Meta-Size": `${fileData.byteLength}`,
Expand All @@ -796,15 +797,15 @@ async function uploadFile(fileUrl: string, refreshToken: string) {
while (needFurtherCall) {
// 获取文件上传结果
result = await axios.post(
"https://stepchat.cn/api/proto.file.v1.FileService/GetFileStatus",
"https://yuewen.cn/api/proto.file.v1.FileService/GetFileStatus",
{
id: fileId,
},
{
headers: {
Cookie: generateCookie(deviceId, token),
"Oasis-Webid": deviceId,
Referer: "https://stepchat.cn/chats/new",
Referer: "https://yuewen.cn/chats/new",
...FAKE_HEADERS,
},
timeout: 15000,
Expand Down Expand Up @@ -844,12 +845,12 @@ function tokenSplit(authorization: string) {
*/
async function getTokenLiveStatus(refreshToken: string) {
const result = await axios.post(
"https://stepchat.cn/passport/proto.api.passport.v1.PassportService/RegisterDevice",
"https://yuewen.cn/passport/proto.api.passport.v1.PassportService/RegisterDevice",
{},
{
headers: {
Cookie: `Oasis-Token=${refreshToken}`,
Referer: "https://stepchat.cn/chats/new",
Referer: "https://yuewen.cn/chats/new",
...FAKE_HEADERS,
},
timeout: 15000,
Expand Down

0 comments on commit ee861b7

Please sign in to comment.