baidu.ts 555 B

1234567891011121314151617181920212223
  1. import { BAIDU_OATUH_URL } from "../constant";
  2. /**
  3. * 使用 AK,SK 生成鉴权签名(Access Token)
  4. * @return 鉴权签名信息
  5. */
  6. export async function getAccessToken(
  7. clientId: string,
  8. clientSecret: string,
  9. ): Promise<{
  10. access_token: string;
  11. expires_in: number;
  12. error?: number;
  13. }> {
  14. const res = await fetch(
  15. `${BAIDU_OATUH_URL}?grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}`,
  16. {
  17. method: "POST",
  18. mode: "cors",
  19. },
  20. );
  21. const resJson = await res.json();
  22. return resJson;
  23. }