ChatGPT-Next-Web/app/utils/baidu.ts

24 lines
555 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { BAIDU_OATUH_URL } from "../constant";
/**
* 使用 AKSK 生成鉴权签名Access Token
* @return 鉴权签名信息
*/
export async function getAccessToken(
clientId: string,
clientSecret: string,
): Promise<{
access_token: string;
expires_in: number;
error?: number;
}> {
const res = await fetch(
`${BAIDU_OATUH_URL}?grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}`,
{
method: "POST",
mode: "cors",
},
);
const resJson = await res.json();
return resJson;
}